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
24 ######################################################################################################
26 ######################################################################################################
27 APPLICATION_INITIALIZE = 'app init'
28 APPLICATION_QUIT = 'app quit'
29 PARAM_MODIFY = 'param modify'
30 BLOCK_MOVE = 'block move'
31 BLOCK_ROTATE_CCW = 'block rotate ccw'
32 BLOCK_ROTATE_CW = 'block rotate cw'
33 BLOCK_PARAM_MODIFY = 'block param modify'
34 BLOCK_INC_TYPE = 'block increment type'
35 BLOCK_DEC_TYPE = 'block decrement type'
36 BLOCK_ENABLE = 'block enable'
37 BLOCK_DISABLE = 'block disable'
38 BLOCK_CUT = 'block cut'
39 BLOCK_COPY = 'block copy'
40 BLOCK_PASTE = 'block paste'
41 PORT_CONTROLLER_INC = 'port controller increment'
42 PORT_CONTROLLER_DEC = 'port controller decrement'
43 ELEMENT_CREATE = 'element create'
44 ELEMENT_DELETE = 'element delete'
45 ELEMENT_SELECT = 'element select'
46 NOTHING_SELECT = 'nothing select'
47 FLOW_GRAPH_OPEN = 'flow graph open'
48 FLOW_GRAPH_UNDO = 'flow graph undo'
49 FLOW_GRAPH_REDO = 'flow graph redo'
50 FLOW_GRAPH_SAVE = 'flow graph save'
51 FLOW_GRAPH_SAVE_AS = 'flow graph save as'
52 FLOW_GRAPH_CLOSE = 'flow graph close'
53 FLOW_GRAPH_NEW = 'flow graph new'
54 FLOW_GRAPH_GEN = 'flow graph gen'
55 FLOW_GRAPH_EXEC = 'flow graph exec'
56 FLOW_GRAPH_KILL = 'flow graph kill'
57 FLOW_GRAPH_SCREEN_CAPTURE = 'flow graph screen capture'
58 ABOUT_WINDOW_DISPLAY = 'about window display'
59 HELP_WINDOW_DISPLAY = 'help window display'
61 ######################################################################################################
63 ######################################################################################################
65 #action name, key name, mod mask
66 (FLOW_GRAPH_NEW, 'n', gtk.gdk.CONTROL_MASK),
67 (FLOW_GRAPH_OPEN, 'o', gtk.gdk.CONTROL_MASK),
68 (FLOW_GRAPH_SAVE, 's', gtk.gdk.CONTROL_MASK),
69 (FLOW_GRAPH_SAVE_AS, 's', gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
70 (FLOW_GRAPH_CLOSE, 'w', gtk.gdk.CONTROL_MASK),
71 (APPLICATION_QUIT, 'q', gtk.gdk.CONTROL_MASK),
72 (FLOW_GRAPH_UNDO, 'z', gtk.gdk.CONTROL_MASK),
73 (FLOW_GRAPH_REDO, 'y', gtk.gdk.CONTROL_MASK),
74 (ELEMENT_DELETE, 'Delete', 0),
75 (BLOCK_ROTATE_CCW, 'Left', 0),
76 (BLOCK_ROTATE_CW, 'Right', 0),
77 (BLOCK_DEC_TYPE, 'Up', 0),
78 (BLOCK_INC_TYPE, 'Down', 0),
79 (BLOCK_PARAM_MODIFY, 'Return', 0),
80 (BLOCK_ENABLE, 'e', 0),
81 (BLOCK_DISABLE, 'd', 0),
82 (BLOCK_CUT, 'x', gtk.gdk.CONTROL_MASK),
83 (BLOCK_COPY, 'c', gtk.gdk.CONTROL_MASK),
84 (BLOCK_PASTE, 'v', gtk.gdk.CONTROL_MASK),
85 (FLOW_GRAPH_GEN, 'F5', 0),
86 (FLOW_GRAPH_EXEC, 'F6', 0),
87 (FLOW_GRAPH_KILL, 'F7', 0),
88 (FLOW_GRAPH_SCREEN_CAPTURE, 'Print', 0),
89 (HELP_WINDOW_DISPLAY, 'F1', 0),
90 #the following have no associated gtk.Action
91 (PORT_CONTROLLER_INC, 'equal', 0),
92 (PORT_CONTROLLER_INC, 'plus', 0),
93 (PORT_CONTROLLER_INC, 'KP_Add', 0),
94 (PORT_CONTROLLER_DEC, 'minus', 0),
95 (PORT_CONTROLLER_DEC, 'KP_Subtract', 0),
98 _actions_key_dict = dict(((key_name, mod_mask), action_name) for action_name, key_name, mod_mask in _actions_key_list)
99 def get_action_name_from_key_name(key_name, mod_mask=0):
101 Get the action name associated with the key name and mask.
102 Both keyname and mask have to match.
103 @param key_name the name of the key
104 @param mod_mask the key press mask (shift, ctrl) 0 for none
105 @return the action name or blank string
107 key_name_mod_mask = (key_name, mod_mask)
108 if key_name_mod_mask in _actions_key_dict: return _actions_key_dict[key_name_mod_mask]
111 ######################################################################################################
113 ######################################################################################################
115 gtk.Action(FLOW_GRAPH_NEW, '_New', 'Create a new flow graph', gtk.STOCK_NEW),
116 gtk.Action(FLOW_GRAPH_OPEN, '_Open', 'Open an existing flow graph', gtk.STOCK_OPEN),
117 gtk.Action(FLOW_GRAPH_SAVE, '_Save', 'Save the current flow graph', gtk.STOCK_SAVE),
118 gtk.Action(FLOW_GRAPH_SAVE_AS, 'Save _As', 'Save the current flow graph as...', gtk.STOCK_SAVE_AS),
119 gtk.Action(FLOW_GRAPH_CLOSE, '_Close', 'Close the current flow graph', gtk.STOCK_CLOSE),
120 gtk.Action(APPLICATION_QUIT, '_Quit', 'Quit program', gtk.STOCK_QUIT),
121 gtk.Action(FLOW_GRAPH_UNDO, '_Undo', 'Undo a change to the flow graph', gtk.STOCK_UNDO),
122 gtk.Action(FLOW_GRAPH_REDO, '_Redo', 'Redo a change to the flow graph', gtk.STOCK_REDO),
123 gtk.Action(ELEMENT_DELETE, '_Delete', 'Delete the selected blocks', gtk.STOCK_DELETE),
124 gtk.Action(BLOCK_ROTATE_CCW, 'Rotate Counterclockwise', 'Rotate the selected blocks 90 degrees to the left', gtk.STOCK_GO_BACK),
125 gtk.Action(BLOCK_ROTATE_CW, 'Rotate Clockwise', 'Rotate the selected blocks 90 degrees to the right', gtk.STOCK_GO_FORWARD),
126 gtk.Action(BLOCK_PARAM_MODIFY, '_Properties', 'Modify params for the selected block', gtk.STOCK_PROPERTIES),
127 gtk.Action(BLOCK_ENABLE, 'E_nable', 'Enable the selected blocks', gtk.STOCK_CONNECT),
128 gtk.Action(BLOCK_DISABLE, 'D_isable', 'Disable the selected blocks', gtk.STOCK_DISCONNECT),
129 gtk.Action(BLOCK_CUT, 'Cu_t', 'Cut', gtk.STOCK_CUT),
130 gtk.Action(BLOCK_COPY, '_Copy', 'Copy', gtk.STOCK_COPY),
131 gtk.Action(BLOCK_PASTE, '_Paste', 'Paste', gtk.STOCK_PASTE),
132 gtk.Action(ABOUT_WINDOW_DISPLAY, '_About', 'About this program', gtk.STOCK_ABOUT),
133 gtk.Action(HELP_WINDOW_DISPLAY, '_Help', 'Usage Tips', gtk.STOCK_HELP),
134 gtk.Action(FLOW_GRAPH_GEN, '_Generate', 'Generate the flow graph', gtk.STOCK_CONVERT),
135 gtk.Action(FLOW_GRAPH_EXEC, '_Execute', 'Execute the flow graph', gtk.STOCK_EXECUTE),
136 gtk.Action(FLOW_GRAPH_KILL, '_Kill', 'Kill the flow graph', gtk.STOCK_STOP),
137 gtk.Action(FLOW_GRAPH_SCREEN_CAPTURE, 'S_creen Capture', 'Create a screen capture of the flow graph', gtk.STOCK_PRINT),
139 def get_all_actions(): return _actions_list
141 _actions_dict = dict((action.get_name(), action) for action in _actions_list)
142 def get_action_from_name(action_name):
144 Retrieve the action from the action list.
145 Search the list and find an action with said name.
146 @param action_name the action name(string)
147 @throw KeyError bad action name
148 @return a gtk action object
150 if action_name in _actions_dict: return _actions_dict[action_name]
151 raise KeyError('Action Name: "%s" does not exist'%action_name)
153 ######################################################################################################
155 ######################################################################################################
156 _accel_group = gtk.AccelGroup()
157 def get_accel_group(): return _accel_group
159 #set the accelerator group, and accelerator path
160 #register the key name and mod mask with the accelerator path
161 for action_name, key_name, mod_mask in _actions_key_list:
163 accel_path = '<main>/'+action_name
164 get_action_from_name(action_name).set_accel_group(get_accel_group())
165 get_action_from_name(action_name).set_accel_path(accel_path)
166 gtk.accel_map_add_entry(accel_path, gtk.gdk.keyval_from_name(key_name), mod_mask)
167 except KeyError: pass #no action was created for this action name