[gnome-games/applygsoc2009: 74/76] XXX: Move method into parent class



commit f3d74210ca3527eeb2ad1051a2819284cd98a1d0
Author: Pablo Castellano <pablog src gnome org>
Date:   Wed Sep 1 05:34:47 2010 +0200

    XXX: Move method into parent class

 gnome-sudoku/src/lib/view.py |   60 ++++++++++++++++--------------------------
 1 files changed, 23 insertions(+), 37 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/view.py b/gnome-sudoku/src/lib/view.py
index 6920f42..6ef3d7f 100644
--- a/gnome-sudoku/src/lib/view.py
+++ b/gnome-sudoku/src/lib/view.py
@@ -118,22 +118,9 @@ class SudokuNumberGrid (gtk.AspectFrame):
                 e = number_box.SudokuNumberBox(upper = self.group_size)
                 e.x = x
                 e.y = y
-                self.table.attach(e, x, x+1, y, y+1,
-                                  )
+                self.table.attach(e, x, x+1, y, y+1)
                 self.__entries__[(x, y)] = e
-        gtk.AspectFrame.__init__(self, obey_child = False)
-        self.set_shadow_type(gtk.SHADOW_NONE)
-        self.eb = gtk.EventBox()
-        self.eb.add(self.table)
-        self.add(self.eb)
-        self.table.set_row_spacings(1)
-        self.table.set_col_spacings(1)
-        box_side = int(math.sqrt(self.group_size))
-        for n in range(1, box_side):
-            self.table.set_row_spacing(box_side*n-1, 2)
-            self.table.set_col_spacing(box_side*n-1, 2)
-        self.table.set_border_width(2)
-        self.show_all()
+                e.connect('key-press-event', self._key_press_cb)
 
     def set_color(self, x, y, color):
         self.__entries__[(x, y)].set_color(color)
@@ -171,6 +158,27 @@ class SudokuNumberGrid (gtk.AspectFrame):
     def set_value(self, x, y, value):
         self.__entries__[(x, y)].set_value(value)
 
+    def _key_press_cb(self, widget, event):
+        key = gtk.gdk.keyval_name(event.keyval)
+        dest_x, dest_y = self._go_around(widget.x, widget.y, key)
+        if dest_x is not None:
+            self.set_focus(dest_x, dest_y)
+
+    def _go_around(self, x, y, direction):
+        '''return the coordinate if we should go to the other side of the grid.
+        Or else return None.'''
+        limit_min, limit_max = 0, self.group_size - 1
+        y_edge = [(limit_min, 'Up'), (limit_max, 'Down')]
+        x_edge = [(limit_min, 'Left'), (limit_max, 'Right')]
+        opposite = {limit_min: limit_max, limit_max: limit_min}
+
+        if (y, direction) in y_edge:
+            return x, opposite[y]
+        elif (x, direction) in x_edge:
+            return opposite[x], y
+        else:
+            return None, None
+
 
 class SudokuView(SudokuNumberGrid):
 
@@ -196,7 +204,6 @@ class SudokuView(SudokuNumberGrid):
                 e.connect('number-changed', self._number_changed_cb)
                 e.connect('notes-changed', self._notes_changed_cb)
                 e.connect('focus-in-event', self._focus_callback)
-                e.connect('key-press-event', self._key_press_cb)
         
         self._tracker = _Tracker(self)
 
@@ -310,12 +317,6 @@ class SudokuView(SudokuNumberGrid):
             self._highlight_cells()
 #        self.emit('focus-changed')
 
-    def _key_press_cb (self, widget, event):
-        key = gtk.gdk.keyval_name(event.keyval)
-        dest = self._go_around(widget.x, widget.y, key)
-        if dest:
-            self.table.set_focus_child(self.__entries__[dest])
-
     def toggle_highlight (self, val):
         self._do_highlight_cells = val
         if val:
@@ -375,21 +376,6 @@ class SudokuView(SudokuNumberGrid):
         self.col_color = colors.rotate_hue_rgb(*self.box_color, **{'rotate_by': 0.66})
         self.box_and_col_color = colors.rotate_hue_rgb(*self.box_color, **{'rotate_by': 1.0 - (0.33 / 2)})
 
-    def _go_around(self, x, y, direction):
-        '''return the coordinate if we should go to the other side of the grid.
-        Or else return None.'''
-        limit_min, limit_max = 0, self.group_size - 1
-        y_edge = [(limit_min, 'Up'), (limit_max, 'Down')]
-        x_edge = [(limit_min, 'Left'), (limit_max, 'Right')]
-        opposite = {limit_min: limit_max, limit_max: limit_min}
-
-        if (y, direction) in y_edge:
-            return x, opposite[y]
-        elif (x, direction) in x_edge:
-            return opposite[x], y
-        else:
-            return None, None
-
     def get_tracker_controller(self):
         return self._tracker
 



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