Python gtk 模块,MenuItem() 实例源码

我们从Python开源项目中,提取了以下37个代码示例,用于说明如何使用gtk.MenuItem()

项目:ns3-rdma    作者:bobzhuyb    | 项目源码 | 文件源码
def populate_node_menu(viz, node, menu):
    ns3_node = ns.network.NodeList.GetNode(node.node_index)
    olsr = ns3_node.GetObject(ns.olsr.olsr.RoutingProtocol.GetTypeId())
    if olsr is None:
        print "No OLSR"
        return

    menu_item = gtk.MenuItem("Show OLSR Routing Table")
    menu_item.show()

    def _show_ipv4_routing_table(dummy_menu_item):
        ShowOlsrRoutingTable(viz, node.node_index)

    menu_item.connect("activate", _show_ipv4_routing_table)
    menu.add(menu_item)
项目:ns3-rdma    作者:bobzhuyb    | 项目源码 | 文件源码
def populate_node_menu(viz, node, menu):
    menu_item = gtk.MenuItem("Show Last Packets")
    menu_item.show()

    def _show_it(dummy_menu_item):
        ShowLastPackets(viz, node.node_index)

    menu_item.connect("activate", _show_it)
    menu.add(menu_item)
项目:ns3-rdma    作者:bobzhuyb    | 项目源码 | 文件源码
def populate_node_menu(viz, node, menu, statistics_collector):

    menu_item = gtk.MenuItem("Show Interface Statistics")
    menu_item.show()

    def _show_it(dummy_menu_item):
        ShowInterfaceStatistics(viz, node.node_index, statistics_collector)

    menu_item.connect("activate", _show_it)
    menu.add(menu_item)
项目:ns3-rdma    作者:bobzhuyb    | 项目源码 | 文件源码
def populate_node_menu(viz, node, menu):
    menu_item = gtk.MenuItem("Show IPv4 Routing Table")
    menu_item.show()

    def _show_ipv4_routing_table(dummy_menu_item):
        ShowIpv4RoutingTable(viz, node.node_index)

    menu_item.connect("activate", _show_ipv4_routing_table)
    menu.add(menu_item)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def make_menu(self):
        menu = gtk.Menu()
        itemlist = [(u'Config', self.on_show),
                    ('restart gae_proxy', self.on_restart_gae_proxy),
                    (u'Quit', self.on_quit)]
        for text, callback in itemlist:
            item = gtk.MenuItem(text)
            item.connect('activate', callback)
            item.show()
            menu.append(item)
        menu.show()
        return menu
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def make_menu(self):
        menu = gtk.Menu()
        itemlist = [(u'Config', self.on_show),
                    ('restart gae_proxy', self.on_restart_gae_proxy),
                    (u'Quit', self.on_quit)]
        for text, callback in itemlist:
            item = gtk.MenuItem(text)
            item.connect('activate', callback)
            item.show()
            menu.append(item)
        menu.show()
        return menu
项目:tools    作者:denglouping    | 项目源码 | 文件源码
def build_Menu(self):
       menu1 = gtk.Menu();
       menu2 = gtk.Menu();
       menuItem1_1 = gtk.MenuItem("1:1");
       menuItem1_2 = gtk.MenuItem("1:2");
       menuItem1_3 = gtk.MenuItem("1:3");
       menuItem2_1 = gtk.MenuItem("??");
       menuItem2_2 = gtk.MenuItem("??");
       menuItem2_3 = gtk.MenuItem("????");
       menuItem2_4 = gtk.MenuItem("?????");
       menuItem2_5 = gtk.MenuItem("????");
       menuItem2_6 = gtk.MenuItem("?????");
       menuItem2_7 = gtk.MenuItem("????")
       menu1.append(menuItem1_1)
       menu1.append(menuItem1_2)
       menu1.append(menuItem1_3)
       menu2.append(menuItem2_1)
       menu2.append(menuItem2_2)
       menu2.append(menuItem2_3)
       menu2.append(menuItem2_4)
       menu2.append(menuItem2_5)
       menu2.append(menuItem2_6)
       menu2.append(menuItem2_7)

       first_menu = gtk.MenuItem("First Menu")
       second_menu = gtk.MenuItem("?????")
       first_menu.set_submenu(menu1)
       second_menu.set_submenu(menu2)

       menuItem2_1.connect("button-press-event",self.select_Server,1);
       menuItem2_2.connect("button-press-event",self.select_Server,2);
       menuItem2_3.connect("button-press-event",self.select_Server,3);
       menuItem2_4.connect("button-press-event",self.add_Server);
       menuItem2_5.connect("button-press-event",self.create_Excel);
       menuItem2_7.connect("button-press-event",self.load_information);

       menu_bar = gtk.MenuBar()
       menu_bar.append (first_menu)
       menu_bar.append (second_menu)

       return menu_bar
项目:epoptes    作者:Epoptes    | 项目源码 | 文件源码
def appendToGroupsMenu(self, group):
        mitem = gtk.MenuItem(group.name)
        mitem.show()
        mitem.connect('activate', self.on_add_to_group_clicked, group)
        self.groups_menu.append(mitem)
项目:epoptes    作者:Epoptes    | 项目源码 | 文件源码
def removeFromGroupsMenu(self, group):
        mitem = gtk.MenuItem(group.name)
        mitem.show()
        mitem.connect('activate', self.on_add_to_group_clicked, group)
        self.groups_menu.append(mitem)
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def on_populate_popup(self, treeview, menu):
        '''Add popup menu options.'''
        menu.prepend(gtk.SeparatorMenuItem())

        # Add menu with view options.
        view_menu = gtk.Menu()
        # Add options to show tags and tagged pages.
        items = ( (_('Show only Pages with Tags'), self._show_tagged,
                   lambda o: self.toggle_show_tagged()),
                  (_('Show Tags'), self.uistate['show tags'],
                   lambda o: self.toggle_show_tags()) )
        for name, active, func in items:
            item = gtk.CheckMenuItem(name)
            item.set_active(active)
            item.connect('activate', func)
            view_menu.append(item)
        view_menu.append(gtk.SeparatorMenuItem())

        # Add options to switch between views.
        def _change_view(item, event):
            self.uistate['Open pages'] = item.zim_view
            self.treeview.change_view(self.uistate['Open pages'])

        items = ( (_('Default'), 'default'),
                  (_('Collapse other Pages'), 'collapse'),
                  (_('Disable'), 'disable') )
        item = None
        for name, view in items:
            item = gtk.RadioMenuItem(group = item, label = name)
            if view == self.uistate['Open pages']:
                item.set_active(True)
            item.zim_view = view
            item.connect('button-release-event', _change_view)
            view_menu.append(item)

        item = gtk.MenuItem('View')
        item.set_submenu(view_menu)
        menu.prepend(item)

        menu.show_all()
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def do_initialize_popup(self, menu):
        '''
        Disable some items in popup menu for only tagged pages mode. 
        Although it is possible to leave it as is but it is not 
        recommended to create or change page names since not all pages 
        are shown.
        '''
        model = self.get_model()
        if not isinstance(model, gtk.TreeModelFilter):
            PageTreeView.do_initialize_popup(self, menu)
            return 

        path = self.get_selected_path() or Path(':')

        item = gtk.MenuItem(_('Open in New Window'))
        item.connect('activate', lambda o: self.ui.open_new_window(path))
        menu.append(item)

        menu.append(gtk.SeparatorMenuItem())

        item = gtk.ImageMenuItem('gtk-copy')
        item.connect('activate', lambda o: self.do_copy())
        menu.append(item)

        self.populate_popup_expand_collapse(menu)
        menu.show_all()
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def row_activated(self, path, column):
        if column.get_sort_column_id() != self.ICON_NAME:
            return False

        def set_icon(path, icon_name = None):

            iter = self.model.get_iter(path)
            tag = self.model.get_value(iter, self.TAG_COL)
            tag = unicode(tag) #  to use with non latin characters

            if icon_name:
                self.icons_for_tags[tag] = icon_name
            else:
                self.icons_for_tags.pop(tag, None)
            self.refill_model()
            return True

        menu = gtk.Menu()

        item = gtk.MenuItem('None')
        item.connect('activate', lambda item: set_icon(path))
        menu.append(item)

        icons = sorted([(a, render_icon(b)) for (a,b) in ICONS.iteritems()
                        if a not in RESERVED_ICON_NAMES])
        for name, icon in icons:
            image = gtk.Image()
            image.set_from_pixbuf(icon)
            item = gtk.ImageMenuItem(name)
            item.set_use_underline(False)
            item.set_image(image)
            item.zim_icon_name = name
            item.connect('activate', lambda item: set_icon(path, item.zim_icon_name))
            menu.append(item)

        menu.show_all()
        menu.popup(None, None, None, 3, 0)
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def row_activated(self, path, column):
        if column.get_sort_column_id() != self.ICON_NAME:
            return False

        def set_icon(path, icon_name = None):

            tag = self.model.get_value(self.model.get_iter(path), self.TAG_COL)
            tag = unicode(tag) #  to use with non latin characters

            if icon_name:
                self.icons_for_tags[tag] = icon_name
            else:
                self.icons_for_tags.pop(tag, None)
            self.refill_model()
            return True

        menu = gtk.Menu()

        item = gtk.MenuItem('None')
        item.connect('activate', lambda item: set_icon(path))
        menu.append(item)

        icons = sorted([(a, render_icon(b)) for (a,b) in ICONS.iteritems()
                        if a not in RESERVED_ICON_NAMES])
        for name, icon in icons:
            image = gtk.Image()
            image.set_from_pixbuf(icon)
            item = gtk.ImageMenuItem(name)
            item.set_use_underline(False)
            item.set_image(image)
            item.zim_icon_name = name
            item.connect('activate', lambda item: set_icon(path, item.zim_icon_name))
            menu.append(item)

        menu.show_all()
        menu.popup(None, None, None, 3, 0)
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def on_populate_popup(self, treeview, menu):
        '''Add popup menu options.'''
        menu.prepend(gtk.SeparatorMenuItem())

        # Add menu with view options.
        view_menu = gtk.Menu()
        # Add options to show tags and tagged pages.
        items = ( (_('Show only Pages with Tags'), self._show_tagged,
                   lambda o: self.toggle_show_tagged()),
                  (_('Show Tags'), self.uistate['show tags'],
                   lambda o: self.toggle_show_tags()) )
        for name, active, func in items:
            item = gtk.CheckMenuItem(name)
            item.set_active(active)
            item.connect('activate', func)
            view_menu.append(item)
        view_menu.append(gtk.SeparatorMenuItem())

        # Add options to switch between views.
        def _change_view(item, event):
            self.uistate['Open pages'] = item.zim_view
            self.treeview.change_view(self.uistate['Open pages'])

        items = ( (_('Default'), 'default'),
                  (_('Collapse other Pages'), 'collapse'),
                  (_('Disable'), 'disable') )
        item = None
        for name, view in items:
            item = gtk.RadioMenuItem(group = item, label = name)
            if view == self.uistate['Open pages']:
                item.set_active(True)
            item.zim_view = view
            item.connect('button-release-event', _change_view)
            view_menu.append(item)

        item = gtk.MenuItem('View')
        item.set_submenu(view_menu)
        menu.prepend(item)

        menu.show_all()
项目:barbieri-playground    作者:barbieri    | 项目源码 | 文件源码
def _setup_menus(self):
        menu = gtk.Menu()

        item = gtk.MenuItem("Player")
        menu.append(item)
        item.show()
        submenu = gtk.Menu()
        if self.current_engine.menu_items:
            for wid in self.current_engine.menu_items:
                submenu.append(wid)
        item.set_submenu(submenu)
        submenu.show_all()

        def add_action(name):
            item = self.actions[name].create_menu_item()
            menu.append(item)
            item.show()

        item = gtk.MenuItem("Source")
        menu.append(item)
        item.show()
        submenu = gtk.Menu()
        for o in self.sources:
            if o.pretty_name:
                subitem = gtk.MenuItem(o.pretty_name)
                submenu.append(subitem)
                subitem.connect("activate", self._source_activated, o)
        item.set_submenu(submenu)
        submenu.show_all()

        add_action("Preferences")

        item = gtk.SeparatorMenuItem()
        menu.append(item)
        item.show()

        add_action("Quit")

        self.set_menu(menu)
        menu.show()
    # _setup_menus()
项目:PiJuice    作者:PiSupply    | 项目源码 | 文件源码
def __init__(self):
        self.tray = gtk.StatusIcon()
        self.tray.connect('activate', self.refresh)

        # Create menu
        menu = gtk.Menu()

        i = gtk.MenuItem("Configure")
        i.show()
        i.connect("activate", self.ConfigurePiJuice)
        menu.append(i)

        i = gtk.MenuItem("About...")
        i.show()
        i.connect("activate", self.show_about)
        menu.append(i)

        self.tray.connect('popup-menu', self.show_menu, menu)

        self.pijuice = PiJuice(1,0x14)

        # Initalise and start battery display
        self.refresh(None)
        self.tray.set_visible(True)

        gobject.timeout_add(REFRESH_INTERVAL, self.refresh, False)
项目:PiJuice    作者:PiSupply    | 项目源码 | 文件源码
def __init__(self):
        self.tray = gtk.StatusIcon()
        self.tray.connect('activate', self.refresh)

        # Create menu
        menu = gtk.Menu()

        i = gtk.MenuItem("Configure")
        i.show()
        i.connect("activate", self.ConfigurePiJuice)
        menu.append(i)

        i = gtk.MenuItem("About...")
        i.show()
        i.connect("activate", self.show_about)
        menu.append(i)

        self.tray.connect('popup-menu', self.show_menu, menu)

        self.pijuice = PiJuice(1,0x14)

        # Initalise and start battery display
        self.refresh(None)
        self.tray.set_visible(True)

        gobject.timeout_add(REFRESH_INTERVAL, self.refresh, False)
项目:PiJuice    作者:PiSupply    | 项目源码 | 文件源码
def __init__(self):
        self.tray = gtk.StatusIcon()
        self.tray.connect('activate', self.refresh)

        # Create menu
        menu = gtk.Menu()

        i = gtk.MenuItem("Configure")
        i.show()
        i.connect("activate", self.ConfigurePiJuice)
        menu.append(i)

        i = gtk.MenuItem("About...")
        i.show()
        i.connect("activate", self.show_about)
        menu.append(i)

        self.tray.connect('popup-menu', self.show_menu, menu)

        self.pijuice = PiJuice(1,0x14)

        # Initalise and start battery display
        self.refresh(None)
        self.tray.set_visible(True)

        gobject.timeout_add(REFRESH_INTERVAL, self.refresh, False)
项目:PiJuice    作者:PiSupply    | 项目源码 | 文件源码
def __init__(self):
        self.tray = gtk.StatusIcon()
        self.tray.connect('activate', self.refresh)

        # Create menu
        menu = gtk.Menu()

        i = gtk.MenuItem("Configure")
        i.show()
        i.connect("activate", self.ConfigurePiJuice)
        menu.append(i)

        i = gtk.MenuItem("About...")
        i.show()
        i.connect("activate", self.show_about)
        menu.append(i)

        self.tray.connect('popup-menu', self.show_menu, menu)

        self.pijuice = PiJuice(1,0x14)

        # Initalise and start battery display
        self.refresh(None)
        self.tray.set_visible(True)

        gobject.timeout_add(REFRESH_INTERVAL, self.refresh, False)
项目:PiJuice    作者:PiSupply    | 项目源码 | 文件源码
def __init__(self):
        self.tray = gtk.StatusIcon()
        self.tray.connect('activate', self.refresh)

        # Create menu
        menu = gtk.Menu()

        i = gtk.MenuItem("Configure")
        i.show()
        i.connect("activate", self.ConfigurePiJuice)
        menu.append(i)

        i = gtk.MenuItem("About...")
        i.show()
        i.connect("activate", self.show_about)
        menu.append(i)

        self.tray.connect('popup-menu', self.show_menu, menu)

        self.pijuice = PiJuice(1,0x14)

        # Initalise and start battery display
        self.refresh(None)
        self.tray.set_visible(True)

        gobject.timeout_add(REFRESH_INTERVAL, self.refresh, False)
项目:mgr.p2p.proxy    作者:tomusdrw    | 项目源码 | 文件源码
def _showTrayIconMenu(self, event_button, event_time, icon):
        menu = gtk.Menu()
        if not self.get_property('visible'):
            showItem = gtk.MenuItem('Show main window')
            showItem.connect('activate', self._trayIconClick)
            showItem.show()
            menu.append(showItem)
        item = gtk.MenuItem('Quit')
        item.connect('activate', gtk.main_quit)
        item.show()
        menu.append(item)
        menu.popup(None, None, gtk.status_icon_position_menu, event_button,event_time, icon)
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def make_menu(self):
        menu = gtk.Menu()
        itemlist = [(u'Config', self.on_show),
                    ('restart gae_proxy', self.on_restart_gae_proxy),
                    (u'Quit', self.on_quit)]
        for text, callback in itemlist:
            item = gtk.MenuItem(text)
            item.connect('activate', callback)
            item.show()
            menu.append(item)
        menu.show()
        return menu
项目:gui-o-matic    作者:mailpile    | 项目源码 | 文件源码
def _add_menu_item(self, item='item', label='Menu item',
                             sensitive=False,
                             op=None, args=None,
                             **ignored_kwarg):
        menu_item = gtk.MenuItem(label)
        menu_item.set_sensitive(sensitive)
        if op:
            def activate(o, a):
                return lambda d: self._do(o, a)
            menu_item.connect("activate", activate(op, args or []))
        menu_item.show()
        self.items[item] = menu_item
        self.menu.append(menu_item)
项目:gui-o-matic    作者:mailpile    | 项目源码 | 文件源码
def _main_window_indicator(self, menu_container, icon_container):
        if not self._HAVE_INDICATOR:
            menubar = gtk.MenuBar()
            im = gtk.MenuItem(self.config.get('app_name', 'GUI-o-Matic'))
            im.set_submenu(self.menu)
            menubar.append(im)
            menu_container.pack_start(menubar, False, True)

            icon = gtk.Image()
            icon_container.pack_start(icon, False, True)
            self.main_window['indicator_icon'] = icon
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def export_plugins(self):
    """
    dinamically finds the available export plugins
    and fills the export menu entry
    """
    plugins = gutils.read_plugins('PluginExport', \
        self.locations['export_plugins'])
    plugins.sort()
    for p in plugins:
        plugin_module = os.path.basename(p).replace('.py', '')
        plugin_name = plugin_module.replace('PluginExport', '')
        menu_items = gtk.MenuItem(plugin_name)
        self.widgets['menu']['export'].append(menu_items)
        menu_items.connect('activate', self.on_export_activate, plugin_name)
        menu_items.show()
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def createMenuItem(self, shortcut, label):
        menuItem = gtk.MenuItem('')
        menuItem.get_child().set_markup("<span color='blue'  size='x-small'>[%s]</span> %s" % (shortcut, label))
        menuItem.show()
        return menuItem
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def get_folder_menu(self, obj, folder, path):
        if not obj or not (isinstance(obj,gtk.Menu) or isinstance(obj,gtk.MenuItem)):
            return None
        for item in obj.get_children():
            if path == folder+'/'+item.get_label():
                return item.get_submenu()
            i = self.get_folder_menu(item.get_submenu(), folder+'/'+item.get_label(), path)
            if i:
                return i
项目:bookmarks-indicator    作者:antoniocoratelli    | 项目源码 | 文件源码
def append_base_items(self):
        '''
        Append Quit, Restart and GitHub link items to the menu.
        '''
        s = gtk.SeparatorMenuItem()
        l = gtk.MenuItem("GitHub")
        r = gtk.MenuItem("Restart")
        q = gtk.MenuItem("Quit")
        l.connect("activate", self.onclick, "https://github.com/antoniocoratelli/bookmarks-indicator")
        r.connect("activate", self.restart)
        q.connect("activate", self.quit)
        for i in [s, l, r, q]: i.show(); self.menu.append(i)
项目:bookmarks-indicator    作者:antoniocoratelli    | 项目源码 | 文件源码
def append_separator(self, widget, name=None):
        '''
        Append a separator to a menu.
        '''
        sep = gtk.SeparatorMenuItem()
        sep.show()
        widget.append(sep)
        if name != None:
            sep_title = gtk.MenuItem(name)
            sep_title.set_sensitive(False)
            sep_title.show()
            widget.append(sep_title)
项目:bookmarks-indicator    作者:antoniocoratelli    | 项目源码 | 文件源码
def append_item(self, parent, path):
        '''
        Append a folder or a file to a menu.
        '''
        name = os.path.basename(path)
        items = []
        if name == ".":
            # the item is a '.' element: add a menu entry to open the folder
            # in the default file explorer, and a menu entry to open a shell
            # with that folder as working directory
            item_dot = gtk.MenuItem(".", False)
            item_dot.connect("activate", self.onclick, path)
            item_shell = gtk.MenuItem(">_", False)
            item_shell.connect("activate", self.onshell, path)
            items.append(item_dot)
            items.append(item_shell)
        elif os.path.isdir(path):
            item = gtk.MenuItem(name, False)
            submenu = self.append_dummy(item)
            item.connect("activate", self.onhover, path, submenu)
            items.append(item)
        else:
            item = gtk.MenuItem(name, False)
            item.connect("activate", self.onclick, path)
            items.append(item)
        for i in items:
            i.show()
            parent.append(i)
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def make_menu(self):
        menu = gtk.Menu()
        itemlist = [(u'Config', self.on_show),
                    ('restart gae_proxy', self.on_restart_gae_proxy),
                    (u'Quit', self.on_quit)]
        for text, callback in itemlist:
            item = gtk.MenuItem(text)
            item.connect('activate', callback)
            item.show()
            menu.append(item)
        menu.show()
        return menu
项目:Proxy-Factory    作者:ping99    | 项目源码 | 文件源码
def make_menu(self):
        menu = gtk.Menu()
        itemlist = [(u'\u663e\u793a', self.on_show),
                    (u'\u9690\u85cf', self.on_hide),
                    (u'\u505c\u6b62', self.on_stop),
                    (u'\u91cd\u65b0\u8f7d\u5165', self.on_reload),
                    (u'\u9000\u51fa', self.on_quit)]
        for text, callback in itemlist:
            item = gtk.MenuItem(text)
            item.connect('activate', callback)
            item.show()
            menu.append(item)
        menu.show()
        return menu
项目:XX-Net-Mini    作者:GFWParty    | 项目源码 | 文件源码
def make_menu(self):
        menu = gtk.Menu()
        itemlist = [(u'\u663e\u793a', self.on_show),
                    (u'\u9690\u85cf', self.on_hide),
                    (u'\u505c\u6b62', self.on_stop),
                    (u'\u91cd\u65b0\u8f7d\u5165', self.on_reload),
                    (u'\u9000\u51fa', self.on_quit)]
        for text, callback in itemlist:
            item = gtk.MenuItem(text)
            item.connect('activate', callback)
            item.show()
            menu.append(item)
        menu.show()
        return menu
项目:fluxgui    作者:xflux-gui    | 项目源码 | 文件源码
def create_menu(self):
        menu = gtk.Menu()

        self.add_menu_item("_Pause f.lux", self._toggle_pause,
                menu, MenuItem=gtk.CheckMenuItem)
        self.add_menu_item("Prefere_nces", self._open_preferences, menu)
        self.add_menu_separator(menu)
        self.add_menu_item("Quit", self._quit, menu)

        return menu
项目:fluxgui    作者:xflux-gui    | 项目源码 | 文件源码
def add_menu_item(self, label, handler, menu,
            event="activate", MenuItem=gtk.MenuItem, show=True):
        item = MenuItem(label)
        item.connect(event, handler)
        menu.append(item)
        if show:
            item.show()
        return item
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def __init__(self):

            self.main_loop = gobject.MainLoop()            

            # Create a window with a horizontal scale.
            self.wnd = gtk.Window()
            self.wnd.set_default_size(640, 480)
            self.wnd.set_title('Have fun with the transparency slider')

            hscale = gtk.HScale()
            hscale.set_digits(0)
            hscale.set_increments(1, 10)
            hscale.set_range(0, 100)
            hscale.set_value(100)

            hscale.connect('value_changed', self.set_window_alpha)

            self.wnd.add(hscale)

            # Note: gtk window must be realized before installing extensions.
            self.wnd.realize()
            self.wnd.show_all()

            self.win32ext = GTKWin32Ext(self.wnd)

            self.win32ext.add_notify_icon()

            # GTK menus from the notify icon!
            menu = gtk.Menu()

            menu_item = gtk.MenuItem('Baloons!')
            menu_item.connect_object('activate', self.menu_cb, self.wnd)
            menu.append(menu_item)

            menu_item = gtk.MenuItem('Fadeout Window')
            menu_item.connect('activate', self.fadeoutwindow)
            menu.append(menu_item)

            menu_item = gtk.MenuItem('Window Disappeared?')
            menu_item.connect('activate', self.fadeinwindow)
            menu.append(menu_item)

            menu.show_all()
            self.win32ext.notify_icon.menu = menu

            # Set up the callback messages
            self.win32ext.message_map({
                WM_TRAYMESSAGE: self.on_notifyicon_activity
                })
项目:ecel    作者:ARL-UTEP-OC    | 项目源码 | 文件源码
def __init__(self, app_engine, gui):
        menu = gtk.Menu()

        # show main application
        main_application_menu_item = gtk.MenuItem("Main Application")
        main_application_menu_item.show()
        menu.append(main_application_menu_item)
        main_application_menu_item.connect('activate', self.show_main_gui, gui)

        #separator
        sep0 = gtk.SeparatorMenuItem()
        sep0.show()
        menu.append(sep0)

        for collector in app_engine.collectors:
            if isinstance(collector, engine.collector.ManualCollector):
                menu_item_collector = gtk.MenuItem(collector.command_description)
                menu.append(menu_item_collector)
                menu_item_collector.connect('activate', self.run_collector, collector)

        #separator
        sep1 = gtk.SeparatorMenuItem()
        sep1.show()
        menu.append(sep1)

        # show about_menu_item dialog
        self.startall_menu_item = gtk.MenuItem("Start All Collectors")
        self.startall_menu_item.show()
        menu.append(self.startall_menu_item)
        self.startall_menu_item.connect('activate', gui.startall_collectors)

        # show about_menu_item dialog
        self.stopall_menu_item = gtk.MenuItem("Stop All Collectors")
        self.stopall_menu_item.show()
        menu.append(self.stopall_menu_item)
        self.stopall_menu_item.connect('activate', gui.stopall_collectors)
        self.stopall_menu_item.set_sensitive(False)

        #separator
        sep2 = gtk.SeparatorMenuItem()
        sep2.show()
        menu.append(sep2)

        # show about_menu_item dialog
        about_menu_item = gtk.MenuItem("About")
        about_menu_item.show()
        menu.append(about_menu_item)
        about_menu_item.connect('activate', self.show_about_dialog)

        # add quit_menu_item item
        quit_menu_item = gtk.MenuItem("Quit")
        quit_menu_item.show()
        menu.append(quit_menu_item)
        quit_menu_item.connect('activate', self.kill_me, app_engine)

        self.tray_ind = appindicator.Indicator("ECEL", gtk.STOCK_NO, appindicator.CATEGORY_SYSTEM_SERVICES)
        self.tray_ind.set_status(appindicator.STATUS_ACTIVE)
        self.tray_ind.set_menu(menu)

        menu.show_all()