Merged r9481:9518 on jblum/grc_reorganize into trunk. Reorganized grc source under...
[debian/gnuradio] / grc / src / gui / Actions.py
1 """
2 Copyright 2007 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 # States
26 ######################################################################################################
27 APPLICATION_INITIALIZE = 'app init'
28 APPLICATION_QUIT = 'app quit'
29 PARAM_MODIFY = 'param modify'
30 BLOCK_MOVE = 'block move'
31 BLOCK_ROTATE_LEFT = 'block rotate left'
32 BLOCK_ROTATE_RIGHT = 'block rotate right'
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 HOTKEYS_WINDOW_DISPLAY = 'hotkeys window display'
60 PREFS_WINDOW_DISPLAY = 'prefs window display'
61
62 ######################################################################################################
63 # Actions
64 ######################################################################################################
65 ACTIONS_LIST = (
66         gtk.Action(FLOW_GRAPH_NEW, '_New', 'Create a new flow graph', 'gtk-new'),
67         gtk.Action(FLOW_GRAPH_OPEN, '_Open', 'Open an existing flow graph', 'gtk-open'),
68         gtk.Action(FLOW_GRAPH_SAVE, '_Save', 'Save the current flow graph', 'gtk-save'),
69         gtk.Action(FLOW_GRAPH_SAVE_AS, 'Save _As', 'Save the current flow graph as...', 'gtk-save-as'),
70         gtk.Action(FLOW_GRAPH_CLOSE, '_Close', 'Close the current flow graph', 'gtk-close'),
71         gtk.Action(APPLICATION_QUIT, '_Quit', 'Quit program', 'gtk-quit'),
72         gtk.Action(FLOW_GRAPH_UNDO, '_Undo', 'Undo a change to the flow graph', 'gtk-undo'),
73         gtk.Action(FLOW_GRAPH_REDO, '_Redo', 'Redo a change to the flow graph', 'gtk-redo'),
74         gtk.Action(ELEMENT_DELETE, '_Delete', 'Delete the selected blocks', 'gtk-delete'),
75         gtk.Action(BLOCK_ROTATE_LEFT, 'Rotate _Left', 'Rotate the selected blocks 90 degrees', 'gtk-go-back'),
76         gtk.Action(BLOCK_ROTATE_RIGHT, 'Rotate _Right', 'Rotate the selected blocks -90 degrees', 'gtk-go-forward'),
77         gtk.Action(BLOCK_PARAM_MODIFY, '_Properties', 'Modify params for the selected block', 'gtk-properties'),
78         gtk.Action(BLOCK_ENABLE, 'E_nable', 'Enable the selected blocks', 'gtk-connect'),
79         gtk.Action(BLOCK_DISABLE, 'D_isable', 'Disable the selected blocks', 'gtk-disconnect'),
80         gtk.Action(BLOCK_CUT, 'Cu_t', 'Cut', 'gtk-cut'),
81         gtk.Action(BLOCK_COPY, '_Copy', 'Copy', 'gtk-copy'),
82         gtk.Action(BLOCK_PASTE, '_Paste', 'Paste', 'gtk-paste'),
83         gtk.Action(PREFS_WINDOW_DISPLAY, '_Preferences', 'Configure Preferences', 'gtk-preferences'),
84         gtk.Action(ABOUT_WINDOW_DISPLAY, '_About', 'About this program', 'gtk-about'),
85         gtk.Action(HOTKEYS_WINDOW_DISPLAY, '_HotKeys', 'Hot Keys', 'gtk-info'),
86         gtk.Action(FLOW_GRAPH_GEN, '_Generate', 'Generate the flow graph', 'gtk-convert'),
87         gtk.Action(FLOW_GRAPH_EXEC, '_Execute', 'Execute the flow graph', 'gtk-execute'),
88         gtk.Action(FLOW_GRAPH_KILL, '_Kill', 'Kill the flow graph', 'gtk-stop'),
89         gtk.Action(FLOW_GRAPH_SCREEN_CAPTURE, 'S_creen Capture', 'Create a screen capture of the flow graph', 'gtk-print'),
90 )
91
92 ACTIONS_DICT = dict((action.get_name(), action) for action in ACTIONS_LIST)
93
94 def get_action_from_name(action_name):
95         """
96         Retrieve the action from the action list.
97         Search the list and find an action with said name.
98         @param action_name the action name(string)
99         @throw KeyError bad action name
100         @return a gtk action object
101         """
102         if ACTIONS_DICT.has_key(action_name): return ACTIONS_DICT[action_name]
103         raise KeyError('Action Name: "%s" does not exist'%action_name)