[gnome-games/sudoku-tube] Move method into parent class
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games/sudoku-tube] Move method into parent class
- Date: Mon, 17 Aug 2009 14:16:15 +0000 (UTC)
commit a8fe79fbfd33a678897d572fa5f9bafb29e0c91f
Author: Zhang Sen <zh jesse gmail com>
Date: Mon Aug 17 20:44:12 2009 +0800
Move method into parent class
gnome-sudoku/src/lib/view.py | 48 +++++++++++++++++++++---------------------
1 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/view.py b/gnome-sudoku/src/lib/view.py
index 9c05163..c2e995c 100644
--- a/gnome-sudoku/src/lib/view.py
+++ b/gnome-sudoku/src/lib/view.py
@@ -141,9 +141,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
+ e.connect('key-press-event', self._key_press_cb)
def _allocate_cb (self, widget, rect):
if rect.width > rect.height:
@@ -209,6 +209,28 @@ class SudokuNumberGrid (gtk.AspectFrame):
def reset(self):
pass
+ 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):
def __init__(self, group_size, controller=None):
@@ -230,7 +252,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)
@@ -351,12 +372,6 @@ class SudokuView(SudokuNumberGrid):
if self._do_highlight_cells:
self._highlight_cells()
- 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 toggle_highlight (self, val):
self._do_highlight_cells = val
if val:
@@ -414,21 +429,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]