Permalink
Browse files

Added support for starting in modes other than sleep.

  • Loading branch information...
1 parent 6b15db5 commit 8def5c0a3f524645ce04e48465d299f99e1278db @FunnyMan3595 FunnyMan3595 committed Aug 26, 2009
Showing with 16 additions and 5 deletions.
  1. +16 −5 timeclock.py
View
21 timeclock.py
@@ -113,7 +113,9 @@ def notify_exhaustion(mode):
CURRENT_SAVE_VERSION = 3 #: Used for save file versioning
class TimeClock:
- def __init__(self):
+ def __init__(self, default_mode="sleep"):
+ self.default_mode = default_mode
+
#Set the Glade file
self.gladefile = os.path.join(SELF_DIR, "timeclock.glade")
self.wTree = gtk.glade.XML(self.gladefile)
@@ -180,15 +182,18 @@ def _init_widgets(self):
self.wTree.get_widget('progress_%sMode' % MODE_NAMES[mode])
self.total[mode] = default_modes[mode]
self.used[mode] = 0
- self.selectedBtn = self.wTree.get_widget('btn_sleepMode')
- self.selectedBtn.mode = SLEEP
+ sleepBtn = self.wTree.get_widget('btn_sleepMode')
+ sleepBtn.mode = SLEEP
+
+ self.selectedBtn = self.wTree.get_widget('btn_%sMode' % self.default_mode)
+ self.selectedBtn.set_active(True)
self.save_timeout = None
# Because PyGTK isn't reliably obeying Glade
self.update_progressBars()
for widget in self.timer_widgets:
widget.set_property('draw-indicator', False)
- self.selectedBtn.set_property('draw-indicator', False)
+ sleepBtn.set_property('draw-indicator', False)
def update_progressBars(self):
"""Common code used for initializing and updating the progress bars."""
@@ -289,9 +294,15 @@ def doSave(self):
parser = OptionParser(version="%%prog v%s" % __version__)
#parser.add_option('-v', '--verbose', action="store_true", dest="verbose",
# default=False, help="Increase verbosity")
+ parser.add_option('-m', '--initial-mode',
+ action="store", dest="mode", default="sleep",
+ metavar="MODE", help="start in MODE")
opts, args = parser.parse_args()
- app = TimeClock()
+ if (opts.mode not in MODE_NAMES):
+ print "Mode '%s' not recognized, defaulting to sleep." % opts.mode
+ opts.mode = "sleep"
+ app = TimeClock(default_mode=opts.mode)
# Make sure that state is saved to disk on exit.
sys.exitfunc = app.doSave

0 comments on commit 8def5c0

Please sign in to comment.