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

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

项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def insert_icon(self, pageview):
        '''Create widget to choose an icon and insert an icon shortcode.'''

        def _insert(item):
            '''Insert an icon shortcode to the cursor position.'''
            buffer = pageview.view.get_buffer()
            text = '{0}{1}{2}{3}{0}'.format(STRONG_MARKUP, PREFIX, item, POSTFIX)
            buffer.insert_at_cursor(text)

        menu = gtk.Menu()
        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_image(image)
            item.set_use_underline(False)
            item.connect('button-release-event', lambda item, _:
                         _insert(item.get_label()))
            menu.append(item)
    menu.popup(None, None, None, 3, 0)
        menu.show_all()
项目:pyttrss    作者:balanceofcowards    | 项目源码 | 文件源码
def __init__(self, ttrss):
        self.ttrss = ttrss
        self.menu = gtk.Menu()
        quitter = gtk.ImageMenuItem(gtk.STOCK_QUIT)
        quitter.set_always_show_image(True)
        self.menu.append(quitter)
        quitter.show()
        quitter.connect("activate", gtk.main_quit)
        self.viewer = ArticleViewer()
        self.viewer.on_hide = self.update_articles
        self.status_icon = gtk.StatusIcon()
        self.status_icon.set_from_icon_name("mail-read")
        self.update_headlines()
        self.to = gtk.timeout_add(1000 * 60, self.update_headlines)
        self.status_icon.connect("activate", self.toggle_viewer)
        self.status_icon.connect("popup-menu", self.show_menu)
项目:bookmarks-indicator    作者:antoniocoratelli    | 项目源码 | 文件源码
def onhover(self, widget, path, submenu):
        '''
        When the user hovers a folder item replace the dummy separator with the
        actual content of the folder.
        '''
        submenu = gtk.Menu()
        widget.set_submenu(submenu)
        self.append_item(submenu, os.path.join(path, "."))
        list_dirs  = get_subdirs(path)
        list_files = get_subfiles(path)
        if len(list_dirs) or len(list_files):
            self.append_separator(submenu)
        for d in sorted(list_dirs):
            self.append_item(submenu, os.path.join(path, d))
        if len(list_dirs) and len(list_files):
            self.append_separator(submenu)
        for f in sorted(list_files):
            self.append_item(submenu, os.path.join(path, f))
项目:ns3-rdma    作者:bobzhuyb    | 项目源码 | 文件源码
def popup_node_menu(self, node, event):
        menu = gtk.Menu()
        self.emit("populate-node-menu", node, menu)
        menu.popup(None, None, None, event.button, event.time)
项目: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
项目: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 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 _menu_setup(self):
        self.items = {}
        self.menu = gtk.Menu()
        self._create_menu_from_config()
项目: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)
项目:hazzy    作者:KurtJacobson    | 项目源码 | 文件源码
def on_gremlin_clicked(self, widget, event, data=None):
        if event.type == gtk.gdk._2BUTTON_PRESS:
            self.clear_live_plotter()

# Settings
        if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:

            menu = gtk.Menu()

            program_alpha = gtk.CheckMenuItem("Program alpha")
            program_alpha.set_active(self.program_alpha)
            program_alpha.connect("activate", self.toggle_program_alpha)
            menu.append(program_alpha)

            show_limits = gtk.CheckMenuItem("Show limits")
            show_limits.set_active(self.show_limits)
            show_limits.connect("activate", self.toggle_show_limits)
            menu.append(show_limits)

            show_extents = gtk.CheckMenuItem("Show extents")
            show_extents.set_active(self.show_extents_option)
            show_extents.connect("activate", self.toggle_show_extents_option)
            menu.append(show_extents)

            live_plot = gtk.CheckMenuItem("Show live plot")
            live_plot.set_active(self.show_live_plot)
            live_plot.connect("activate", self.toggle_show_live_plot)
            menu.append(live_plot)

#            lathe = gtk.CheckMenuItem("Lathe mode")
#            lathe.set_active(self.lathe_option )
#            lathe.connect("activate", self.toggle_lathe_option)
#            menu.append(lathe)

            menu.popup(None, None, None, event.button, event.time)
            menu.show_all()
项目: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 init_indicator(self):
        '''
        Set the basic properties (icon, label, ...) of the indicator.
        '''
        self.menu = gtk.Menu()
        self.indicator = ai.Indicator(self.title, self.icon, ai.CATEGORY_APPLICATION_STATUS)
        self.indicator.set_label(self.label)
        self.indicator.set_status(ai.STATUS_ACTIVE)
        self.indicator.set_menu(self.menu)
项目:bookmarks-indicator    作者:antoniocoratelli    | 项目源码 | 文件源码
def append_dummy(self, widget):
        '''
        Insert a dummy separator in the submenu of a folder item.
        Thanks to this function item representing folders always have an arrow,
        and it is possible to expand the folder content only when the user
        actually hovers the item.
        '''
        submenu = gtk.Menu()
        self.append_separator(submenu)
        widget.set_submenu(submenu)
        return submenu
项目: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
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def setup_menu(self, mnu_items, mnu_pixmaps, activate_cb):
        """returns a gtk menu object
        Parameters:
            mnu_items   : List of menu item names (either a string, a gtk stock item or '_sep_' for a separator)
            mnu_pixmaps : List of pixmaps (filename, a gtk stock icon or None)
            activate_cb : Callback function for menu activation
        Returns:
            Reference to the constructed gtk.Menu
        """
        mnu = gtk.Menu()
        for i in range(len(mnu_items)):
            #separator or menu item?
            if mnu_items[i] != '_sep_':
                #menu item
                mnuItem = gtk.ImageMenuItem(stock_id=mnu_items[i])
                img = gtk.Image()
                if mnu_pixmaps[i]:
                    if mnu_pixmaps[i][:4] == 'gtk-' and '.' not in mnu_pixmaps[i]:
                        #stock icon
                        img.set_from_stock(mnu_pixmaps[i], gtk.ICON_SIZE_MENU)
                    else:
                        #file icon
                        img.set_from_pixbuf(self.get_pixbuf(mnu_pixmaps[i], gtk.ICON_SIZE_MENU))
                    img.show()
                    mnuItem.set_image(img)
                mnuItem.connect('activate', activate_cb)
                mnuItem.set_name(mnu_items[i])
            else:
                #separator
                mnuItem = gtk.SeparatorMenuItem()
            #add item to menu
            mnuItem.show()
            mnu.append(mnuItem)
        #done
        return mnu
项目: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
项目: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()
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def add_catalog_items(self, menu_add):

        def add_to_menu(grp_menu, path) :
            for ptr in range(len(path)) :
                try :
                    p = path[ptr]
                    if p.tag.lower() in ["menu", "menuitem", "group", "sub"] :
                        name = p.get("name") if "name" in p.keys() else ""
                        a_menu_item = gtk.ImageMenuItem(_(name))

                        tooltip = _(p.get("tool_tip")) if "tool_tip" in p.keys() else None
                        if (tooltip is not None) and (tooltip != '') :
                            a_menu_item.set_tooltip_markup(_(tooltip))

                        icon = p.get('icon')
                        if icon is not None :
                            img = gtk.Image()
                            img.set_from_pixbuf(get_pixbuf(icon, add_menu_icon_size))
                            a_menu_item.set_image(img)

                        src = p.get('src')
                        if src is not None :
                            a_menu_item.connect("activate", self.add_feature, src)

                        grp_menu.append(a_menu_item)

                        if p.tag.lower() in ['menu', "group"] :
                            a_menu = gtk.Menu()
                            a_menu_item.set_submenu(a_menu)
                            add_to_menu(a_menu, p)

                    elif p.tag.lower() == "separator":
                        grp_menu.append(gtk.SeparatorMenuItem())
                except:
                    pass

        if self.catalog.tag != 'ncam_ui' :
            mess_dlg(_('Menu is old format, no toolbar defined.\nUpdate to new format'))
            add_to_menu(menu_add, self.catalog)
        else :
            for _ptr in range(len(self.catalog)) :
                _p = self.catalog[_ptr]
                if _p.tag.lower() in ["menu", "group"] :
                    add_to_menu(menu_add, _p)
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def updateTree(self):
        for grupo in dict(groups):
            if len(groups[grupo])==0:
                del groups[grupo]

        if conf.COLLAPSED_FOLDERS == None:
            conf.COLLAPSED_FOLDERS = ','.join(self.get_collapsed_nodes())

        self.menuServers.foreach(self.menuServers.remove)
        self.treeModel.clear()

        iconHost = self.treeServers.render_icon("gtk-network", size=gtk.ICON_SIZE_BUTTON, detail=None)
        iconDir = self.treeServers.render_icon("gtk-directory", size=gtk.ICON_SIZE_BUTTON, detail=None)             

        grupos = groups.keys()
        grupos.sort(lambda x,y: cmp(y,x))

        for grupo in grupos:
            group = None
            path = ""
            menuNode = self.menuServers

            for folder in grupo.split("/"):
                path = path + '/' + folder
                row = self.get_folder(self.treeModel, '', path)
                if row == None:
                    group = self.treeModel.prepend(group, [folder, None, iconDir])
                else:
                    group = row.iter

                menu = self.get_folder_menu(self.menuServers, '', path)
                if menu == None:
                    menu = gtk.ImageMenuItem(folder)
                    #menu.set_image(gtk.image_new_from_stock(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_MENU))
                    menuNode.prepend(menu)
                    menuNode = gtk.Menu()
                    menu.set_submenu(menuNode)
                    menu.show()
                else:
                    menuNode = menu

            groups[grupo].sort(key=operator.attrgetter('name'))
            for host in groups[grupo]:
                self.treeModel.append(group, [host.name, host, iconHost])
                mnuItem = gtk.ImageMenuItem(host.name)
                mnuItem.set_image(gtk.image_new_from_stock(gtk.STOCK_NETWORK, gtk.ICON_SIZE_MENU))
                mnuItem.show()
                mnuItem.connect("activate", lambda arg, nb, h: self.addTab(nb, h), self.nbConsole, host) 
                menuNode.append(mnuItem)

        self.set_collapsed_nodes()
        conf.COLLAPSED_FOLDERS = None