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

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

项目: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()
项目: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.'''
            text = getIconMarkup(item)
            pageview.view.get_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)
项目: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)
项目:terminator-themes    作者:EliverLara    | 项目源码 | 文件源码
def callback(self, menuitems, menu, terminal):
        """Add our item to the menu"""
        self.terminal = terminal
        item = Gtk.ImageMenuItem(Gtk.STOCK_FIND)
        item.connect('activate',self.configure)
        item.set_label("Themes")
        item.set_sensitive(True)
        menuitems.append(item)
项目: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
项目: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