Permalink
Browse files

Protect against crash-related data loss by saving timer values every …

…five minutes. (Part 2 of 2)

Timeclock.py now unhooks the save timer and manually triggers it when sleep mode is activated.
  • Loading branch information...
1 parent 927dde6 commit d4ff1c659d4f4da62ecd9942cd395cc2b284e993 Stephan Sokolow committed Jul 2, 2009
Showing with 9 additions and 3 deletions.
  1. +9 −3 timeclock.py
View
@@ -170,9 +170,6 @@ def __init__(self):
self.wTree.signal_autoconnect(dic)
gobject.timeout_add(1000, self.tick)
- # Save timer states every five minutes in case of crashes
- gobject.timeout_add(1000 * 60 * 5, self.doSave)
-
def _init_widgets(self):
"""All non-signal, non-glade widget initialization."""
# Set up the data structures
@@ -187,6 +184,7 @@ def _init_widgets(self):
self.used[mode] = 0
self.selectedBtn = self.wTree.get_widget('btn_sleepMode')
self.selectedBtn.mode = SLEEP
+ self.save_timeout = None
# Because PyGTK isn't reliably obeying Glade
self.update_progressBars()
@@ -212,6 +210,14 @@ def mode_changed(self, widget):
if widget.get_active():
self.selectedBtn = widget
+ if self.selectedBtn.mode == SLEEP and self.save_timeout:
+ gobject.source_remove(self.save_timeout)
+ self.save_timeout = None
+ self.doSave()
+ elif self.selectedBtn.mode != SLEEP and not self.save_timeout:
+ # Save timer states every five minutes in case of crashes
+ self.save_timeout = gobject.timeout_add(1000 * 60 * 5, self.doSave)
+
def reset_clicked(self, widget):
"""Callback for the reset button"""
self.used = dict((x, 0) for x in self.used)

0 comments on commit d4ff1c6

Please sign in to comment.