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