summaryrefslogtreecommitdiff
path: root/grc/gui
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2009-09-13 03:25:56 -0700
committerJosh Blum <josh@joshknows.com>2009-09-13 03:25:56 -0700
commitae3c009666f2bba0e10e054b0747d8f82a29515f (patch)
tree8607336925431206e0a76621eb738fcfcd64aaa4 /grc/gui
parent6bd669d6e2fbe4b0ba5f74b697e532cf909c9e1d (diff)
tweaked key handling callbacks
Diffstat (limited to 'grc/gui')
-rw-r--r--grc/gui/ActionHandler.py4
-rw-r--r--grc/gui/Actions.py13
2 files changed, 8 insertions, 9 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 59e535bd49..361be1cf8f 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -81,9 +81,7 @@ class ActionHandler:
"""
try: assert self.get_focus_flag()
except AssertionError: return False
- try: Actions.get_action_from_key_press(event)()
- except KeyError: return False
- return True #handled by this method
+ return Actions.handle_key_press(event)
def _quit(self, window, event):
"""
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index 90017987f6..b22279c1da 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -29,13 +29,12 @@ NO_MODS_MASK = 0
_actions_keypress_dict = dict()
_keymap = gtk.gdk.keymap_get_default()
_used_mods_mask = NO_MODS_MASK
-def get_action_from_key_press(event):
+def handle_key_press(event):
"""
- Get the action associated with the key press event.
+ Call the action associated with the key press event.
Both the key value and the mask must have a match.
@param event a gtk key press event
- @throws a key error when no action matches
- @return the action object
+ @return true if handled
"""
_used_mods_mask = reduce(lambda x, y: x | y, [mod_mask for keyval, mod_mask in _actions_keypress_dict], NO_MODS_MASK)
#extract the key value and the consumed modifiers
@@ -43,8 +42,10 @@ def get_action_from_key_press(event):
event.hardware_keycode, event.state, event.group)
#get the modifier mask and ignore irrelevant modifiers
mod_mask = event.state & ~consumed & _used_mods_mask
- try: return _actions_keypress_dict[(keyval, mod_mask)]
- except KeyError: raise KeyError, 'Keypress: "%s, %s" does not have an associated action'%(gtk.gdk.keyval_name(keyval), mod_mask)
+ #look up the keypress and call the action
+ try: _actions_keypress_dict[(keyval, mod_mask)]()
+ except KeyError: return False #not handled
+ return True #handled here
_all_actions_list = list()
def get_all_actions(): return _all_actions_list