[gnome-games/sudoku-tube] Trivial refactoring
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/sudoku-tube] Trivial refactoring
- Date: Sun, 9 Aug 2009 13:43:39 +0000 (UTC)
commit 094f6421ab9fd6ac915577ba3ada90e615386658
Author: Zhang Sen <zh jesse gmail com>
Date: Sun Aug 9 21:18:18 2009 +0800
Trivial refactoring
gnome-sudoku/src/lib/main.py | 53 +++++++++++++++++++++--------------------
1 files changed, 27 insertions(+), 26 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index e678d61..1f55da7 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -38,7 +38,7 @@ logging.basicConfig()
logger = logging.getLogger("main")
-class UI (gconf_wrapper.GConfWrapper):
+class SudokuGame(gconf_wrapper.GConfWrapper):
initial_prefs = {'group_size':9,
'always_show_hints':0,
@@ -65,8 +65,12 @@ class UI (gconf_wrapper.GConfWrapper):
)
self.sudoku_maker = sudoku_maker.SudokuMaker()
self.sudoku_tracker = saver.SudokuTracker()
+
self._main_model = None
+ self._notes_model = None
self._main_grid_vew = None
+ self._side_grid_vew = None
+
self._history_manager = None
self._tube = None
self._peer = None
@@ -228,7 +232,6 @@ class UI (gconf_wrapper.GConfWrapper):
self.gconf[k]
except:
self.gconf[k] = v
- self.player = self.gconf['player']
def setup_main_window (self):
gtk.window_set_default_icon_name('gnome-sudoku')
@@ -309,8 +312,6 @@ class UI (gconf_wrapper.GConfWrapper):
action.connect("activate", callback)
def setup_undo (self):
- self.cleared = [] # used for Undo memory
- self.cleared_notes = [] # used for Undo memory
undo_action = self.builder.get_object('Undo')
redo_action = self.builder.get_object('Redo')
self._history_manager = undo.HistoryManager(undo_action, redo_action)
@@ -339,7 +340,7 @@ class UI (gconf_wrapper.GConfWrapper):
('show_tracker',
self.builder.get_object('ToggleTracker'))]]
- def start_worker_thread (self, *args):
+ def start_worker_thread(self):
n_new_puzzles = self.sudoku_maker.n_puzzles(new = True)
if n_new_puzzles < self.gconf['minimum_number_of_new_puzzles']:
self.worker = threading.Thread(target = lambda *args: self.sudoku_maker.work(limit = 5))
@@ -350,13 +351,13 @@ class UI (gconf_wrapper.GConfWrapper):
self.worker.start()
return True
- def stop_worker_thread (self, *args):
+ def stop_worker_thread(self):
if hasattr(self, 'worker'):
self.sudoku_maker.stop()
for c in self.worker_connections:
self.timer.disconnect(c)
- def stop_dancer (self, *args):
+ def stop_dancer(self):
if hasattr(self, 'dancer'):
self.dancer.stop_dancing()
delattr(self, 'dancer')
@@ -409,9 +410,9 @@ class UI (gconf_wrapper.GConfWrapper):
sublabel=label)
def _negotiate_result(self):
- def reply_handler(self, *args):
+ def reply_handler(*args):
print 'acknowledge reply', args
- def error_handler(self, error):
+ def error_handler(error):
print 'acknowledge error:', error
if self._is_initiator:
@@ -674,7 +675,7 @@ class UI (gconf_wrapper.GConfWrapper):
return jar
- def full_screen_cb (self, *args):
+ def full_screen_cb(self, action):
if self.is_fullscreen:
self.w.unfullscreen()
self.is_fullscreen = False
@@ -682,28 +683,28 @@ class UI (gconf_wrapper.GConfWrapper):
self.w.fullscreen()
self.is_fullscreen = True
- def clear_cb (self, *args):
+ def clear_cb(self, action):
self._main_model.reset_grid()
- def clear_notes_cb (self, *args):
+ def clear_notes_cb(self, action):
self._notes_model.clear_notes()
- def show_hint_cb (self, *args):
+ def show_hint_cb(self, action):
current = self._main_grid_vew.get_focus()
if current:
self._notes_model.show_hint(current.x, current.y)
- def auto_hint_cb (self, action):
+ def auto_hint_cb(self, action):
self._notes_model.toggle_auto_hint(action.get_active())
- def impossible_implication_cb (self, action):
+ def impossible_implication_cb(self, action):
self._main_model.toggle_impossible_implications(True)
- def auto_fill_cb (self, action):
+ def auto_fill_cb(self, action):
cmd = model.AutoFillCmd(self._main_model)
self._history_manager.execute_command(cmd)
- def auto_fill_current_square_cb (self, *args):
+ def auto_fill_current_square_cb(self, action):
current = self._main_grid_vew.get_focus()
if current:
x, y = current.x, current.y
@@ -731,7 +732,7 @@ class UI (gconf_wrapper.GConfWrapper):
self.statusbar.pop(self.sbid)
self.statusbar.push(self.sbid, status)
- def update_statusbar (self, *args):
+ def update_statusbar(self):
if not self._main_model:
self.set_statusbar_value(" ")
return True
@@ -747,7 +748,7 @@ class UI (gconf_wrapper.GConfWrapper):
def toggle_highlight_cb (self, widg):
self._main_grid_vew.toggle_highlight(widg.get_active())
- def show_info_cb (self, *args):
+ def show_info_cb(self, action):
if not self._main_model.grid:
dialog_extras.show_message(parent = self.w,
title = _("Puzzle Information"),
@@ -789,7 +790,7 @@ class UI (gconf_wrapper.GConfWrapper):
return self._main_model and self._main_model.grid.is_changed() and \
not self.won
- def show_about (self, *args):
+ def show_about(self, action):
about = gtk.AboutDialog()
about.set_transient_for(self.w)
about.set_name(APPNAME)
@@ -806,21 +807,21 @@ class UI (gconf_wrapper.GConfWrapper):
about.connect("response", lambda d, r: d.destroy())
about.show()
- def show_help (self, *args):
+ def show_help(self, action):
try:
gtk.show_uri(self.w.get_screen(), "ghelp:gnome-sudoku", gtk.get_current_event_time())
except gobject.GError, error:
# FIXME: This should create a pop-up dialog
print _('Unable to display help: %s') % str(error)
- def print_game (self, *args):
+ def print_game(self, action):
printing.print_sudokus([self._main_model], self.w)
- def print_multiple_games (self, *args):
+ def print_multiple_games(self, action):
gp = printing.GamePrinter(self.sudoku_maker, self.gconf)
gp.run_dialog()
- def generate_puzzle_gui (self, *args):
+ def generate_puzzle_gui(self, action):
sudoku_generator_gui.GameGenerator(self, self.gconf)
@@ -835,9 +836,9 @@ def start_game(debug=False):
## functions in a threaded GLib program.
gobject.threads_init()
- u = UI()
+ game = SudokuGame()
try:
gtk.main()
except KeyboardInterrupt:
# properly quit on a keyboard interrupt...
- u.quit_cb()
+ game.quit_cb()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]