Sat, 31 Dec 2022 16:27:55 +0100
Updated copyright for 2023.
# -*- coding: utf-8 -*- # Copyright (c) 2012 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the time tracker edit dialog. """ from PyQt6.QtCore import QDate, QDateTime, pyqtSlot from PyQt6.QtWidgets import QDialog, QDialogButtonBox from .Ui_TimeTrackerEntryDialog import Ui_TimeTrackerEntryDialog class TimeTrackerEntryDialog(QDialog, Ui_TimeTrackerEntryDialog): """ Class implementing the time tracker edit dialog. """ def __init__(self, tracker, entry, taskItems, commentItems, parent=None): """ Constructor @param tracker reference to the time tracker @type TimeTracker @param entry reference to the time tracker entry @type TimeTrackEntry @param taskItems list of task item entries for the task combo box @type list of str @param commentItems list of comment item entries for the comment combo box @type list of str @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setupUi(self) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) self.taskCombo.addItems(taskItems) self.commentCombo.addItems(commentItems) # The allowed end time (i.e. start date and time plus duration must be # earlier or equal to the start date and time of the current entry. self.__endDateTime = QDateTime(tracker.getCurrentEntry().getStartDateTime()) self.durationSpinBox.setMinimum(tracker.getPreferences("MinimumDuration")) if entry is None: self.setWindowTitle(self.tr("Add Tracker Entry")) self.startDateTimeEdit.setDate(QDate.currentDate()) else: self.startDateTimeEdit.setDateTime(entry.getStartDateTime()) self.durationSpinBox.setValue(entry.getDuration()) self.durationSpinBox.setMaximum( entry.getStartDateTime().secsTo(self.__endDateTime) // 60 ) self.taskCombo.setEditText(entry.getTask()) self.commentCombo.setEditText(entry.getComment()) msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) def __checkOk(self): """ Private slot to set the enabled state of the OK button. """ dt = self.startDateTimeEdit.dateTime() self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( dt.addSecs(self.durationSpinBox.value() * 60) <= self.__endDateTime ) @pyqtSlot(QDateTime) def on_startDateTimeEdit_dateTimeChanged(self, date): """ Private slot handling a change of the start date and time. @param date start date and time @type QDateTime """ self.__checkOk() @pyqtSlot(int) def on_durationSpinBox_valueChanged(self, value): """ Private slot handling a change of the duration. @param value value of the duration spin box @type int """ self.__checkOk() def getData(self): """ Public method to get the data. @return tuple with start date and time, duration, task description and comment @rtype tuple of (QDateTime, int, str, str) """ return ( self.startDateTimeEdit.dateTime(), self.durationSpinBox.value(), self.taskCombo.currentText(), self.commentCombo.currentText(), )