#7 effort stop/start when laptop lid closed/opened

open
None
5
2012-09-15
2008-09-28
maho5
No

Hi,

Few months ago I have asked you about technical details of my idea (stop effort when laptop goes sleep, resume when laptop is resumed).

Here is result of my work - patch in code, and 2 files:

  • dbus configuration (to put in /etc/dbus-1/system.d/
  • sleep/resume powermanager hook (to put in /etc/pm/sleep.d/)

This patch is against 0.70.0 . I tried to apply it against 0.73, but seems that you did some revolution in gui code, so I can't do it quickly.

No choosing it in preferences ... in fact, it's a bit quick and dirty (but works for me :D). I hope you will find it usefull, and do something nice based on it. If not, and you need from me more mature patch, let me know, I will try to polish it a bit.

Discussion

  • maho5
    maho5
    2008-09-28

    patch against 0.70.0

     
    Attachments
  • maho5
    maho5
    2008-09-28

    /etc/dbus-1/system.d/taskcoach.conf

     
    Attachments
  • maho5
    maho5
    2008-09-28

    File Added: taskcoach.conf

     
  • maho5
    maho5
    2008-09-28

    File Added: 01-taskcoach-stop.sh

     
  • maho5
    maho5
    2008-09-28

    /etc/pm/sleep.d/01-taskcoach-stop.sh

     
    Attachments
  • Frank Niessink
    Frank Niessink
    2008-10-02

    Hi,

    Thanks for the patch. I won't apply the patch as it is now, because of the missing preference option and because I don't like the additional start and stop scripts. I think it should be possible to register an event handler and then start the dbus mainloop in a separate thread and do the stop/start tracking from the separate thread.

    Cheers, Frank

     
  • maho5
    maho5
    2008-10-02

    re preference - I fully agree. I'll try to do it later.

    re separate thread - why should I initialize dbus in separate thread, if it's mainloop creates thread itself?

    re events - what do you mean?

     
  • maho5
    maho5
    2008-12-18

    patch against 0.71.4

     
    Attachments
  • maho5
    maho5
    2008-12-18

    Hi,

    Attached patch agains 0.71.4. I read more about dbus signals, and did it as you wanted (at least I hope it is as you wanted).

    Regarding preferences - still didn't it, so it's probably not to implement yet. But I'm attaching, to ask you, if I'm initializing dbus code in correct place. Reason why I'm asking, is that sources are a bit complicated, so I found no better way to access to effort start/stop command than pass reference to objects in taskbar while they are creating. However - I feel that it isn't the best way.

    If I'm right, please give me hint, how could I stop current effort and start it again in other way ...

    File Added: laptop-lid-2.diff

     
  • Frank Niessink
    Frank Niessink
    2008-12-18

    Hi,

    [This is without looking at the code, will do that later]

    The best way to get notified of effort tracking start and stop events is to register an event handler, like this:

    from taskcoachlib import patterns

    Somewhere during initialization do:

    patterns.Publisher().registerObserver(self.onStartEffortTracking, eventType='task.track.start')
    patterns.Publisher().registerObserver(self.onStopEffortTracking, eventType='task.track.stop')
    self.trackedTasks = []
    self.tasksToRestart = []

    The event handlers:

    def onStartEffortTracking(self, event):
    self.trackedTasks.append(event.source())

    def onStopEffortTracking(self, event):
    self.trackedTasks.remove(event.source())

    Now you always know which tasks are begin tracked, so when the lid is closed simply do:

    def onCloseLid(self, ...):
    # Stopping effort tracking will indirectly invoked onStopEffortTracking so we need to keep track of
    # the tracked tasks ourselves:
    self.tasksToRestart = self.trackedTasks[:]
    for task in self.trackedTasks:
    task.stopTracking()

    def onOpenLid(self, ...):
    for task in self.tasksToRestart:
    task.startTracking() # This method does not exist at the moment, see below
    self.tasksToRestart = []

    New Task method:

    def startTracking(self):
    newEffort = effort.Effort(self)
    self.addEffort(newEffort)

    Cheers, Frank

     
  • Frank Niessink
    Frank Niessink
    2008-12-18

    Hi,

    Sorry about the lost indentation, hope it is clear anyway?

    Cheers, Frank