TimeTracker/TimeTrackerEntryDialog.py

changeset 16
63437823b396
child 31
db0afa672b75
equal deleted inserted replaced
15:645506ab3376 16:63437823b396
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the time tracker edit dialog.
8 """
9
10 from PyQt4.QtCore import pyqtSlot, QDateTime, QDate
11 from PyQt4.QtGui import QDialog, QDialogButtonBox
12
13 from .Ui_TimeTrackerEntryDialog import Ui_TimeTrackerEntryDialog
14
15
16 class TimeTrackerEntryDialog(QDialog, Ui_TimeTrackerEntryDialog):
17 """
18 Class implementing the time tracker edit dialog.
19 """
20 def __init__(self, tracker, entry, taskItems, commentItems, parent=None):
21 """
22 Constructor
23
24 @param tracker reference to the time tracker (TimeTracker)
25 @param entry reference to the time tracker entry (TimeTrackEntry)
26 @param taskItems list of task item entries for the
27 task combo box (list of strings)
28 @param commentItems list of comment item entries for the
29 comment combo box (list of strings)
30 @param parent reference to the parent widget (QWidget)
31 """
32 super().__init__(parent)
33 self.setupUi(self)
34
35 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
36
37 self.taskCombo.addItems(taskItems)
38 self.commentCombo.addItems(commentItems)
39
40 # The allowed end time (i.e. start date and time plus duration must be
41 # earlier or equal to the start date and time of the current entry.
42 self.__endDateTime = QDateTime(tracker.getCurrentEntry().getStartDateTime())
43
44 self.durationSpinBox.setMinimum(tracker.getPreferences("MinimumDuration"))
45
46 if entry is None:
47 self.setWindowTitle(self.tr("Add Tracker Entry"))
48 self.startDateTimeEdit.setDate(QDate.currentDate())
49 else:
50 self.startDateTimeEdit.setDateTime(entry.getStartDateTime())
51 self.durationSpinBox.setValue(entry.getDuration())
52 self.taskCombo.setEditText(entry.getTask())
53 self.commentCombo.setEditText(entry.getComment())
54
55 def __checkOk(self):
56 """
57 Private slot to set the enabled state of the OK button.
58 """
59 dt = self.startDateTimeEdit.dateTime()
60 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
61 dt.addSecs(self.durationSpinBox.value() * 60) <= self.__endDateTime)
62
63 @pyqtSlot(QDateTime)
64 def on_startDateTimeEdit_dateTimeChanged(self, date):
65 """
66 Private slot handling a change of the start date and time.
67 """
68 self.__checkOk()
69
70 @pyqtSlot(int)
71 def on_durationSpinBox_valueChanged(self, p0):
72 """
73 Private slot handling a change of the duration.
74 """
75 self.__checkOk()
76
77 def getData(self):
78 """
79 Public method to get the data.
80
81 @return tuple with start date and time, duration, task description
82 and comment (QDateTime, integer, string, string)
83 """
84 return (
85 self.startDateTimeEdit.dateTime(),
86 self.durationSpinBox.value(),
87 self.taskCombo.currentText(),
88 self.commentCombo.currentText(),
89 )

eric ide

mercurial