diff -r 21b31f1308ab -r 37049a04b8fa TimeTracker/TimeTracker.py --- a/TimeTracker/TimeTracker.py Sat Sep 28 13:37:07 2013 +0200 +++ b/TimeTracker/TimeTracker.py Fri Oct 25 18:54:29 2013 +0200 @@ -62,20 +62,24 @@ from .TimeTrackerWidget import TimeTrackerWidget self.__widget = TimeTrackerWidget(self) - self.__ui.addSideWidget(self.__ui.BottomSide, self.__widget, - UI.PixmapCache.getIcon(os.path.join("TimeTracker", "icons", "clock.png")), + self.__ui.addSideWidget( + self.__ui.BottomSide, self.__widget, + UI.PixmapCache.getIcon( + os.path.join("TimeTracker", "icons", "clock.png")), self.tr("Time Tracker")) - self.__activateAct = E5Action(self.trUtf8('Time Tracker'), - self.trUtf8('T&ime Tracker'), - QKeySequence(self.trUtf8("Alt+Shift+I")), - 0, self, - 'time_tracker_activate') + self.__activateAct = E5Action( + self.trUtf8('Time Tracker'), + self.trUtf8('T&ime Tracker'), + QKeySequence(self.trUtf8("Alt+Shift+I")), + 0, self, + 'time_tracker_activate') self.__activateAct.setStatusTip(self.trUtf8( "Switch the input focus to the Time Tracker window.")) self.__activateAct.setWhatsThis(self.trUtf8( """<b>Activate Time Tracker</b>""" - """<p>This switches the input focus to the Time Tracker window.</p>""" + """<p>This switches the input focus to the Time Tracker""" + """ window.</p>""" )) self.__activateAct.triggered[()].connect(self.__activateWidget) @@ -108,7 +112,8 @@ TimeTracker.FileName) self.__readTrackerEntries() - self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) + self.__widget.showTrackerEntries(sorted(self.__entries.values(), + reverse=True)) self.__widget.setEnabled(True) self.startTrackerEntry() @@ -132,11 +137,12 @@ data = f.read() f.close() except (IOError, OSError) as err: - E5MessageBox.critical(self.__ui, + E5MessageBox.critical( + self.__ui, self.trUtf8("Read Time Tracker File"), - self.trUtf8("""<p>The time tracker file <b>{0}</b> could not be""" - """ read.</p><p>Reason: {1}</p>""").format( - self.__trackerFilePath, str(err))) + self.trUtf8("""<p>The time tracker file <b>{0}</b> could""" + """ not be read.</p><p>Reason: {1}</p>""") + .format(self.__trackerFilePath, str(err))) return from .TimeTrackEntry import TimeTrackEntry @@ -151,23 +157,27 @@ invalidCount += 1 if invalidCount: - E5MessageBox.information(self.__ui, + E5MessageBox.information( + self.__ui, self.trUtf8("Read Time Tracker File"), - self.trUtf8("""<p>The time tracker file <b>{0}</b> contained""" - """ %n invalid entries. These have been discarded.</p>""", - "", invalidCount).format(self.__trackerFilePath)) + self.trUtf8("""<p>The time tracker file <b>{0}</b>""" + """ contained %n invalid entries. These""" + """ have been discarded.</p>""", "", + invalidCount).format(self.__trackerFilePath)) def saveTrackerEntries(self, filePath="", ids=[]): """ Public slot to save the tracker entries to a file. - @keyparam filePath path and name of the file to write the entries to (string) + @keyparam filePath path and name of the file to write the entries to + (string) @keyparam ids list of entry IDs to be written (list of integer) """ if not filePath: filePath = self.__trackerFilePath if ids: - entriesList = [self.__entries[eid] for eid in ids if eid in self.__entries] + entriesList = [self.__entries[eid] for eid in ids + if eid in self.__entries] else: entriesList = self.__entries.values() try: @@ -177,11 +187,12 @@ f.write(entry.toString() + "\n") f.close() except (IOError, OSError) as err: - E5MessageBox.critical(self.__ui, + E5MessageBox.critical( + self.__ui, self.trUtf8("Save Time Tracker File"), - self.trUtf8("""<p>The time tracker file <b>{0}</b> could not be""" - """ saved.</p><p>Reason: {1}</p>""").format( - self.__trackerFilePath, str(err))) + self.trUtf8("""<p>The time tracker file <b>{0}</b> could""" + """ not be saved.</p><p>Reason: {1}</p>""") + .format(self.__trackerFilePath, str(err))) def importTrackerEntries(self, fname): """ @@ -194,11 +205,12 @@ data = f.read() f.close() except (IOError, OSError) as err: - E5MessageBox.critical(self.__ui, + E5MessageBox.critical( + self.__ui, self.trUtf8("Import Time Tracker File"), - self.trUtf8("""<p>The time tracker file <b>{0}</b> could not be""" - """ read.</p><p>Reason: {1}</p>""").format( - fname, str(err))) + self.trUtf8("""<p>The time tracker file <b>{0}</b> could""" + """ not be read.</p><p>Reason: {1}</p>""") + .format(fname, str(err))) return from .TimeTrackEntry import TimeTrackEntry @@ -236,27 +248,34 @@ if invalidCount != 0 or duplicateCount != 0: if invalidCount != 0 and duplicateCount != 0: - msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" + msg = self.tr( + """<p>The time tracker file <b>{0}</b> contained""" """ %n invalid entries.""", "", invalidCount).format(fname) - msg += " " + self.tr(""" %n duplicate entries were detected.""", - "", duplicateCount) + msg += " " + self.tr( + """ %n duplicate entries were detected.""", "", + duplicateCount) elif duplicateCount != 0: - msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" + msg = self.tr( + """<p>The time tracker file <b>{0}</b> contained""" """ %n duplicate entries.""", "", duplicateCount).format(fname) elif invalidCount != 0: - msg = self.tr("""<p>The time tracker file <b>{0}</b> contained""" + msg = self.tr( + """<p>The time tracker file <b>{0}</b> contained""" """ %n invalid entries.""", "", invalidCount).format(fname) - msg += " " + self.tr(""" %n entries have been ignored.</p>""", + msg += " " + self.tr( + """ %n entries have been ignored.</p>""", "", invalidCount + duplicateCount) - E5MessageBox.information(self.__ui, + E5MessageBox.information( + self.__ui, self.trUtf8("Import Time Tracker File"), msg) self.__widget.clear() - self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) + self.__widget.showTrackerEntries(sorted(self.__entries.values(), + reverse=True)) self.__widget.setCurrentEntry(self.__currentEntry) def addTrackerEntry(self, startDateTime, duration, task, comment): @@ -275,7 +294,7 @@ return if duration < self.__plugin.getPreferences("MinimumDuration"): - return + return if len(self.__entries.keys()): nextID = max(self.__entries.keys()) + 1 @@ -293,7 +312,8 @@ self.__entries[nextID] = entry self.__widget.clear() - self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) + self.__widget.showTrackerEntries(sorted(self.__entries.values(), + reverse=True)) self.__widget.setCurrentEntry(self.__currentEntry) def pauseTrackerEntry(self): @@ -346,6 +366,8 @@ def getCurrentEntry(self): """ Public method to get a reference to the current tracker entry. + + @return reference to the current entry (TimeTrackEntry) """ return self.__currentEntry @@ -397,15 +419,16 @@ self.saveTrackerEntries() self.__widget.clear() - self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) + self.__widget.showTrackerEntries(sorted(self.__entries.values(), + reverse=True)) self.__widget.setCurrentEntry(self.__currentEntry) def mergeDuplicateTrackerEntries(self): """ Public slot to merge duplicate time tracker entries. - If entries with the identical start date and time are found, the durations - of these entries are added. + If entries with the identical start date and time are found, the + durations of these entries are added. """ entries = {} for entry in self.__entries.values(): @@ -426,7 +449,8 @@ self.saveTrackerEntries() self.__widget.clear() - self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True)) + self.__widget.showTrackerEntries(sorted(self.__entries.values(), + reverse=True)) self.__widget.setCurrentEntry(self.__currentEntry) def entryChanged(self):