Created
March 19, 2014 15:54
-
-
Save tom-monaco/9644753 to your computer and use it in GitHub Desktop.
Taskcoach patch to enable decimal hour display in the effort viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: taskcoach/taskcoachlib/config/defaults.py | |
=================================================================== | |
--- taskcoach/taskcoachlib/config/defaults.py (revision 6433) | |
+++ taskcoach/taskcoachlib/config/defaults.py (working copy) | |
@@ -524,7 +524,8 @@ | |
'showsmwarning': 'True', | |
'sayreminder': 'False', | |
'sdtcspans': '60,120,1440,2880', | |
- 'sdtcspans_effort': '60,120,180,240' | |
+ 'sdtcspans_effort': '60,120,180,240', | |
+ 'decimaltime' : 'False' | |
}, | |
'syncml': { | |
'url': '', | |
Index: taskcoach/taskcoachlib/gui/dialog/preferences.py | |
=================================================================== | |
--- taskcoach/taskcoachlib/gui/dialog/preferences.py (revision 6433) | |
+++ taskcoach/taskcoachlib/gui/dialog/preferences.py (working copy) | |
@@ -585,6 +585,10 @@ | |
helpText=_('If there is no user input for this amount of time\n' | |
'(in minutes), %(name)s will ask what to do about current ' | |
'efforts.') % meta.data.metaDict) | |
+ self.addBooleanSetting('feature', 'decimaltime', | |
+ _('Use decimal times for effort entries.'), | |
+ _('Display one hour, fifteen minutes as 1.25 instead of 1:15\n' | |
+ 'This is useful when creating invoices.')) | |
self.fit() | |
def ok(self): | |
Index: taskcoach/taskcoachlib/gui/viewer/effort.py | |
=================================================================== | |
--- taskcoach/taskcoachlib/gui/viewer/effort.py (revision 6433) | |
+++ taskcoach/taskcoachlib/gui/viewer/effort.py (working copy) | |
@@ -61,6 +61,8 @@ | |
'settings.%s.alwaysroundup' % self.settingsSection()) | |
pub.subscribe(self.on_aggregation_changed, | |
'settings.%s.aggregation' % self.settingsSection()) | |
+ pub.subscribe(self.onHourDisplayChanged, | |
+ 'settings.feature.decimaltime') | |
def selectableColumns(self): | |
columns = list() | |
@@ -76,6 +78,9 @@ | |
def onRoundingChanged(self, value): # pylint: disable=W0613 | |
self.__initRoundingToolBarUICommands() | |
self.refresh() | |
+ | |
+ def onHourDisplayChanged(self,value): | |
+ self.refresh() | |
def __initModeToolBarUICommands(self): | |
self.aggregationUICommand.setChoice(self.aggregation) | |
@@ -381,7 +386,11 @@ | |
for effort in efforts: | |
td = td + effort.duration() | |
- sumTimeSpent = render.timeSpent(td, showSeconds=self.__show_seconds()) | |
+ if self.settings.getboolean('feature','decimaltime'): | |
+ sumTimeSpent = render.timeSpentDecimal(td) | |
+ else: | |
+ sumTimeSpent = render.timeSpent(td, showSeconds=self.__show_seconds()) | |
+ | |
if sumTimeSpent == '': | |
if self.__show_seconds(): | |
sumTimeSpent = '0:00:00' | |
@@ -468,7 +477,11 @@ | |
showSeconds = self.__show_seconds() | |
else: | |
showSeconds = True | |
- return render.timeSpent(duration, showSeconds=showSeconds) | |
+ | |
+ if self.settings.getboolean('feature','decimaltime'): | |
+ return render.timeSpentDecimal(duration) | |
+ else: | |
+ return render.timeSpent(duration, showSeconds=showSeconds) | |
def __renderTotalTimeSpent(self, anEffort): | |
''' Return a rendered version of the effort total duration (of | |
@@ -477,7 +490,10 @@ | |
# in aggregated mode | |
total_duration = anEffort.duration(recursive=True, | |
rounding=self.__round_precision(), roundUp=self.__always_round_up()) | |
- return render.timeSpent(total_duration, | |
+ if self.settings.getboolean('feature','decimaltime'): | |
+ return render.timeSpentDecimal(total_duration) | |
+ else: | |
+ return render.timeSpent(total_duration, | |
showSeconds=self.__show_seconds()) | |
def __renderTimeSpentOnDay(self, anEffort, dayOffset): | |
@@ -489,8 +505,11 @@ | |
kwargs['roundUp'] = self.__always_round_up() | |
duration = anEffort.durationDay(dayOffset, **kwargs) \ | |
if self.aggregation == 'week' else date.TimeDelta() | |
- return render.timeSpent(self.__round_duration(duration), | |
- showSeconds=self.__show_seconds()) | |
+ if self.settings.getboolean('feature','decimaltime'): | |
+ return render.timeSpentDecimal(self.__round_duration(duration)) | |
+ else: | |
+ return render.timeSpent(self.__round_duration(duration), | |
+ showSeconds=self.__show_seconds()) | |
@staticmethod | |
def __renderRevenue(anEffort): | |
Index: taskcoach/taskcoachlib/render.py | |
=================================================================== | |
--- taskcoach/taskcoachlib/render.py (revision 6433) | |
+++ taskcoach/taskcoachlib/render.py (working copy) | |
@@ -68,6 +68,17 @@ | |
return sign + '%d:%02d' % (hours, minutes) + \ | |
(':%02d' % seconds if showSeconds else '') | |
+def timeSpentDecimal(timeSpent): | |
+ ''' Render time spent (of type date.TimeDelta) as | |
+ "<hours>.<fractional hours> ''' | |
+ zero = datemodule.TimeDelta() | |
+ if timeSpent == zero: | |
+ return '' | |
+ else: | |
+ sign = '-' if timeSpent < zero else '' | |
+ hours, minutes, seconds = timeSpent.hoursMinutesSeconds() | |
+ decimalHours = hours + minutes/60.0 + seconds/3600.0 | |
+ return sign + '%.2f' % (decimalHours) | |
def recurrence(recurrence): | |
''' Render the recurrence as a short string describing the frequency of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment