Exemplo n.º 1
0
 def do_key_press_event(self, event):
     action = KEY_MAP.get(event.keyval, None)
     if action == 'new':
         self.emit('new-key-pressed', 0)
         return True
     # Ignore key presses while animating.
     if self._is_animating():
         return False
     if not self._board_drawer.board_is_valid():
         self._board_drawer.set_selected_cell(None)
         return action is not None
     else:
         selected_cell = self._board_drawer.get_selected_cell()
         if selected_cell is None:
             self._board_drawer.select_center_cell()
             return True
         else:
             if action == 'select':
                 self.emit('piece-selected', *selected_cell)
             elif action == 'undo':
                 self.emit('undo-key-pressed', 0)
             elif action == 'redo':
                 self.emit('redo-key-pressed', 0)
             else:
                 offsets = {'up'    : ( 0,  1),
                            'down'  : ( 0, -1),
                            'left'  : (-1,  0),
                            'right' : ( 1,  0)}
                 if action in offsets:
                     offset = offsets[action]
                     return self._board_drawer.move_selected_cell(*offset)
                 else:
                     return False
Exemplo n.º 2
0
 def _key_press_event_cb(self, source, event):
     # Make the game navigable by keypad controls.
     action = KEY_MAP.get(event.keyval, None)
     if action is None:
         return False
     if not self._stuck_strip.get_state_flags() & Gtk.AccelFlags.VISIBLE:
         return True
     if self._game.get_focus_child():
         if action == 'down':
             self._stuck_strip.button.grab_focus()
         return True
     elif self._stuck_strip.get_focus_child():
         if action == 'up':
             self._game.grab_focus()
         elif action == 'select':
             self._stuck_strip.button.activate()
         return True
     return True
Exemplo n.º 3
0
 def _key_press_event_cb(self, source, event):
     # Make the game navigable by keypad controls.
     action = KEY_MAP.get(event.keyval, None)
     if action is None:
         return False
     if not self._stuck_strip.get_state_flags() & Gtk.AccelFlags.VISIBLE:
         return True
     if self._game.get_focus_child():
         if action == 'down':
             self._stuck_strip.button.grab_focus()
         return True
     elif self._stuck_strip.get_focus_child():
         if action == 'up':
             self._game.grab_focus()
         elif action == 'select':
             self._stuck_strip.button.activate()
         return True
     return True
Exemplo n.º 4
0
 def _key_press_event_cb(self, source, event):
     # Make the game navigable by keypad controls.
     action = KEY_MAP.get(event.keyval, None)
     if action is None:
         return False
     if not self._stuck_strip.flags() & gtk.VISIBLE:
         return True
     if self.game.focus_child:
         if action == "down":
             self._stuck_strip.button.grab_focus()
         return True
     elif self._stuck_strip.focus_child:
         if action == "up":
             self.game.grab_focus()
         elif action == "select":
             self._stuck_strip.button.activate()
         return True
     return True
Exemplo n.º 5
0
 def do_key_press_event(self, event):
     action = KEY_MAP.get(event.keyval, None)
     if (action == 'new') or \
        (action == 'select' and not self._board_drawer.board_is_valid()):
         self.emit('new-key-pressed', 0)
         return True
     # Ignore key presses while animating.
     if self._is_animating():
         return False
     if not self._board_drawer.board_is_valid():
         self._board_drawer.set_selected_cell(None)
         return action is not None
     else:
         selected_cell = self._board_drawer.get_selected_cell()
         if selected_cell is None:
             self._board_drawer.select_center_cell()
             return True
         else:
             if action == 'select':
                 self.emit('piece-selected', *selected_cell)
             elif action == 'undo':
                 self.emit('undo-key-pressed', 0)
             elif action == 'redo':
                 self.emit('redo-key-pressed', 0)
             else:
                 offsets = {
                     'up': (0, 1),
                     'down': (0, -1),
                     'left': (-1, 0),
                     'right': (1, 0)
                 }
                 if action in offsets:
                     offset = offsets[action]
                     return self._board_drawer.move_selected_cell(*offset)
                 else:
                     return False