[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10883 - gnuradio/branches/developers/jblum/grc/grc/sr
From: |
jblum |
Subject: |
[Commit-gnuradio] r10883 - gnuradio/branches/developers/jblum/grc/grc/src/gui |
Date: |
Sun, 19 Apr 2009 18:30:21 -0600 (MDT) |
Author: jblum
Date: 2009-04-19 18:30:21 -0600 (Sun, 19 Apr 2009)
New Revision: 10883
Modified:
gnuradio/branches/developers/jblum/grc/grc/src/gui/ActionHandler.py
gnuradio/branches/developers/jblum/grc/grc/src/gui/Actions.py
Log:
Unified the hotkey handling so mapping is in one place (Actions.py).
And handling is separated from mapping (ActionHandler.py).
Modified: gnuradio/branches/developers/jblum/grc/grc/src/gui/ActionHandler.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/gui/ActionHandler.py
2009-04-19 21:22:45 UTC (rev 10882)
+++ gnuradio/branches/developers/jblum/grc/grc/src/gui/ActionHandler.py
2009-04-20 00:30:21 UTC (rev 10883)
@@ -58,7 +58,7 @@
#setup the main window
self.main_window = MainWindow(self.handle_states, platform)
self.main_window.connect('delete_event', self._quit)
- self.main_window.connect('key_press_event',
self._handle_key_press)
+ self.main_window.connect('key-press-event',
self._handle_key_press)
self.get_page = self.main_window.get_page
self.get_flow_graph = self.main_window.get_flow_graph
self.get_focus_flag =
self.main_window.drawing_area.get_focus_flag
@@ -73,34 +73,25 @@
def _handle_key_press(self, widget, event):
"""
- Handle key presses from the keyboard and translate key combos
into actions.
- This key press handler is called before the gtk accelerators
kick in.
- This handler ensures that key presses without a mod mask,
- only pass to the accelerators if the flow graph is in focus.
- This function also handles keys that accelerators refuse to
handle: left/right,
- and keys that are not registered with an accelerator: +/-.
- @return false to let the accelerators handle the key action
+ Handle key presses from the keyboard and translate key
combinations into actions.
+ This key press handler is called prior to the gtk key press
handler.
+ This handler bypasses built in accelerator key handling when in
focus because
+ * some keys are ignored by the accelerators like the direction
keys,
+ * some keys are not registered to any accelerators but are
still used.
+ When not in focus, gtk and the accelerators handle the the key
press.
+ @return false to let gtk handle the key action
"""
#dont allow key presses to queue up
if gtk.events_pending(): return True
- if self.get_focus_flag():
- try:
- self.handle_states({
- 'Left': Actions.BLOCK_ROTATE_CCW,
- 'Right': Actions.BLOCK_ROTATE_CW,
- 'Up': Actions.BLOCK_DEC_TYPE,
- 'Down': Actions.BLOCK_INC_TYPE,
- 'equal': Actions.PORT_CONTROLLER_INC,
- 'plus': Actions.PORT_CONTROLLER_INC,
- 'KP_Add': Actions.PORT_CONTROLLER_INC,
- 'minus': Actions.PORT_CONTROLLER_DEC,
- 'KP_Subtract':
Actions.PORT_CONTROLLER_DEC,
- }[gtk.gdk.keyval_name(event.keyval)])
- return True
- #focus: always return false for accelerator to handle
- except: return False
- #no focus: only allow accelerator to handle when a mod is used
- return not event.state
+ #extract action name from this key press
+ key_name = gtk.gdk.keyval_name(event.keyval)
+ mod_mask = event.state
+ action_name = Actions.get_action_name_from_key_name(key_name,
mod_mask)
+ #handle the action if flow graph is in focus
+ if action_name and self.get_focus_flag():
+ self.handle_states(action_name)
+ return True #handled by this method
+ return False #let gtk handle the key press
def _quit(self, window, event):
"""
Modified: gnuradio/branches/developers/jblum/grc/grc/src/gui/Actions.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/gui/Actions.py
2009-04-19 21:22:45 UTC (rev 10882)
+++ gnuradio/branches/developers/jblum/grc/grc/src/gui/Actions.py
2009-04-20 00:30:21 UTC (rev 10883)
@@ -61,32 +61,53 @@
######################################################################################################
# Action Key Map
######################################################################################################
-_actions_key_map = {
- #action name: (key name, mask)
- FLOW_GRAPH_NEW: ('n', gtk.gdk.CONTROL_MASK),
- FLOW_GRAPH_OPEN: ('o', gtk.gdk.CONTROL_MASK),
- FLOW_GRAPH_SAVE: ('s', gtk.gdk.CONTROL_MASK),
- FLOW_GRAPH_SAVE_AS: ('s', gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
- FLOW_GRAPH_CLOSE: ('w', gtk.gdk.CONTROL_MASK),
- APPLICATION_QUIT: ('q', gtk.gdk.CONTROL_MASK),
- FLOW_GRAPH_UNDO: ('z', gtk.gdk.CONTROL_MASK),
- FLOW_GRAPH_REDO: ('y', gtk.gdk.CONTROL_MASK),
- ELEMENT_DELETE: ('Delete', 0),
- BLOCK_ROTATE_CCW: ('Left', 0),
- BLOCK_ROTATE_CW: ('Right', 0),
- BLOCK_PARAM_MODIFY: ('Return', 0),
- BLOCK_ENABLE: ('e', 0),
- BLOCK_DISABLE: ('d', 0),
- BLOCK_CUT: ('x', gtk.gdk.CONTROL_MASK),
- BLOCK_COPY: ('c', gtk.gdk.CONTROL_MASK),
- BLOCK_PASTE: ('v', gtk.gdk.CONTROL_MASK),
- FLOW_GRAPH_GEN: ('F5', 0),
- FLOW_GRAPH_EXEC: ('F6', 0),
- FLOW_GRAPH_KILL: ('F7', 0),
- FLOW_GRAPH_SCREEN_CAPTURE: ('Print', 0),
- HELP_WINDOW_DISPLAY: ('F1', 0),
-}
+_actions_key_list = (
+ #action name, key name, mod mask
+ (FLOW_GRAPH_NEW, 'n', gtk.gdk.CONTROL_MASK),
+ (FLOW_GRAPH_OPEN, 'o', gtk.gdk.CONTROL_MASK),
+ (FLOW_GRAPH_SAVE, 's', gtk.gdk.CONTROL_MASK),
+ (FLOW_GRAPH_SAVE_AS, 's', gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
+ (FLOW_GRAPH_CLOSE, 'w', gtk.gdk.CONTROL_MASK),
+ (APPLICATION_QUIT, 'q', gtk.gdk.CONTROL_MASK),
+ (FLOW_GRAPH_UNDO, 'z', gtk.gdk.CONTROL_MASK),
+ (FLOW_GRAPH_REDO, 'y', gtk.gdk.CONTROL_MASK),
+ (ELEMENT_DELETE, 'Delete', 0),
+ (BLOCK_ROTATE_CCW, 'Left', 0),
+ (BLOCK_ROTATE_CW, 'Right', 0),
+ (BLOCK_DEC_TYPE, 'Up', 0),
+ (BLOCK_INC_TYPE, 'Down', 0),
+ (BLOCK_PARAM_MODIFY, 'Return', 0),
+ (BLOCK_ENABLE, 'e', 0),
+ (BLOCK_DISABLE, 'd', 0),
+ (BLOCK_CUT, 'x', gtk.gdk.CONTROL_MASK),
+ (BLOCK_COPY, 'c', gtk.gdk.CONTROL_MASK),
+ (BLOCK_PASTE, 'v', gtk.gdk.CONTROL_MASK),
+ (FLOW_GRAPH_GEN, 'F5', 0),
+ (FLOW_GRAPH_EXEC, 'F6', 0),
+ (FLOW_GRAPH_KILL, 'F7', 0),
+ (FLOW_GRAPH_SCREEN_CAPTURE, 'Print', 0),
+ (HELP_WINDOW_DISPLAY, 'F1', 0),
+ #the following have no associated gtk.Action
+ (PORT_CONTROLLER_INC, 'equal', 0),
+ (PORT_CONTROLLER_INC, 'plus', 0),
+ (PORT_CONTROLLER_INC, 'KP_Add', 0),
+ (PORT_CONTROLLER_DEC, 'minus', 0),
+ (PORT_CONTROLLER_DEC, 'KP_Subtract', 0),
+)
+_actions_key_dict = dict(((key_name, mod_mask), action_name) for action_name,
key_name, mod_mask in _actions_key_list)
+def get_action_name_from_key_name(key_name, mod_mask=0):
+ """
+ Get the action name associated with the key name and mask.
+ Both keyname and mask have to match.
+ @param key_name the name of the key
+ @param mod_mask the key press mask (shift, ctrl) 0 for none
+ @return the action name or blank string
+ """
+ key_name_mod_mask = (key_name, mod_mask)
+ if key_name_mod_mask in _actions_key_dict: return
_actions_key_dict[key_name_mod_mask]
+ return ''
+
######################################################################################################
# Actions
######################################################################################################
@@ -126,16 +147,21 @@
@throw KeyError bad action name
@return a gtk action object
"""
- if _actions_dict.has_key(action_name): return _actions_dict[action_name]
+ if action_name in _actions_dict: return _actions_dict[action_name]
raise KeyError('Action Name: "%s" does not exist'%action_name)
+######################################################################################################
+# Accelerators
+######################################################################################################
_accel_group = gtk.AccelGroup()
def get_accel_group(): return _accel_group
-#load the actions key map
#set the accelerator group, and accelerator path
-#register the key and mod with the accelerator path
-for action_name, (key_name, mod) in _actions_key_map.iteritems():
- get_action_from_name(action_name).set_accel_group(get_accel_group())
- get_action_from_name(action_name).set_accel_path('<main>/'+action_name)
- gtk.accel_map_add_entry('<main>/'+action_name,
gtk.gdk.keyval_from_name(key_name),mod)
+#register the key name and mod mask with the accelerator path
+for action_name, key_name, mod_mask in _actions_key_list:
+ try:
+ accel_path = '<main>/'+action_name
+
get_action_from_name(action_name).set_accel_group(get_accel_group())
+ get_action_from_name(action_name).set_accel_path(accel_path)
+ gtk.accel_map_add_entry(accel_path,
gtk.gdk.keyval_from_name(key_name), mod_mask)
+ except KeyError: pass #no action was created for this action name
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10883 - gnuradio/branches/developers/jblum/grc/grc/src/gui,
jblum <=