[gnome-games/sudoku-tube] Fix the dancer



commit dcb7409493709b196363c495b508e17128a9b6dc
Author: Zhang Sen <zh jesse gmail com>
Date:   Sat Jul 18 12:14:42 2009 +0800

    Fix the dancer
    
    * It needs to know about the model, in order to perform box_dance and others.
    * The try-except seems useless, and is error-prone.

 gnome-sudoku/src/lib/dancer.py |   36 ++++++++++++++++++------------------
 gnome-sudoku/src/lib/main.py   |    2 +-
 2 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/dancer.py b/gnome-sudoku/src/lib/dancer.py
index d0e7ce6..5da8377 100644
--- a/gnome-sudoku/src/lib/dancer.py
+++ b/gnome-sudoku/src/lib/dancer.py
@@ -20,36 +20,37 @@ class GridDancer:
 
     STEPS_PER_ANIMATION = 10
 
-    def __init__ (self, grid):
+    def __init__ (self, view, model):
         self.animations = [self.value_dance,
                            self.box_dance,
                            self.col_dance,
                            self.row_dance,]
         self.current_animation = self.value_dance
         self.step = 0
-        self.grid = grid
+        self._view = view
+        self._model = model
         self.dancing = False
         self.adjustment = 0
 
     def start_dancing (self):
-        for box in self.grid.__entries__.values():
+        for box in self._view.__entries__.values():
             box.props.can_focus = False
             if box.read_only:
                 box.read_only = False
                 box.need_restore = True
             else:
                 box.need_restore = False
-        self.grid.get_toplevel().child_focus(gtk.DIR_TAB_BACKWARD)
+        self._view.get_toplevel().child_focus(gtk.DIR_TAB_BACKWARD)
         self.dancing = True
         gobject.timeout_add(350, self.dance_grid)
 
     def stop_dancing (self):
         self.dancing = False
-        for box in self.grid.__entries__.values():
+        for box in self._view.__entries__.values():
             box.props.can_focus = True
             if box.need_restore:
                 box.read_only = True
-        self.grid.unhighlight_cells()
+        self._view.unhighlight_cells()
 
     def dance_grid (self):
         if not self.dancing:
@@ -57,10 +58,7 @@ class GridDancer:
         if self.step > self.STEPS_PER_ANIMATION:
             self.rotate_animation()
         self.adjustment = (self.adjustment + 1) % 9
-        try:
-            self.current_animation()
-        except AttributeError:
-            return True
+        self.current_animation()
         self.step += 1
         if self.dancing:
             return True
@@ -79,26 +77,26 @@ class GridDancer:
         for x in range(9):
             color = self.next_color(x)
             for y in range(9):
-                self.grid.__entries__[(x, y)].set_background_color(color)
+                self._view.__entries__[(x, y)].set_background_color(color)
 
     def row_dance (self):
         for y in range(9):
             color = self.next_color(y)
             for x in range(9):
-                self.grid.__entries__[(x, y)].set_background_color(color)
+                self._view.__entries__[(x, y)].set_background_color(color)
 
     def box_dance (self):
         for box in range(9):
             color = self.next_color(box)
-            for x, y in self.grid.grid.box_coords[box]:
-                self.grid.__entries__[(x, y)].set_background_color(color)
+            for x, y in self._model.grid.box_coords[box]:
+                self._view.__entries__[(x, y)].set_background_color(color)
 
     def value_dance (self):
         for value in range(10):
             color = self.next_color(value)
             for x in range(9):
                 for y in range(9):
-                    box = self.grid.__entries__[(x, y)]
+                    box = self._view.__entries__[(x, y)]
                     if box.get_value() == value:
                         box.set_background_color(color)
 
@@ -115,8 +113,10 @@ if __name__ == '__main__':
                   4 6 9 1 8 7 5 3 2
                   1 2 8 9 5 3 6 7 4
                   7 5 3 4 6 2 8 1 9'''
-        gsd = gsudoku.SudokuGameDisplay(game)
-        dancer = GridDancer(gsd)
+        view = gsudoku.SudokuView(9)
+        model = gsudoku.SudokuModel(game, 9)
+        view.connect_to_model(model)
+        dancer = GridDancer(view, model)
 
         button = gtk.Button('toggle')
         button.connect('clicked',
@@ -124,7 +124,7 @@ if __name__ == '__main__':
                     else dancer.start_dancing())
 
         vbox = gtk.VBox()
-        vbox.pack_start(gsd)
+        vbox.pack_start(view)
         vbox.pack_end(button)
         vbox.set_focus_child(button)
 
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index db97053..eeea398 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -343,7 +343,7 @@ class UI (gconf_wrapper.GConfWrapper):
                                  self._main_model.auto_fills) % {
                                          'n':self._main_model.auto_fills}
         import dancer
-        self.dancer = dancer.GridDancer(self._main_grid_vew)
+        self.dancer = dancer.GridDancer(self._main_grid_vew, self._main_model)
         self.dancer.start_dancing()
         dialog_extras.show_message(_("You win!"), label = _("You win!"),
                                    sublabel = sublabel



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]