2 Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 ########################################################################
28 ########################################################################
29 _actions_keypress_dict = dict()
30 _keymap = gtk.gdk.keymap_get_default()
31 _used_mods_mask = NO_MODS_MASK
32 def get_action_from_key_press(event):
34 Get the action associated with the key press event.
35 Both the key value and the mask must have a match.
36 @param event a gtk key press event
37 @throws a key error when no action matches
38 @return the action object
40 _used_mods_mask = reduce(lambda x, y: x | y, [mod_mask for keyval, mod_mask in _actions_keypress_dict], NO_MODS_MASK)
41 #extract the key value and the consumed modifiers
42 keyval, egroup, level, consumed = _keymap.translate_keyboard_state(
43 event.hardware_keycode, event.state, event.group)
44 #get the modifier mask and ignore irrelevant modifiers
45 mod_mask = event.state & ~consumed & _used_mods_mask
46 try: return _actions_keypress_dict[(keyval, mod_mask)]
47 except KeyError: raise KeyError, 'Keypress: "%s, %s" does not have an associated action'%(gtk.gdk.keyval_name(keyval), mod_mask)
49 _all_actions_list = list()
50 def get_all_actions(): return _all_actions_list
52 _accel_group = gtk.AccelGroup()
53 def get_accel_group(): return _accel_group
55 class Action(gtk.Action):
57 A custom Action class based on gtk.Action.
58 Pass additional arguments such as keypresses.
59 Register actions and keypresses with this module.
62 def __init__(self, keypresses=(), name=None, label=None, tooltip=None, stock_id=None):
64 Create a new Action instance.
65 @param key_presses a tuple of (keyval1, mod_mask1, keyval2, mod_mask2, ...)
66 @param the regular gtk.Action parameters (defaults to None)
68 if name is None: name = label
69 gtk.Action.__init__(self,
70 name=name, label=label,
71 tooltip=tooltip, stock_id=stock_id,
74 _all_actions_list.append(self)
75 for i in range(len(keypresses)/2):
76 keyval, mod_mask = keypresses[i*2:(i+1)*2]
77 #register this keypress
78 assert not _actions_keypress_dict.has_key((keyval, mod_mask))
79 _actions_keypress_dict[(keyval, mod_mask)] = self
80 #set the accelerator group, and accelerator path
81 #register the key name and mod mask with the accelerator path
82 if label is None: continue #dont register accel
83 accel_path = '<main>/'+self.get_name()
84 self.set_accel_group(get_accel_group())
85 self.set_accel_path(accel_path)
86 gtk.accel_map_add_entry(accel_path, keyval, mod_mask)
90 The string representation should be the name of the action id.
91 Try to find the action id for this action by searching this module.
95 return filter(lambda attr: getattr(Actions, attr) == self, dir(Actions))[0]
96 except: return self.get_name()
98 def __repr__(self): return str(self)
102 Emit the activate signal when called with ().
104 self.emit('activate')
106 ########################################################################
108 ########################################################################
109 PAGE_CHANGE = Action()
110 FLOW_GRAPH_NEW = Action(
112 tooltip='Create a new flow graph',
113 stock_id=gtk.STOCK_NEW,
114 keypresses=(gtk.keysyms.n, gtk.gdk.CONTROL_MASK),
116 FLOW_GRAPH_OPEN = Action(
118 tooltip='Open an existing flow graph',
119 stock_id=gtk.STOCK_OPEN,
120 keypresses=(gtk.keysyms.o, gtk.gdk.CONTROL_MASK),
122 FLOW_GRAPH_SAVE = Action(
124 tooltip='Save the current flow graph',
125 stock_id=gtk.STOCK_SAVE,
126 keypresses=(gtk.keysyms.s, gtk.gdk.CONTROL_MASK),
128 FLOW_GRAPH_SAVE_AS = Action(
130 tooltip='Save the current flow graph as...',
131 stock_id=gtk.STOCK_SAVE_AS,
132 keypresses=(gtk.keysyms.s, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
134 FLOW_GRAPH_CLOSE = Action(
136 tooltip='Close the current flow graph',
137 stock_id=gtk.STOCK_CLOSE,
138 keypresses=(gtk.keysyms.w, gtk.gdk.CONTROL_MASK),
140 APPLICATION_INITIALIZE = Action()
141 APPLICATION_QUIT = Action(
143 tooltip='Quit program',
144 stock_id=gtk.STOCK_QUIT,
145 keypresses=(gtk.keysyms.q, gtk.gdk.CONTROL_MASK),
147 FLOW_GRAPH_UNDO = Action(
149 tooltip='Undo a change to the flow graph',
150 stock_id=gtk.STOCK_UNDO,
151 keypresses=(gtk.keysyms.z, gtk.gdk.CONTROL_MASK),
153 FLOW_GRAPH_REDO = Action(
155 tooltip='Redo a change to the flow graph',
156 stock_id=gtk.STOCK_REDO,
157 keypresses=(gtk.keysyms.y, gtk.gdk.CONTROL_MASK),
159 NOTHING_SELECT = Action()
160 ELEMENT_SELECT = Action()
161 ELEMENT_CREATE = Action()
162 ELEMENT_DELETE = Action(
164 tooltip='Delete the selected blocks',
165 stock_id=gtk.STOCK_DELETE,
166 keypresses=(gtk.keysyms.Delete, NO_MODS_MASK),
168 BLOCK_MOVE = Action()
169 BLOCK_ROTATE_CCW = Action(
170 label='Rotate Counterclockwise',
171 tooltip='Rotate the selected blocks 90 degrees to the left',
172 stock_id=gtk.STOCK_GO_BACK,
173 keypresses=(gtk.keysyms.Left, NO_MODS_MASK),
175 BLOCK_ROTATE_CW = Action(
176 label='Rotate Clockwise',
177 tooltip='Rotate the selected blocks 90 degrees to the right',
178 stock_id=gtk.STOCK_GO_FORWARD,
179 keypresses=(gtk.keysyms.Right, NO_MODS_MASK),
181 BLOCK_PARAM_MODIFY = Action(
183 tooltip='Modify params for the selected block',
184 stock_id=gtk.STOCK_PROPERTIES,
185 keypresses=(gtk.keysyms.Return, NO_MODS_MASK),
187 BLOCK_ENABLE = Action(
189 tooltip='Enable the selected blocks',
190 stock_id=gtk.STOCK_CONNECT,
191 keypresses=(gtk.keysyms.e, NO_MODS_MASK),
193 BLOCK_DISABLE = Action(
195 tooltip='Disable the selected blocks',
196 stock_id=gtk.STOCK_DISCONNECT,
197 keypresses=(gtk.keysyms.d, NO_MODS_MASK),
202 stock_id=gtk.STOCK_CUT,
203 keypresses=(gtk.keysyms.x, gtk.gdk.CONTROL_MASK),
208 stock_id=gtk.STOCK_COPY,
209 keypresses=(gtk.keysyms.c, gtk.gdk.CONTROL_MASK),
211 BLOCK_PASTE = Action(
214 stock_id=gtk.STOCK_PASTE,
215 keypresses=(gtk.keysyms.v, gtk.gdk.CONTROL_MASK),
217 ABOUT_WINDOW_DISPLAY = Action(
219 tooltip='About this program',
220 stock_id=gtk.STOCK_ABOUT,
222 HELP_WINDOW_DISPLAY = Action(
224 tooltip='Usage Tips',
225 stock_id=gtk.STOCK_HELP,
226 keypresses=(gtk.keysyms.F1, NO_MODS_MASK),
228 TYPES_WINDOW_DISPLAY = Action(
230 tooltip='Types Color Mapping',
231 stock_id=gtk.STOCK_DIALOG_INFO,
233 FLOW_GRAPH_GEN = Action(
235 tooltip='Generate the flow graph',
236 stock_id=gtk.STOCK_CONVERT,
237 keypresses=(gtk.keysyms.F5, NO_MODS_MASK),
239 FLOW_GRAPH_EXEC = Action(
241 tooltip='Execute the flow graph',
242 stock_id=gtk.STOCK_EXECUTE,
243 keypresses=(gtk.keysyms.F6, NO_MODS_MASK),
245 FLOW_GRAPH_KILL = Action(
247 tooltip='Kill the flow graph',
248 stock_id=gtk.STOCK_STOP,
249 keypresses=(gtk.keysyms.F7, NO_MODS_MASK),
251 FLOW_GRAPH_SCREEN_CAPTURE = Action(
252 label='S_creen Capture',
253 tooltip='Create a screen capture of the flow graph',
254 stock_id=gtk.STOCK_PRINT,
255 keypresses=(gtk.keysyms.Print, NO_MODS_MASK),
257 PORT_CONTROLLER_DEC = Action(
258 keypresses=(gtk.keysyms.minus, NO_MODS_MASK, gtk.keysyms.KP_Subtract, NO_MODS_MASK),
260 PORT_CONTROLLER_INC = Action(
261 keypresses=(gtk.keysyms.plus, NO_MODS_MASK, gtk.keysyms.KP_Add, NO_MODS_MASK),
263 BLOCK_INC_TYPE = Action(
264 keypresses=(gtk.keysyms.Down, NO_MODS_MASK),
266 BLOCK_DEC_TYPE = Action(
267 keypresses=(gtk.keysyms.Up, NO_MODS_MASK),