Statistics
| Branch: | Tag: | Revision:

root / grc / gui / Actions.py @ 854bed10

History | View | Annotate | Download (7.8 kB)

1
"""
2
Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
3
This file is part of GNU Radio
4
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.
9
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.
14
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
18
"""
19
20
import pygtk
21
pygtk.require('2.0')
22
import gtk
23
24
######################################################################################################
25
# Action Names
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'
60
TYPES_WINDOW_DISPLAY = 'types window display'
61
62
######################################################################################################
63
# Action Key Map
64
######################################################################################################
65
_actions_key_list = (
66
        #action name, key name, mod mask
67
        (FLOW_GRAPH_NEW, 'n', gtk.gdk.CONTROL_MASK),
68
        (FLOW_GRAPH_OPEN, 'o', gtk.gdk.CONTROL_MASK),
69
        (FLOW_GRAPH_SAVE, 's', gtk.gdk.CONTROL_MASK),
70
        (FLOW_GRAPH_SAVE_AS, 's', gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
71
        (FLOW_GRAPH_CLOSE, 'w', gtk.gdk.CONTROL_MASK),
72
        (APPLICATION_QUIT, 'q', gtk.gdk.CONTROL_MASK),
73
        (FLOW_GRAPH_UNDO, 'z', gtk.gdk.CONTROL_MASK),
74
        (FLOW_GRAPH_REDO, 'y', gtk.gdk.CONTROL_MASK),
75
        (ELEMENT_DELETE, 'Delete', 0),
76
        (BLOCK_ROTATE_CCW, 'Left', 0),
77
        (BLOCK_ROTATE_CW, 'Right', 0),
78
        (BLOCK_DEC_TYPE, 'Up', 0),
79
        (BLOCK_INC_TYPE, 'Down', 0),
80
        (BLOCK_PARAM_MODIFY, 'Return', 0),
81
        (BLOCK_ENABLE, 'e', 0),
82
        (BLOCK_DISABLE, 'd', 0),
83
        (BLOCK_CUT, 'x', gtk.gdk.CONTROL_MASK),
84
        (BLOCK_COPY, 'c', gtk.gdk.CONTROL_MASK),
85
        (BLOCK_PASTE, 'v', gtk.gdk.CONTROL_MASK),
86
        (FLOW_GRAPH_GEN, 'F5', 0),
87
        (FLOW_GRAPH_EXEC, 'F6', 0),
88
        (FLOW_GRAPH_KILL, 'F7', 0),
89
        (FLOW_GRAPH_SCREEN_CAPTURE, 'Print', 0),
90
        (HELP_WINDOW_DISPLAY, 'F1', 0),
91
        #the following have no associated gtk.Action
92
        (PORT_CONTROLLER_INC, 'equal', 0),
93
        (PORT_CONTROLLER_INC, 'plus', 0),
94
        (PORT_CONTROLLER_INC, 'KP_Add', 0),
95
        (PORT_CONTROLLER_DEC, 'minus', 0),
96
        (PORT_CONTROLLER_DEC, 'KP_Subtract', 0),
97
)
98
99
_actions_key_dict = dict(((key_name, mod_mask), action_name) for action_name, key_name, mod_mask in _actions_key_list)
100
def get_action_name_from_key_name(key_name, mod_mask=0):
101
        """
102
        Get the action name associated with the key name and mask.
103
        Both keyname and mask have to match.
104
        @param key_name the name of the key
105
        @param mod_mask the key press mask (shift, ctrl) 0 for none
106
        @return the action name or blank string
107
        """
108
        key_name_mod_mask = (key_name, mod_mask)
109
        if key_name_mod_mask in _actions_key_dict: return _actions_key_dict[key_name_mod_mask]
110
        return ''
111
112
######################################################################################################
113
# Actions
114
######################################################################################################
115
_actions_list = (
116
        gtk.Action(FLOW_GRAPH_NEW, '_New', 'Create a new flow graph', gtk.STOCK_NEW),
117
        gtk.Action(FLOW_GRAPH_OPEN, '_Open', 'Open an existing flow graph', gtk.STOCK_OPEN),
118
        gtk.Action(FLOW_GRAPH_SAVE, '_Save', 'Save the current flow graph', gtk.STOCK_SAVE),
119
        gtk.Action(FLOW_GRAPH_SAVE_AS, 'Save _As', 'Save the current flow graph as...', gtk.STOCK_SAVE_AS),
120
        gtk.Action(FLOW_GRAPH_CLOSE, '_Close', 'Close the current flow graph', gtk.STOCK_CLOSE),
121
        gtk.Action(APPLICATION_QUIT, '_Quit', 'Quit program', gtk.STOCK_QUIT),
122
        gtk.Action(FLOW_GRAPH_UNDO, '_Undo', 'Undo a change to the flow graph', gtk.STOCK_UNDO),
123
        gtk.Action(FLOW_GRAPH_REDO, '_Redo', 'Redo a change to the flow graph', gtk.STOCK_REDO),
124
        gtk.Action(ELEMENT_DELETE, '_Delete', 'Delete the selected blocks', gtk.STOCK_DELETE),
125
        gtk.Action(BLOCK_ROTATE_CCW, 'Rotate Counterclockwise', 'Rotate the selected blocks 90 degrees to the left', gtk.STOCK_GO_BACK),
126
        gtk.Action(BLOCK_ROTATE_CW, 'Rotate Clockwise', 'Rotate the selected blocks 90 degrees to the right', gtk.STOCK_GO_FORWARD),
127
        gtk.Action(BLOCK_PARAM_MODIFY, '_Properties', 'Modify params for the selected block', gtk.STOCK_PROPERTIES),
128
        gtk.Action(BLOCK_ENABLE, 'E_nable', 'Enable the selected blocks', gtk.STOCK_CONNECT),
129
        gtk.Action(BLOCK_DISABLE, 'D_isable', 'Disable the selected blocks', gtk.STOCK_DISCONNECT),
130
        gtk.Action(BLOCK_CUT, 'Cu_t', 'Cut', gtk.STOCK_CUT),
131
        gtk.Action(BLOCK_COPY, '_Copy', 'Copy', gtk.STOCK_COPY),
132
        gtk.Action(BLOCK_PASTE, '_Paste', 'Paste', gtk.STOCK_PASTE),
133
        gtk.Action(ABOUT_WINDOW_DISPLAY, '_About', 'About this program', gtk.STOCK_ABOUT),
134
        gtk.Action(HELP_WINDOW_DISPLAY, '_Help', 'Usage Tips', gtk.STOCK_HELP),
135
        gtk.Action(TYPES_WINDOW_DISPLAY, '_Types', 'Types Color Mapping', gtk.STOCK_DIALOG_INFO),
136
        gtk.Action(FLOW_GRAPH_GEN, '_Generate', 'Generate the flow graph', gtk.STOCK_CONVERT),
137
        gtk.Action(FLOW_GRAPH_EXEC, '_Execute', 'Execute the flow graph', gtk.STOCK_EXECUTE),
138
        gtk.Action(FLOW_GRAPH_KILL, '_Kill', 'Kill the flow graph', gtk.STOCK_STOP),
139
        gtk.Action(FLOW_GRAPH_SCREEN_CAPTURE, 'S_creen Capture', 'Create a screen capture of the flow graph', gtk.STOCK_PRINT),
140
)
141
def get_all_actions(): return _actions_list
142
143
_actions_dict = dict((action.get_name(), action) for action in _actions_list)
144
def get_action_from_name(action_name):
145
        """
146
        Retrieve the action from the action list.
147
        Search the list and find an action with said name.
148
        @param action_name the action name(string)
149
        @throw KeyError bad action name
150
        @return a gtk action object
151
        """
152
        if action_name in _actions_dict: return _actions_dict[action_name]
153
        raise KeyError('Action Name: "%s" does not exist'%action_name)
154
155
######################################################################################################
156
# Accelerators
157
######################################################################################################
158
_accel_group = gtk.AccelGroup()
159
def get_accel_group(): return _accel_group
160
161
#set the accelerator group, and accelerator path
162
#register the key name and mod mask with the accelerator path
163
for action_name, key_name, mod_mask in _actions_key_list:
164
        try:
165
                accel_path = '<main>/'+action_name
166
                get_action_from_name(action_name).set_accel_group(get_accel_group())
167
                get_action_from_name(action_name).set_accel_path(accel_path)
168
                gtk.accel_map_add_entry(accel_path, gtk.gdk.keyval_from_name(key_name), mod_mask)
169
        except KeyError: pass #no action was created for this action name