Merged changeset r9285:9377 from jblum/grc into trunk, with distcheck fixes
[debian/gnuradio] / grc / src / grc / 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 ##@package Actions
20 #Global actions for gui elements to communicate state changes to the action handler.
21 #Use gtk.stock_list_ids() to get a list of possible stock ids (for toolbar/menu icons)
22 #@author Josh Blum
23
24 import pygtk
25 pygtk.require('2.0')
26 import gtk
27
28 ######################################################################################################
29 # States
30 ######################################################################################################
31 APPLICATION_INITIALIZE = 'app init'
32 APPLICATION_QUIT = 'app quit'
33 PARAM_MODIFY = 'param modify'
34 BLOCK_MOVE = 'block move'
35 BLOCK_ROTATE_LEFT = 'block rotate left'
36 BLOCK_ROTATE_RIGHT = 'block rotate right'
37 BLOCK_PARAM_MODIFY = 'block param modify'
38 BLOCK_INC_TYPE = 'block increment type'
39 BLOCK_DEC_TYPE = 'block decrement type'
40 BLOCK_ENABLE = 'block enable'
41 BLOCK_DISABLE = 'block disable'
42 BLOCK_CUT = 'block cut'
43 BLOCK_COPY = 'block copy'
44 BLOCK_PASTE = 'block paste'
45 PORT_CONTROLLER_INC = 'port controller increment'
46 PORT_CONTROLLER_DEC = 'port controller decrement'
47 ELEMENT_CREATE = 'element create'
48 ELEMENT_DELETE = 'element delete'
49 ELEMENT_SELECT = 'element select'
50 NOTHING_SELECT = 'nothing select'
51 FLOW_GRAPH_OPEN = 'flow graph open'
52 FLOW_GRAPH_UNDO = 'flow graph undo'
53 FLOW_GRAPH_REDO = 'flow graph redo'
54 FLOW_GRAPH_SAVE = 'flow graph save'
55 FLOW_GRAPH_SAVE_AS = 'flow graph save as'
56 FLOW_GRAPH_CLOSE = 'flow graph close'
57 FLOW_GRAPH_NEW = 'flow graph new'
58 FLOW_GRAPH_GEN = 'flow graph gen'
59 FLOW_GRAPH_EXEC = 'flow graph exec'
60 FLOW_GRAPH_KILL = 'flow graph kill'
61 FLOW_GRAPH_SCREEN_CAPTURE = 'flow graph screen capture'
62 ABOUT_WINDOW_DISPLAY = 'about window display'
63 HOTKEYS_WINDOW_DISPLAY = 'hotkeys window display'
64 PREFS_WINDOW_DISPLAY = 'prefs window display'
65
66 ######################################################################################################
67 # Actions
68 ######################################################################################################
69 ACTIONS_LIST = (
70         gtk.Action(FLOW_GRAPH_NEW, '_New', 'Create a new flow graph', 'gtk-new'),
71         gtk.Action(FLOW_GRAPH_OPEN, '_Open', 'Open an existing flow graph', 'gtk-open'),
72         gtk.Action(FLOW_GRAPH_SAVE, '_Save', 'Save the current flow graph', 'gtk-save'),
73         gtk.Action(FLOW_GRAPH_SAVE_AS, 'Save _As', 'Save the current flow graph as...', 'gtk-save-as'),
74         gtk.Action(FLOW_GRAPH_CLOSE, '_Close', 'Close the current flow graph', 'gtk-close'),
75         gtk.Action(APPLICATION_QUIT, '_Quit', 'Quit program', 'gtk-quit'),
76         gtk.Action(FLOW_GRAPH_UNDO, '_Undo', 'Undo a change to the flow graph', 'gtk-undo'),
77         gtk.Action(FLOW_GRAPH_REDO, '_Redo', 'Redo a change to the flow graph', 'gtk-redo'),
78         gtk.Action(ELEMENT_DELETE, '_Delete', 'Delete the selected blocks', 'gtk-delete'),
79         gtk.Action(BLOCK_ROTATE_LEFT, 'Rotate _Left', 'Rotate the selected blocks 90 degrees', 'gtk-go-back'),
80         gtk.Action(BLOCK_ROTATE_RIGHT, 'Rotate _Right', 'Rotate the selected blocks -90 degrees', 'gtk-go-forward'),
81         gtk.Action(BLOCK_PARAM_MODIFY, '_Properties', 'Modify params for the selected block', 'gtk-properties'),
82         gtk.Action(BLOCK_ENABLE, 'E_nable', 'Enable the selected blocks', 'gtk-connect'),
83         gtk.Action(BLOCK_DISABLE, 'D_isable', 'Disable the selected blocks', 'gtk-disconnect'),
84         gtk.Action(BLOCK_CUT, 'Cu_t', 'Cut', 'gtk-cut'),
85         gtk.Action(BLOCK_COPY, '_Copy', 'Copy', 'gtk-copy'),
86         gtk.Action(BLOCK_PASTE, '_Paste', 'Paste', 'gtk-paste'),
87         gtk.Action(PREFS_WINDOW_DISPLAY, '_Preferences', 'Configure Preferences', 'gtk-preferences'),
88         gtk.Action(ABOUT_WINDOW_DISPLAY, '_About', 'About this program', 'gtk-about'),
89         gtk.Action(HOTKEYS_WINDOW_DISPLAY, '_HotKeys', 'Hot Keys', 'gtk-info'),
90         gtk.Action(FLOW_GRAPH_GEN, '_Generate', 'Generate the flow graph', 'gtk-convert'),
91         gtk.Action(FLOW_GRAPH_EXEC, '_Execute', 'Execute the flow graph', 'gtk-execute'),
92         gtk.Action(FLOW_GRAPH_KILL, '_Kill', 'Kill the flow graph', 'gtk-stop'),
93         gtk.Action(FLOW_GRAPH_SCREEN_CAPTURE, 'S_creen Capture', 'Create a screen capture of the flow graph', 'gtk-print'),
94 )
95
96 ACTIONS_DICT = dict((action.get_name(), action) for action in ACTIONS_LIST)
97
98 def get_action_from_name(action_name):
99         """!
100         Retrieve the action from the action list.
101         Search the list and find an action with said name.
102         @param action_name the action name(string)
103         @throw KeyError bad action name
104         @return a gtk action object
105         """
106         if ACTIONS_DICT.has_key(action_name): return ACTIONS_DICT[action_name]
107         raise KeyError('Action Name: "%s" does not exist'%action_name)
108