TimeTracker/TimeTrackerEntryDialog.py

changeset 16
63437823b396
child 31
db0afa672b75
diff -r 645506ab3376 -r 63437823b396 TimeTracker/TimeTrackerEntryDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TimeTracker/TimeTrackerEntryDialog.py	Sun Oct 21 19:23:38 2012 +0200
@@ -0,0 +1,89 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the time tracker edit dialog.
+"""
+
+from PyQt4.QtCore import pyqtSlot, QDateTime, QDate
+from PyQt4.QtGui 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 (TimeTracker)
+        @param entry reference to the time tracker entry (TimeTrackEntry)
+        @param taskItems list of task item entries for the
+            task combo box (list of strings)
+        @param commentItems list of comment item entries for the
+            comment combo box (list of strings)
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        self.buttonBox.button(QDialogButtonBox.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.taskCombo.setEditText(entry.getTask())
+            self.commentCombo.setEditText(entry.getComment())
+    
+    def __checkOk(self):
+        """
+        Private slot to set the enabled state of the OK button.
+        """
+        dt = self.startDateTimeEdit.dateTime()
+        self.buttonBox.button(QDialogButtonBox.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.
+        """
+        self.__checkOk()
+    
+    @pyqtSlot(int)
+    def on_durationSpinBox_valueChanged(self, p0):
+        """
+        Private slot handling a change of the duration.
+        """
+        self.__checkOk()
+    
+    def getData(self):
+        """
+        Public method to get the data.
+        
+        @return tuple with start date and time, duration, task description
+            and comment (QDateTime, integer, string, string)
+        """
+        return (
+            self.startDateTimeEdit.dateTime(),
+            self.durationSpinBox.value(),
+            self.taskCombo.currentText(),
+            self.commentCombo.currentText(),
+        )

eric ide

mercurial