gnome-games r7822 - trunk/gnome-sudoku/src/lib
- From: thomashpa svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r7822 - trunk/gnome-sudoku/src/lib
- Date: Fri, 15 Aug 2008 01:56:47 +0000 (UTC)
Author: thomashpa
Date: Fri Aug 15 01:56:47 2008
New Revision: 7822
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7822&view=rev
Log:
Clean up timer code. Patch by Thomas H.P. Andersen. Fixes bug #530792 and bug #544499
Modified:
trunk/gnome-sudoku/src/lib/main.py
trunk/gnome-sudoku/src/lib/saver.py
trunk/gnome-sudoku/src/lib/timer.py
Modified: trunk/gnome-sudoku/src/lib/main.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/main.py (original)
+++ trunk/gnome-sudoku/src/lib/main.py Fri Aug 15 01:56:47 2008
@@ -174,7 +174,6 @@
self.won = False
# add the accelerator group to our toplevel window
self.worker_connections=[]
- self.timer.start_timing()
# setup sudoku maker...
self.sudoku_maker = sudoku_maker.SudokuMaker()
self.sudoku_tracker = saver.SudokuTracker()
@@ -212,6 +211,7 @@
if not choice:
return True
#print 'choice is ',choice
+ self.timer.start_timing()
if choice[0] == game_selector.NewOrSavedGameSelector.NEW_GAME:
self.gsd.change_grid(choice[1],9)
if choice[0] == game_selector.NewOrSavedGameSelector.SAVED_GAME:
@@ -543,8 +543,6 @@
delattr(self,'dancer')
self.gsd.grid = None
self.tracker_ui.reset()
- self.timer.reset_timer()
- self.timer.start_timing()
self.history.clear()
self.won = False
@@ -770,20 +768,6 @@
self.current_puzzle_string = puzz
tot_string = _("Playing %(difficulty)s puzzle.")%{'difficulty':self.current_puzzle_diff.value_string()}
tot_string += " " + "(%1.2f)"%self.current_puzzle_diff.value
- #if self.timer.tot_time or self.timer.tot_time_complete:
- # time_string = _("%s (%s active)")%(
- # self.timer.total_time_string(),
- # self.timer.active_time_string()
- # )
- # if not self.timer.__timing__:
- # time_string += " %s"%_('paused')
- # tot_string += " - " + time_string
- #if self.gsd.hints and not self.gconf['always_show_hints']:
- # tot_string += " - " +ngettext("%(n)s hint","%(n)s hints",
- # self.gsd.hints)%{'n':self.gsd.hints}
- #if self.gsd.auto_fills:
- # tot_string += " " +ngettext("%(n)s auto-fill","%(n)s auto-fills",
- # self.gsd.auto_fills)%{'n':self.gsd.auto_fills}
self.set_statusbar_value(tot_string)
return True
Modified: trunk/gnome-sudoku/src/lib/saver.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/saver.py (original)
+++ trunk/gnome-sudoku/src/lib/saver.py Fri Aug 15 01:56:47 2008
@@ -30,8 +30,7 @@
def jar_game (ui):
jar = {} # what we will pickle
#jar['undo_history']=ui.history
- ui.timer.resume_timing()
- ui.timer.toggle_timing(False) # Save time...
+ ui.timer.finish_timing()
jar['game']=ui.gsd.grid.to_string()
jar['trackers']=ui.gsd.trackers
jar['tracking']=ui.gsd.__trackers_tracking__
Modified: trunk/gnome-sudoku/src/lib/timer.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/timer.py (original)
+++ trunk/gnome-sudoku/src/lib/timer.py Fri Aug 15 01:56:47 2008
@@ -122,9 +122,8 @@
def __init__ (self, window):
gobject.GObject.__init__(self)
self.window = window
- self.__timing__ = False
+ self.timing_running = False
self.__absolute_start_time__ = 0
- self.__paused__ = False
self.tot_time = 0
self.tot_time_complete = 0
self.window.connect('window-state-event',self.window_state_event_cb)
@@ -141,57 +140,44 @@
def toggle_timing (self, on):
if not self.__absolute_start_time__:
- self.reset_timer()
- if self.__paused__: return False
- if on and not self.__timing__:
+ return
+
+ if on and not self.timing_running:
self.timing_started_at = time.time()
- self.__timing__ = True
+ self.timing_running = True
self.emit('timing-started')
- #print 'timing!'
- if not on and self.__timing__:
+
+ if not on and self.timing_running:
end_time = time.time()
- self.__timing__ = False
+ self.timing_running = False
self.tot_time += (end_time - self.timing_started_at)
self.tot_time_complete = end_time - self.__absolute_start_time__
- #print 'Stopped timing...',self.tot_time
self.emit('timing-stopped')
- #print on,'represents no change'
-
- def finish_timing (self):
- self.toggle_timing(False)
- if not self.tot_time_complete:
- self.tot_time_complete = time.time() - self.__absolute_start_time__
- #print 'tot_time ',self.tot_time
- #print 'tot_time_complete ',self.tot_time_complete
-
- def active_time_string (self):
- if self.__timing__ and not self.__paused__:
- return format_time(self.tot_time+time.time()-self.timing_started_at)
- else:
- return format_time(self.tot_time)
-
- def total_time_string (self):
- if self.__timing__:
- return format_time(time.time()-self.__absolute_start_time__)
- else:
- return format_time(self.tot_time_complete)
-
- def reset_timer (self):
- self.__absolute_start_time__ = time.time()
- self.tot_time = 0
- self.toggle_timing(False)
def start_timing (self):
+ self.timing_running = False
+ self.__absolute_start_time__ = 0
+ self.tot_time = 0
+ self.tot_time_complete = 0
self.__absolute_start_time__ = time.time()
self.toggle_timing(True)
- def pause_timing (self):
+ def finish_timing (self):
self.toggle_timing(False)
- self.__paused__ = True
+ if self.tot_time < 1:
+ self.tot_time = 1;
+ # dirty hack: never let total time be less than active time
+ if self.tot_time > self.tot_time_complete:
+ self.tot_time_complete = self.tot_time;
+ self.__absolute_start_time__ = 0
- def resume_timing (self):
- self.__paused = False
- self.toggle_timing(True)
+ # make sure to call finish_timing before using this function
+ def active_time_string (self):
+ return format_time(self.tot_time)
+
+ # make sure to call finish_timing before using this function
+ def total_time_string (self):
+ return format_time(self.tot_time_complete)
if gtk.pygtk_version[1]<8: gobject.type_register(ActiveTimer)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]