Merge commit 'v3.3.0' into upstream
[debian/gnuradio] / grc / gui / Bars.py
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 Actions
21 import pygtk
22 pygtk.require('2.0')
23 import gtk
24
25 ##The list of actions for the toolbar.
26 TOOLBAR_LIST = (
27         Actions.FLOW_GRAPH_NEW,
28         Actions.FLOW_GRAPH_OPEN,
29         Actions.FLOW_GRAPH_SAVE,
30         Actions.FLOW_GRAPH_CLOSE,
31         None,
32         Actions.FLOW_GRAPH_SCREEN_CAPTURE,
33         None,
34         Actions.BLOCK_CUT,
35         Actions.BLOCK_COPY,
36         Actions.BLOCK_PASTE,
37         Actions.ELEMENT_DELETE,
38         None,
39         Actions.FLOW_GRAPH_UNDO,
40         Actions.FLOW_GRAPH_REDO,
41         None,
42         Actions.ERRORS_WINDOW_DISPLAY,
43         Actions.FLOW_GRAPH_GEN,
44         Actions.FLOW_GRAPH_EXEC,
45         Actions.FLOW_GRAPH_KILL,
46         None,
47         Actions.BLOCK_ROTATE_CCW,
48         Actions.BLOCK_ROTATE_CW,
49         None,
50         Actions.BLOCK_ENABLE,
51         Actions.BLOCK_DISABLE,
52 )
53
54 ##The list of actions and categories for the menu bar.
55 MENU_BAR_LIST = (
56         (gtk.Action('File', '_File', None, None), [
57                 Actions.FLOW_GRAPH_NEW,
58                 Actions.FLOW_GRAPH_OPEN,
59                 None,
60                 Actions.FLOW_GRAPH_SAVE,
61                 Actions.FLOW_GRAPH_SAVE_AS,
62                 None,
63                 Actions.FLOW_GRAPH_SCREEN_CAPTURE,
64                 None,
65                 Actions.FLOW_GRAPH_CLOSE,
66                 Actions.APPLICATION_QUIT,
67         ]),
68         (gtk.Action('Edit', '_Edit', None, None), [
69                 Actions.FLOW_GRAPH_UNDO,
70                 Actions.FLOW_GRAPH_REDO,
71                 None,
72                 Actions.BLOCK_CUT,
73                 Actions.BLOCK_COPY,
74                 Actions.BLOCK_PASTE,
75                 Actions.ELEMENT_DELETE,
76                 None,
77                 Actions.BLOCK_ROTATE_CCW,
78                 Actions.BLOCK_ROTATE_CW,
79                 None,
80                 Actions.BLOCK_ENABLE,
81                 Actions.BLOCK_DISABLE,
82                 None,
83                 Actions.BLOCK_PARAM_MODIFY,
84         ]),
85         (gtk.Action('View', '_View', None, None), [
86                 Actions.ERRORS_WINDOW_DISPLAY,
87         ]),
88         (gtk.Action('Build', '_Build', None, None), [
89                 Actions.FLOW_GRAPH_GEN,
90                 Actions.FLOW_GRAPH_EXEC,
91                 Actions.FLOW_GRAPH_KILL,
92         ]),
93         (gtk.Action('Help', '_Help', None, None), [
94                 Actions.HELP_WINDOW_DISPLAY,
95                 Actions.TYPES_WINDOW_DISPLAY,
96                 None,
97                 Actions.ABOUT_WINDOW_DISPLAY,
98         ]),
99 )
100
101 class Toolbar(gtk.Toolbar):
102         """The gtk toolbar with actions added from the toolbar list."""
103
104         def __init__(self):
105                 """
106                 Parse the list of action names in the toolbar list.
107                 Look up the action for each name in the action list and add it to the toolbar.
108                 """
109                 gtk.Toolbar.__init__(self)
110                 self.set_style(gtk.TOOLBAR_ICONS)
111                 for action in TOOLBAR_LIST:
112                         if action: #add a tool item
113                                 self.add(action.create_tool_item())
114                                 #this reset of the tooltip property is required (after creating the tool item) for the tooltip to show
115                                 action.set_property('tooltip', action.get_property('tooltip'))
116                         else: self.add(gtk.SeparatorToolItem())
117
118 class MenuBar(gtk.MenuBar):
119         """The gtk menu bar with actions added from the menu bar list."""
120
121         def __init__(self):
122                 """
123                 Parse the list of submenus from the menubar list.
124                 For each submenu, get a list of action names.
125                 Look up the action for each name in the action list and add it to the submenu.
126                 Add the submenu to the menu bar.
127                 """
128                 gtk.MenuBar.__init__(self)
129                 for main_action, actions in MENU_BAR_LIST:
130                         #create the main menu item
131                         main_menu_item = main_action.create_menu_item()
132                         self.append(main_menu_item)
133                         #create the menu
134                         main_menu = gtk.Menu()
135                         main_menu_item.set_submenu(main_menu)
136                         for action in actions:
137                                 if action: #append a menu item
138                                         main_menu.append(action.create_menu_item())
139                                 else: main_menu.append(gtk.SeparatorMenuItem())
140                         main_menu.show_all() #this show all is required for the separators to show