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 handle_key_press(event):
34 Call 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 @return true if handled
39 _used_mods_mask = reduce(lambda x, y: x | y, [mod_mask for keyval, mod_mask in _actions_keypress_dict], NO_MODS_MASK)
40 #extract the key value and the consumed modifiers
41 keyval, egroup, level, consumed = _keymap.translate_keyboard_state(
42 event.hardware_keycode, event.state, event.group)
43 #get the modifier mask and ignore irrelevant modifiers
44 mod_mask = event.state & ~consumed & _used_mods_mask
45 #look up the keypress and call the action
46 try: _actions_keypress_dict[(keyval, mod_mask)]()
47 except KeyError: return False #not handled
48 return True #handled here
50 _all_actions_list = list()
51 def get_all_actions(): return _all_actions_list
53 _accel_group = gtk.AccelGroup()
54 def get_accel_group(): return _accel_group
56 class Action(gtk.Action):
58 A custom Action class based on gtk.Action.
59 Pass additional arguments such as keypresses.
60 Register actions and keypresses with this module.
63 def __init__(self, keypresses=(), name=None, label=None, tooltip=None, stock_id=None):
65 Create a new Action instance.
66 @param key_presses a tuple of (keyval1, mod_mask1, keyval2, mod_mask2, ...)
67 @param the regular gtk.Action parameters (defaults to None)
69 if name is None: name = label
70 gtk.Action.__init__(self,
71 name=name, label=label,
72 tooltip=tooltip, stock_id=stock_id,
75 _all_actions_list.append(self)
76 for i in range(len(keypresses)/2):
77 keyval, mod_mask = keypresses[i*2:(i+1)*2]
78 #register this keypress
79 assert not _actions_keypress_dict.has_key((keyval, mod_mask))
80 _actions_keypress_dict[(keyval, mod_mask)] = self
81 #set the accelerator group, and accelerator path
82 #register the key name and mod mask with the accelerator path
83 if label is None: continue #dont register accel
84 accel_path = '<main>/'+self.get_name()
85 self.set_accel_group(get_accel_group())
86 self.set_accel_path(accel_path)
87 gtk.accel_map_add_entry(accel_path, keyval, mod_mask)
91 The string representation should be the name of the action id.
92 Try to find the action id for this action by searching this module.
96 return filter(lambda attr: getattr(Actions, attr) == self, dir(Actions))[0]
97 except: return self.get_name()
99 def __repr__(self): return str(self)
103 Emit the activate signal when called with ().
105 self.emit('activate')
107 ########################################################################
109 ########################################################################
110 PAGE_CHANGE = Action()
111 FLOW_GRAPH_NEW = Action(
113 tooltip='Create a new flow graph',
114 stock_id=gtk.STOCK_NEW,
115 keypresses=(gtk.keysyms.n, gtk.gdk.CONTROL_MASK),
117 FLOW_GRAPH_OPEN = Action(
119 tooltip='Open an existing flow graph',
120 stock_id=gtk.STOCK_OPEN,
121 keypresses=(gtk.keysyms.o, gtk.gdk.CONTROL_MASK),
123 FLOW_GRAPH_SAVE = Action(
125 tooltip='Save the current flow graph',
126 stock_id=gtk.STOCK_SAVE,
127 keypresses=(gtk.keysyms.s, gtk.gdk.CONTROL_MASK),
129 FLOW_GRAPH_SAVE_AS = Action(
131 tooltip='Save the current flow graph as...',
132 stock_id=gtk.STOCK_SAVE_AS,
133 keypresses=(gtk.keysyms.s, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
135 FLOW_GRAPH_CLOSE = Action(
137 tooltip='Close the current flow graph',
138 stock_id=gtk.STOCK_CLOSE,
139 keypresses=(gtk.keysyms.w, gtk.gdk.CONTROL_MASK),
141 APPLICATION_INITIALIZE = Action()
142 APPLICATION_QUIT = Action(
144 tooltip='Quit program',
145 stock_id=gtk.STOCK_QUIT,
146 keypresses=(gtk.keysyms.q, gtk.gdk.CONTROL_MASK),
148 FLOW_GRAPH_UNDO = Action(
150 tooltip='Undo a change to the flow graph',
151 stock_id=gtk.STOCK_UNDO,
152 keypresses=(gtk.keysyms.z, gtk.gdk.CONTROL_MASK),
154 FLOW_GRAPH_REDO = Action(
156 tooltip='Redo a change to the flow graph',
157 stock_id=gtk.STOCK_REDO,
158 keypresses=(gtk.keysyms.y, gtk.gdk.CONTROL_MASK),
160 NOTHING_SELECT = Action()
161 ELEMENT_SELECT = Action()
162 ELEMENT_CREATE = Action()
163 ELEMENT_DELETE = Action(
165 tooltip='Delete the selected blocks',
166 stock_id=gtk.STOCK_DELETE,
167 keypresses=(gtk.keysyms.Delete, NO_MODS_MASK),
169 BLOCK_MOVE = Action()
170 BLOCK_ROTATE_CCW = Action(
171 label='Rotate Counterclockwise',
172 tooltip='Rotate the selected blocks 90 degrees to the left',
173 stock_id=gtk.STOCK_GO_BACK,
174 keypresses=(gtk.keysyms.Left, NO_MODS_MASK),
176 BLOCK_ROTATE_CW = Action(
177 label='Rotate Clockwise',
178 tooltip='Rotate the selected blocks 90 degrees to the right',
179 stock_id=gtk.STOCK_GO_FORWARD,
180 keypresses=(gtk.keysyms.Right, NO_MODS_MASK),
182 BLOCK_PARAM_MODIFY = Action(
184 tooltip='Modify params for the selected block',
185 stock_id=gtk.STOCK_PROPERTIES,
186 keypresses=(gtk.keysyms.Return, NO_MODS_MASK),
188 BLOCK_ENABLE = Action(
190 tooltip='Enable the selected blocks',
191 stock_id=gtk.STOCK_CONNECT,
192 keypresses=(gtk.keysyms.e, NO_MODS_MASK),
194 BLOCK_DISABLE = Action(
196 tooltip='Disable the selected blocks',
197 stock_id=gtk.STOCK_DISCONNECT,
198 keypresses=(gtk.keysyms.d, NO_MODS_MASK),
203 stock_id=gtk.STOCK_CUT,
204 keypresses=(gtk.keysyms.x, gtk.gdk.CONTROL_MASK),
209 stock_id=gtk.STOCK_COPY,
210 keypresses=(gtk.keysyms.c, gtk.gdk.CONTROL_MASK),
212 BLOCK_PASTE = Action(
215 stock_id=gtk.STOCK_PASTE,
216 keypresses=(gtk.keysyms.v, gtk.gdk.CONTROL_MASK),
218 ERRORS_WINDOW_DISPLAY = Action(
220 tooltip='View flow graph errors',
221 stock_id=gtk.STOCK_DIALOG_ERROR,
223 ABOUT_WINDOW_DISPLAY = Action(
225 tooltip='About this program',
226 stock_id=gtk.STOCK_ABOUT,
228 HELP_WINDOW_DISPLAY = Action(
230 tooltip='Usage tips',
231 stock_id=gtk.STOCK_HELP,
232 keypresses=(gtk.keysyms.F1, NO_MODS_MASK),
234 TYPES_WINDOW_DISPLAY = Action(
236 tooltip='Types color mapping',
237 stock_id=gtk.STOCK_DIALOG_INFO,
239 FLOW_GRAPH_GEN = Action(
241 tooltip='Generate the flow graph',
242 stock_id=gtk.STOCK_CONVERT,
243 keypresses=(gtk.keysyms.F5, NO_MODS_MASK),
245 FLOW_GRAPH_EXEC = Action(
247 tooltip='Execute the flow graph',
248 stock_id=gtk.STOCK_EXECUTE,
249 keypresses=(gtk.keysyms.F6, NO_MODS_MASK),
251 FLOW_GRAPH_KILL = Action(
253 tooltip='Kill the flow graph',
254 stock_id=gtk.STOCK_STOP,
255 keypresses=(gtk.keysyms.F7, NO_MODS_MASK),
257 FLOW_GRAPH_SCREEN_CAPTURE = Action(
258 label='S_creen Capture',
259 tooltip='Create a screen capture of the flow graph',
260 stock_id=gtk.STOCK_PRINT,
261 keypresses=(gtk.keysyms.Print, NO_MODS_MASK),
263 PORT_CONTROLLER_DEC = Action(
264 keypresses=(gtk.keysyms.minus, NO_MODS_MASK, gtk.keysyms.KP_Subtract, NO_MODS_MASK),
266 PORT_CONTROLLER_INC = Action(
267 keypresses=(gtk.keysyms.plus, NO_MODS_MASK, gtk.keysyms.KP_Add, NO_MODS_MASK),
269 BLOCK_INC_TYPE = Action(
270 keypresses=(gtk.keysyms.Down, NO_MODS_MASK),
272 BLOCK_DEC_TYPE = Action(
273 keypresses=(gtk.keysyms.Up, NO_MODS_MASK),