Fixed the problem of focus changing on arrow key
[getaclue.git] / player_mainwindow.py
index e167f03..6ba9137 100644 (file)
@@ -211,6 +211,10 @@ along with GetAClue.  If not, see <http://www.gnu.org/licenses/>."""
 
                self.set_selection_of_num (anum)
 
 
                self.set_selection_of_num (anum)
 
+               # focus on the drawing area
+               puzgrid = self.ui.get_object ("puzzlegrid")
+               self.window.set_focus (puzgrid)
+
                return False
 
        # callback for tree view "down" being activated
                return False
 
        # callback for tree view "down" being activated
@@ -223,6 +227,10 @@ along with GetAClue.  If not, see <http://www.gnu.org/licenses/>."""
 
                self.set_selection_of_num (dnum, False)
 
 
                self.set_selection_of_num (dnum, False)
 
+               # focus on the drawing area
+               puzgrid = self.ui.get_object ("puzzlegrid")
+               self.window.set_focus (puzgrid)
+
        # moving the current selection in grid by one up or down
        def move_selection_updown (self, step):
                # increase or reduce the row by step until an occupied grid is found
        # moving the current selection in grid by one up or down
        def move_selection_updown (self, step):
                # increase or reduce the row by step until an occupied grid is found
@@ -322,58 +330,64 @@ along with GetAClue.  If not, see <http://www.gnu.org/licenses/>."""
                return False
 
        # callback for main window key release event
                return False
 
        # callback for main window key release event
-       def on_mainwindow_key_press_event (self, window, event):
+       def on_puzzlegrid_key_press_event (self, drawarea, event):
                if self.puzzle:
                if self.puzzle:
-                       drawarea = self.ui.get_object ("puzzlegrid")
                        key = gtk.gdk.keyval_name (event.keyval).lower ()
 
                        key = gtk.gdk.keyval_name (event.keyval).lower ()
 
-                       if event.state == gtk.gdk.SHIFT_MASK and key == "up":
+                       if key == "up":
                                # reduce the row by 1 until you find an occupied grid and not a
                                # black block
                                self.move_selection_updown (-1)
                                self.typing_mode = self.DOWN
                                drawarea.queue_draw ()
                                # reduce the row by 1 until you find an occupied grid and not a
                                # black block
                                self.move_selection_updown (-1)
                                self.typing_mode = self.DOWN
                                drawarea.queue_draw ()
-                       elif event.state == gtk.gdk.SHIFT_MASK and key == "down":
+                               return True
+                       elif key == "down":
                                # increase the row by 1 until you find an occupied grid and not a
                                # black block
                                self.move_selection_updown (1)
                                self.typing_mode = self.DOWN
                                drawarea.queue_draw ()
                                # increase the row by 1 until you find an occupied grid and not a
                                # black block
                                self.move_selection_updown (1)
                                self.typing_mode = self.DOWN
                                drawarea.queue_draw ()
-                       elif event.state == gtk.gdk.SHIFT_MASK and key == "right":
+                               return True
+                       elif key == "right":
                                # increase the column by 1 until you find an occupied grid and not
                                # a black block
                                self.move_selection_across (1)
                                self.typing_mode = self.ACROSS
                                drawarea.queue_draw ()
                                # increase the column by 1 until you find an occupied grid and not
                                # a black block
                                self.move_selection_across (1)
                                self.typing_mode = self.ACROSS
                                drawarea.queue_draw ()
-                       elif event.state == gtk.gdk.SHIFT_MASK and key == "left":
+                               return True
+                       elif key == "left":
                                # decrease the column by 1 until you find an occupied grid and not
                                # a black block
                                self.move_selection_across (-1)
                                self.typing_mode = self.ACROSS
                                drawarea.queue_draw ()
                                # decrease the column by 1 until you find an occupied grid and not
                                # a black block
                                self.move_selection_across (-1)
                                self.typing_mode = self.ACROSS
                                drawarea.queue_draw ()
+                               return True
                        # if it is A-Z or a-z then
                        elif len (key) == 1 and key.isalpha ():
                                guess_char = key.upper ()
                                self.set_guess (guess_char)
                                drawarea.queue_draw ()
                        # if it is A-Z or a-z then
                        elif len (key) == 1 and key.isalpha ():
                                guess_char = key.upper ()
                                self.set_guess (guess_char)
                                drawarea.queue_draw ()
+                               return True
                        # if it is the delete key then delete character at selected row/col
                        elif key == "delete":
                                self.puzzle.data[self.selected_row][self.selected_col].guess = None
                                drawarea.queue_draw ()
                        # if it is the delete key then delete character at selected row/col
                        elif key == "delete":
                                self.puzzle.data[self.selected_row][self.selected_col].guess = None
                                drawarea.queue_draw ()
+                               return True
                        # if the key is space key then delete character and move across or
                        # down one step depending on the mode
                        elif key == "space":
                                self.set_guess (None)
                                drawarea.queue_draw ()
                        # if the key is space key then delete character and move across or
                        # down one step depending on the mode
                        elif key == "space":
                                self.set_guess (None)
                                drawarea.queue_draw ()
+                               return True
                        # if it is backspace key then delete character at previous row/col
                        # depending on the input mode. If across editing mode, then delete
                        # at previous column else at previous row
                        elif key == "backspace":
                                self.delete_prev_guess ()
                                drawarea.queue_draw ()
                        # if it is backspace key then delete character at previous row/col
                        # depending on the input mode. If across editing mode, then delete
                        # at previous column else at previous row
                        elif key == "backspace":
                                self.delete_prev_guess ()
                                drawarea.queue_draw ()
+                               return True
 
                return False
 
                return False
-
        # puzzle grid focus in event
        def on_puzzlegrid_focus_out_event (self, drawarea, event):
                if self.puzzle:
        # puzzle grid focus in event
        def on_puzzlegrid_focus_out_event (self, drawarea, event):
                if self.puzzle: