another distcheck fix
[debian/gnuradio] / grc / src / grc / 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 ##@package grc.gui.Bars
20 #Create the GUI's toolbar and menubar
21
22 from grc.Actions import *
23 import pygtk
24 pygtk.require('2.0')
25 import gtk
26
27 ##The list of actions for the toolbar.
28 TOOLBAR_LIST = (
29         FLOW_GRAPH_NEW,
30         FLOW_GRAPH_OPEN,
31         FLOW_GRAPH_SAVE,
32         FLOW_GRAPH_CLOSE,
33         None,
34         FLOW_GRAPH_SCREEN_CAPTURE,
35         None,
36         BLOCK_CUT,
37         BLOCK_COPY,
38         BLOCK_PASTE,
39         ELEMENT_DELETE,
40         None,
41         FLOW_GRAPH_UNDO,
42         FLOW_GRAPH_REDO,
43         None,
44         FLOW_GRAPH_GEN,
45         FLOW_GRAPH_EXEC,
46         FLOW_GRAPH_KILL,
47         None,
48         BLOCK_ROTATE_LEFT,
49         BLOCK_ROTATE_RIGHT,
50         None,
51         BLOCK_ENABLE,
52         BLOCK_DISABLE,
53 )
54
55 ##The list of actions and categories for the menu bar.
56 MENU_BAR_LIST = (
57         (gtk.Action('File', '_File', None, None), [
58                 FLOW_GRAPH_NEW,
59                 FLOW_GRAPH_OPEN,
60                 None,
61                 FLOW_GRAPH_SAVE,
62                 FLOW_GRAPH_SAVE_AS,
63                 None,
64                 FLOW_GRAPH_SCREEN_CAPTURE,
65                 None,
66                 FLOW_GRAPH_CLOSE,
67                 APPLICATION_QUIT,
68         ]),
69         (gtk.Action('Edit', '_Edit', None, None), [
70                 FLOW_GRAPH_UNDO,
71                 FLOW_GRAPH_REDO,
72                 None,
73                 BLOCK_CUT,
74                 BLOCK_COPY,
75                 BLOCK_PASTE,
76                 ELEMENT_DELETE,
77                 None,
78                 BLOCK_ROTATE_LEFT,
79                 BLOCK_ROTATE_RIGHT,
80                 None,
81                 BLOCK_ENABLE,
82                 BLOCK_DISABLE,
83                 None,
84                 BLOCK_PARAM_MODIFY,
85         ]),
86         (gtk.Action('Build', '_Build', None, None), [
87                 FLOW_GRAPH_GEN,
88                 FLOW_GRAPH_EXEC,
89                 FLOW_GRAPH_KILL,
90         ]),
91         (gtk.Action('Options', '_Options', None, None), [
92                 PREFS_WINDOW_DISPLAY,
93         ]),
94         (gtk.Action('Help', '_Help', None, None), [
95                 ABOUT_WINDOW_DISPLAY,
96                 HOTKEYS_WINDOW_DISPLAY,
97         ]),
98 )
99
100 class Toolbar(gtk.Toolbar):
101         """The gtk toolbar with actions added from the toolbar list."""
102
103         def __init__(self):
104                 """
105                 Parse the list of action names in the toolbar list.
106                 Look up the action for each name in the action list and add it to the toolbar.
107                 """
108                 gtk.Toolbar.__init__(self)
109                 self.set_style(gtk.TOOLBAR_ICONS)
110                 for action_name in TOOLBAR_LIST:
111                         if action_name: #add a tool item
112                                 action = get_action_from_name(action_name)
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,action_names 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_name in action_names:
137                                 if action_name: #append a menu item
138                                         action = get_action_from_name(action_name)
139                                         main_menu.append(action.create_menu_item())
140                                 else: main_menu.append(gtk.SeparatorMenuItem())
141                         main_menu.show_all() #this show all is required for the separators to show
142