1
# -*- coding: utf-8 -*-
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
7
#of this software and associated documentation files (the "Software"), to deal
8
#in the Software without restriction, including without limitation the rights
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
#copies of the Software, and to permit persons to whom the Software is
11
#furnished to do so, subject to the following conditions:
13
#The above copyright notice and this permission notice shall be included in
14
#all copies or substantial portions of the Software.
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
import pida.core.service as service
26
import pida.pidagtk.icons as icons
29
MENU_MU = """<span>%s</span>"""
31
class Menubar(service.service):
36
#self.__menu = gtk.MenuBar()
37
#m = self.get_service('window').uimanager.get_widget('FileMenu')
44
def __create_item(self, text, icon, commandargs=None):
46
box = gtk.HBox(spacing=4)
48
icon = icons.icons.get_image(icon)
49
box.pack_start(icon, expand=False)
52
label.set_markup(MENU_MU % text)
53
box.pack_start(label, expand=False)
55
if commandargs is not None:
57
targetservice, command, argdict = commandargs
58
def activated(menuitem):
59
self.boss.call_command(targetservice, command, **argdict)
60
item.connect('activate', activated)
62
raise TypeError, "commandargs is (service, command, argdict)"
65
def __add_item(self, group, item):
66
self.__toplevels[group].append(item)
68
def __add(self, group, *args, **kw):
69
item = self.__create_item(*args, **kw)
70
self.__add_item(group, item)
72
def __add_separator(self, group):
73
item = gtk.SeparatorMenuItem()
74
self.__toplevels[group].append(item)
78
self.__generate_base_menu()
80
def __generate_base_menu(self):
81
# Is this really worse than a hunk of XML?
87
for toplevel in toplevels:
88
menuitem = self.__create_item(toplevel, None, None)
89
self.__menu.append(menuitem)
91
menuitem.set_submenu(menu)
92
self.__toplevels[toplevel] = menu
95
('pida', 'Options', 'configure',
96
('configmanager', 'show-editor', {})),
97
('pida', 'Scripts', 'scripts',
98
('scripts', 'show-editor', {})),
99
('pida', 'Contexts', 'contexts',
100
('contexts', 'show-editor', {})),
102
('pida', 'Manhole', 'manhole',
103
('manhole', 'run', {})),
104
('actions', 'Search', 'find',
105
('grepper', 'find-interactive', {})),
106
('actions', 'Terminal', 'terminal',
107
('terminal', 'execute_shell', {})),
108
('actions', 'Python Shell', 'python',
109
('terminal', 'execute', {'command_line': 'python'})),
111
('actions', '~', 'filemanager',
112
('filemanager', 'browse',
113
{'directory': os.path.expanduser('~')})),
114
('actions', 'Web Browser', 'internet',
115
('webbrowser', 'browse',
118
for itemargs in items:
119
if itemargs[1] == None:
120
self.__add_separator(itemargs[0])
122
self.__add(*itemargs)
124
self.__menu.show_all()
129
view = property(get_menu)
132
def get_menu_definition(self):
135
<menu name="base_file" action="base_file_menu">
136
<placeholder name="OpenFileMenu" />
137
<placeholder name="SaveFileMenu" />
138
<placeholder name="ExtrasFileMenu" />
139
<placeholder name="GlobalFileMenu" />
141
<menu name="base_edit" action="base_edit_menu">
143
<menu name="base_project" action="base_project_menu">
145
<menu name="base_tools" action="base_tools_menu">
147
<menu name="base_help" action="base_help_menu">