[gnome-games/sudoku-tube] Extract method of setting focus
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/sudoku-tube] Extract method of setting focus
- Date: Wed, 8 Jul 2009 14:57:41 +0000 (UTC)
commit f3449c7dbedc7608d2d3328d7dbfa40ddfecae97
Author: Zhang Sen <zh jesse gmail com>
Date: Wed Jul 8 22:08:57 2009 +0800
Extract method of setting focus
* Put this method in a base-class, not directly in SudokuGameDisplay
* Rewrite _go_around, though not perfect yet
gnome-sudoku/src/lib/gsudoku.py | 30 ++++++++++++++++--------------
1 files changed, 16 insertions(+), 14 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index 71c4e06..d2848a5 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -101,6 +101,9 @@ class SudokuNumberGrid (gtk.AspectFrame):
def set_readonly_appearance(self, x, y, flag):
self.__entries__[(x, y)].set_read_only(flag)
+ def set_focus(self, x, y):
+ self.table.set_focus_child(self.__entries__[x, y])
+
class ParallelDict (dict):
"""A handy new sort of dictionary for tracking conflicts.
@@ -178,25 +181,24 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
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])
+ 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)
- if (y, direction) == (limit_min, 'Up'):
- dest = (x, limit_max)
- elif (y, direction) == (limit_max, 'Down'):
- dest = (x, limit_min)
- elif (x, direction) == (limit_min, 'Left'):
- dest = (limit_max, y)
- elif (x, direction) == (limit_max, 'Right'):
- dest = (limit_min, y)
+ 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_edge = {limit_min: limit_max, limit_max: limit_min}
+
+ if (y, direction) in y_edge:
+ return x, opposite_edge[y]
+ elif (x, direction) in x_edge:
+ return opposite_edge[x], y
else:
- return None
- return dest
+ return None, None
def _focus_callback(self, e, event):
self.focused = e
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]