TimeTracker/TimeTrackerEntryDialog.py

Wed, 01 Jan 2014 14:47:57 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 01 Jan 2014 14:47:57 +0100
changeset 44
fe7ddb709c6a
parent 42
37049a04b8fa
child 45
ff7d62d441b5
permissions
-rw-r--r--

Updated copyright for 2014.

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

eric ide

mercurial