gnome-games r9002 - trunk/gnome-sudoku/src/lib



Author: thomashpa
Date: Mon Apr  6 23:59:12 2009
New Revision: 9002
URL: http://svn.gnome.org/viewvc/gnome-games?rev=9002&view=rev

Log:
Move to focus to other side when moving out of the grid. Patch by Zhang Sen. Fixes bug #530171

Modified:
   trunk/gnome-sudoku/src/lib/gsudoku.py

Modified: trunk/gnome-sudoku/src/lib/gsudoku.py
==============================================================================
--- trunk/gnome-sudoku/src/lib/gsudoku.py	(original)
+++ trunk/gnome-sudoku/src/lib/gsudoku.py	Mon Apr  6 23:59:12 2009
@@ -752,8 +752,31 @@
             e.connect('undo-change',self.entry_callback)
             e.connect('changed',self.entry_callback)
             e.connect('focus-in-event',self.focus_callback)
+            e.connect('key-press-event', self.key_press_cb, e.x, e.y)
         self.connect('focus-changed',self.highlight_cells)
 
+    def key_press_cb (self, widget, event, x, y):
+        key = gtk.gdk.keyval_name(event.keyval)
+        dest = self.go_around(x, y, key)
+        if dest:
+            self.table.set_focus_child(self.__entries__[dest])
+
+    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)
+        else:
+            return None
+        return dest
+
     @simple_debug
     def focus_callback (self, e, event):
         self.focused = e



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