~ubuntu-branches/ubuntu/saucy/pida/saucy

« back to all changes in this revision

Viewing changes to pida/services/menubar.py

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-08-01 13:08:56 UTC
  • mfrom: (0.1.2 etch) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060801130856-v92ktopgdxc8rv7q
Tags: 0.3.1-2ubuntu1
* Re-sync with Debian
* Remove bashisms from debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*- 
 
2
 
 
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
 
4
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
 
5
 
 
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:
 
12
 
 
13
#The above copyright notice and this permission notice shall be included in
 
14
#all copies or substantial portions of the Software.
 
15
 
 
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
 
22
#SOFTWARE.
 
23
 
 
24
import pida.core.service as service
 
25
import gtk
 
26
import pida.pidagtk.icons as icons
 
27
import os
 
28
 
 
29
MENU_MU = """<span>%s</span>"""
 
30
 
 
31
class Menubar(service.service):
 
32
 
 
33
    NAME = "menubar"
 
34
    
 
35
    def init(self):
 
36
        #self.__menu = gtk.MenuBar()
 
37
        #m = self.get_service('window').uimanager.get_widget('FileMenu')
 
38
        self.__menu = None#m
 
39
        self.__toplevels = {}
 
40
    
 
41
    def bind(self):
 
42
        pass 
 
43
 
 
44
    def __create_item(self, text, icon, commandargs=None):
 
45
        item = gtk.MenuItem()
 
46
        box = gtk.HBox(spacing=4)
 
47
        if icon is not None:
 
48
            icon = icons.icons.get_image(icon)
 
49
            box.pack_start(icon, expand=False)
 
50
        if text != '':
 
51
            label = gtk.Label()
 
52
            label.set_markup(MENU_MU % text)
 
53
            box.pack_start(label, expand=False)
 
54
        item.add(box)
 
55
        if commandargs is not None:
 
56
            try:
 
57
                targetservice, command, argdict = commandargs
 
58
                def activated(menuitem):
 
59
                    self.boss.call_command(targetservice, command, **argdict)
 
60
                item.connect('activate', activated)
 
61
            except:
 
62
                raise TypeError, "commandargs is (service, command, argdict)"
 
63
        return item
 
64
 
 
65
    def __add_item(self, group, item):
 
66
        self.__toplevels[group].append(item)
 
67
 
 
68
    def __add(self, group, *args, **kw):
 
69
        item = self.__create_item(*args, **kw)
 
70
        self.__add_item(group, item)
 
71
        
 
72
    def __add_separator(self, group):
 
73
        item = gtk.SeparatorMenuItem()
 
74
        self.__toplevels[group].append(item)
 
75
 
 
76
    def reset(self):
 
77
        return
 
78
        self.__generate_base_menu()
 
79
 
 
80
    def __generate_base_menu(self):
 
81
        # Is this really worse than a hunk of XML?
 
82
        toplevels = ['pida',
 
83
                     'actions',
 
84
                     'help',
 
85
                     ]
 
86
 
 
87
        for toplevel in toplevels:
 
88
            menuitem = self.__create_item(toplevel, None, None)
 
89
            self.__menu.append(menuitem)
 
90
            menu = gtk.Menu()
 
91
            menuitem.set_submenu(menu)
 
92
            self.__toplevels[toplevel] = menu
 
93
        
 
94
        items = [
 
95
                 ('pida', 'Options', 'configure',
 
96
                    ('configmanager', 'show-editor', {})),
 
97
                 ('pida', 'Scripts', 'scripts',
 
98
                    ('scripts', 'show-editor', {})),
 
99
                 ('pida', 'Contexts', 'contexts',
 
100
                    ('contexts', 'show-editor', {})),
 
101
                 ('pida', None),
 
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'})),
 
110
                 ('actions', None),
 
111
                 ('actions', '~', 'filemanager',
 
112
                    ('filemanager', 'browse',
 
113
                        {'directory': os.path.expanduser('~')})),
 
114
                 ('actions', 'Web Browser', 'internet',
 
115
                    ('webbrowser', 'browse',
 
116
                        {}))]
 
117
 
 
118
        for itemargs in items:
 
119
            if itemargs[1] == None:
 
120
                self.__add_separator(itemargs[0])
 
121
            else:
 
122
                self.__add(*itemargs)
 
123
        
 
124
        self.__menu.show_all()
 
125
        
 
126
 
 
127
    def get_menu(self):
 
128
        return self.__menu
 
129
    view = property(get_menu)
 
130
 
 
131
 
 
132
    def get_menu_definition(self):
 
133
        return  """
 
134
                <menubar>
 
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" />
 
140
                </menu>
 
141
                <menu name="base_edit" action="base_edit_menu">
 
142
                </menu>
 
143
                <menu name="base_project" action="base_project_menu">
 
144
                </menu>
 
145
                <menu name="base_tools" action="base_tools_menu">
 
146
                </menu>
 
147
                <menu name="base_help" action="base_help_menu">
 
148
                </menu>
 
149
                </menubar>
 
150
                """
 
151
 
 
152
 
 
153
Service = Menubar