+ # callback for puzzle grid mouse button release event
+ def on_puzzlegrid_button_release_event (self, drawarea, event):
+ self.window.set_focus (drawarea)
+ return True
+
+ # 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
+ # black block
+ last_occupied_row = self.selected_row
+ while True:
+ self.selected_row += step
+ if self.selected_row < 0 or self.selected_row >= self.puzzle.rows:
+ self.selected_row = last_occupied_row
+ break
+ if (self.puzzle.data[self.selected_row][self.selected_col].occupied_across is True
+ or self.puzzle.data[self.selected_row][self.selected_col].occupied_down is True):
+ break
+
+ # moving the current selection in grid by one across either way
+ def move_selection_across (self, step):
+ # increase or reduce the row by step until an occupied grid is found
+ # black block
+ last_occupied_col = self.selected_col
+ while True:
+ self.selected_col += step
+ if self.selected_col < 0 or self.selected_col >= self.puzzle.cols:
+ self.selected_col = last_occupied_col
+ break
+ if (self.puzzle.data[self.selected_row][self.selected_col].occupied_across is True
+ or self.puzzle.data[self.selected_row][self.selected_col].occupied_down is True):
+ break
+
+ # callback for puzzle grid key release event
+ def on_puzzlegrid_key_press_event (self, drawarea, event):
+ key = gtk.gdk.keyval_name (event.keyval)
+
+ if event.state == gtk.gdk.SHIFT_MASK and key == "Up":
+ # reduce the row by 1 until you find an occupied grid and not a
+ # black block
+ self.move_selection_updown (-1)
+ drawarea.queue_draw ()
+ elif event.state == gtk.gdk.SHIFT_MASK and key == "Down":
+ # increase the row by 1 until you find an occupied grid and not a
+ # black block
+ self.move_selection_updown (1)
+ drawarea.queue_draw ()
+ elif event.state == gtk.gdk.SHIFT_MASK and key == "Right":
+ # increase the column by 1 until you find an occupied grid and not
+ # a black block
+ self.move_selection_across (1)
+ drawarea.queue_draw ()
+ elif event.state == gtk.gdk.SHIFT_MASK and key == "Left":
+ # decrease the column by 1 until you find an occupied grid and not
+ # a black block
+ self.move_selection_across (-1)
+ drawarea.queue_draw ()
+ return False
+
+ # puzzle grid focus in event
+ def on_puzzlegrid_focus_out_event (self, drawarea, event):
+ col = drawarea.window.get_colormap ().alloc_color (gtk.gdk.Color ("gray"))
+ drawarea.window.set_background (col)
+
+ return False
+
+ # puzzle grid focus out event
+ def on_puzzlegrid_focus_in_event (self, drawarea, event):
+ col = drawarea.window.get_colormap ().alloc_color (gtk.gdk.Color ("white"))
+ drawarea.window.set_background (col)
+ return False
+
+ # callback for drawing the puzzle grid