Hi,
2008/6/3 maho <[EMAIL PROTECTED]>:
> Hi,
>
> I wanted to implement one small and easy (or rather "I thought that it's
> easy") feature in taskcoach. Stop an effort when laptop lid is closed/PC is
> suspended, and resume it after PC is resumed.
Here's how I would approach this. First, since Task Coach has no
pause/resume functionality at the moment I would implement that first,
including the user interface. To resume, we need to know the task the
user was tracking when effort tracking was paused. That information is
already available by looking up the most recent effort record in the
effort list. So conceptually, there is no difference between stopping
effort tracking and pausing effort tracking. By the way, I am assuming
that the time between pause and resume will not be registered as time
spent on the task (what would the use of pause/resume be if it were,
right?). So, to summarize "pause = stop tracking" and "resume = start
tracking for the task that was last being tracked."
Now we need to decide what the user interface will look like.
Currently, Task Coach has two task tracking buttons: start effort and
stop effort (the clocks). We at least need a resume button that is
enabled as long as there is at least one effort record in the effort
list. We also need an icon, by the way, so look for one in
icons.in/nuvola.zip. If no stock icon is available I create one
myself, in this case by for example combining the clock icon with a
'play' button, and add it to the zip file. Since that big zip file is
not distributed with Task Coach, but icons are converted to a python
file we need to add the icon to icons.in/iconmap.py to get it included
in the generated icons.py ("make icons" generates a new icons.py btw).
Next is to add the resume button to the toolbar and a resume menu item
to the effort menu on the menubar, and maybe as well to the task and
effort right-click popup menu's. For this we need a new user interface
command. The user interface commands are in
taskcoachlib/gui/uicommand.py. Look for EffortStart and use that as an
example for EffortResume. EffortStart uses the selected task to start
tracking for. EffortResume will use the task of the most recent effort
as task to start tracking effort for. Something like this:
class EffortResume(EffortListCommand, TaskListCommand):
''' UICommand to resume tracking effort. '''
def __init__(self, *args, **kwargs):
super(EffortResume, self).__init__(bitmap='resume',
menuText=_('&Resume tracking effort'),
helpText=_('Resume tracking effort for the last tracked task'),
*args, **kwargs)
def doCommand(self, event):
lastTask = self.mostRecentEffortRecord().task()
start = command.StartEffortCommand(self.taskList, [lastTask])
start.do()
def enabled(self, event):
return len(self.effortList) > 0
def mostRecentEffortRecord(self):
return #most recent effort record from self.effortList#
And we instantiate the EffortResume uicommand by adding around line 1967:
self['resumeeffort'] = EffortResume(taskList=taskList,
effortList=effortList)
Note that command.StartEffortCommand is already an undoable command,
so we're lucky and get undo for free.
Now we need to add this user interface command to menu's and toolbar.
In taskcoachlib/gui/menu.py, add it to the effort menu:
class EffortMenu(Menu):
def __init__(self, mainwindow, uiCommands):
super(EffortMenu, self).__init__(mainwindow)
self.appendUICommands(uiCommands, ['neweffort', 'editeffort',
'deleteeffort', None, 'starteffort', 'resumeeffort', 'stopeffort'])
And similarly to other menus. To add it to the toolbar edit
taskcoachlib/gui/toolbar.py in a similar way.
Now you're ready to bind the closing of the laptop lid to stop
tracking effort and opening of the lid to resume tracking effort.
You'll need a preference option for users to turn this behaviour on
and off. Add a default to taskcoachlib/config/defaults.py. Add the
user interface to taskcoachlib/gui/dialog/preferences.py, e.g. to the
TaskBehaviorPage, by using one of the standard methods for adding a
preference, e.g. self.addBooleanSetting.
Oh, and since this is Linux specific (right?) you'll need to make sure
that the preference is only visible on Linux (there is one example of
a Mac specific option you can work from).
Last step is to bind the dbus events somewhere to EffortStop.doCommand
and EffortResume.doCommand. I guess the best place is a new module in
the gui package.
Hope this helps, Frank
PS: If you'd like me to implement the UI part, let me know, it
shouldn't take long no that I've thought it through already ;-)