Python gi.repository.Gtk 模块,ImageMenuItem() 实例源码

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

项目:emoji-keyboard    作者:OzymandiasTheGreat    | 项目源码 | 文件源码
def build_menu(self):

        menu = Gtk.Menu()
        self.show_keyboard = Gtk.ImageMenuItem('Show Keyboard')
        icon_keyboard = Gtk.Image.new_from_icon_name('keyboard', 22)
        self.show_keyboard.set_image(icon_keyboard)
        self.show_keyboard.connect('activate', self.toggle_keyboard)
        self.search = Gtk.ImageMenuItem('Search')
        icon_search = Gtk.Image.new_from_icon_name('search', 22)
        self.search.set_image(icon_search)
        self.search.connect('activate', self.toggle_search)
        self.settings = Gtk.ImageMenuItem('Settings')
        icon_settings = Gtk.Image.new_from_icon_name('configure', 22)
        self.settings.set_image(icon_settings)
        self.settings.connect('activate', self.show_settings)
        self.menu_quit = Gtk.ImageMenuItem('Quit')
        icon_quit = Gtk.Image.new_from_icon_name('application-exit', 22)
        self.menu_quit.set_image(icon_quit)
        self.menu_quit.connect('activate', self.quit)
        menu.append(self.show_keyboard)
        menu.append(self.search)
        menu.append(self.settings)
        menu.append(self.menu_quit)
        menu.show_all()
        return menu
项目:fux-terminal    作者:fuxprojesi    | 项目源码 | 文件源码
def on_button_press_event(wid, event):
        """
        on_button_press_event: Sa? tu?a t?kland???nda yap?lacak i?lem

        Fare'nin sa? tu?una t?kland???nda bu fonksiyon tetiklenir. Fonksiyon içinde
        T?klanan tu?un sa? tu? olup olmad??? sorgulan?r. E?er do?ru ise aç?l?r menü
        Olu?turulur. Olu?turulam menü argümanlar?na sinyaller atan?r ve gösterilir.
        """
        if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3:
           menu = Gtk.Menu()

           term = Gtk.ImageMenuItem("Terminal Aç")
           term_img = Gtk.Image()
           term_img.set_from_icon_name("utilities-terminal", Gtk.IconSize.MENU)
           term.set_image(term_img)
           term.set_always_show_image(True)

           copy = Gtk.ImageMenuItem("Kopyala")
           copy_img = Gtk.Image()
           copy_img.set_from_icon_name("edit-copy", Gtk.IconSize.MENU)
           copy.set_image(copy_img)
           copy.set_always_show_image(True)

           paste = Gtk.ImageMenuItem("Yap??t?r")
           paste_img = Gtk.Image()
           paste_img.set_from_icon_name("edit-paste", Gtk.IconSize.MENU)
           paste.set_image(paste_img)
           paste.set_always_show_image(True)

           menu.append(term)
           menu.append(Gtk.SeparatorMenuItem())
           menu.append(copy)
           menu.append(paste)

           term.connect("activate", RightClick.open_terminal)
           copy.connect("activate", RightClick.copy_text)
           paste.connect("activate", RightClick.paste_text)

           menu.show_all()
           menu.popup(None, None, None, None, event.button, event.time)
           return True
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def create_stock_menu_item(stock, txt, callback, ag, accel_key, accel_mod):
    box = Gtk.HBox(False, 0)
    box.set_spacing(PAD_SMALL)
    im = Gtk.Image()
    im.set_from_stock(stock, Gtk.IconSize.MENU)
    item = Gtk.ImageMenuItem(txt)
    item.set_image(im)
    if accel_key != 0:
        item.add_accelerator('activate', ag, accel_key, accel_mod, Gtk.AccelFlags.VISIBLE)
    item.connect('activate', callback)
    return item
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def on_right_click_row(self, button, event, linked):
        idx = self.m_model.index(linked)
        if event.button == 3:
            m = Gtk.Menu()
            item = Gtk.ImageMenuItem(Gtk.STOCK_DELETE)
            item.connect('activate', self.on_delete_link, linked)
            ###
            m.append(item)
            item = Gtk.ImageMenuItem(Gtk.STOCK_CUT)
            item.connect('activate', self.on_cut_link, idx)
            ###
            m.append(item)
            item = Gtk.ImageMenuItem(Gtk.STOCK_PASTE)
            item.set_sensitive(bool(Editor.clipboard))
            item.connect('activate', self.on_paste, idx)
            ###
            m.append(item)
            item = Gtk.ImageMenuItem(Gtk.STOCK_EDIT)
            item.connect('activate', self.on_edit_linktext, linked)
            item.set_sensitive(bool(not isinstance(linked, basestring)))
            ###
            m.append(item)
            item = Gtk.ImageMenuItem(Gtk.STOCK_GO_UP)
            item.connect('activate', self.on_move_link_up, idx)
            item.set_sensitive(bool(idx > 0))
            ###
            m.append(item)
            item = Gtk.ImageMenuItem(Gtk.STOCK_GO_DOWN)
            item.connect('activate', self.on_move_link_down, idx)
            item.set_sensitive(bool(idx < len(self.m_model) - 1))
            ###
            m.append(item)
            item = Gtk.ImageMenuItem(Gtk.STOCK_EDIT)
            item.set_sensitive(isinstance(linked, unicode))
            item.connect('activate', self.on_edit_file, idx)
            ###
            m.append(item)
            m.show_all()
            m.popup(None, None, None, None, event.button, event.time)
            return True
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def _populate_popup(self, textview, menu):
        '''Populates the menu with the Find item.'''
        menu.append(Gtk.SeparatorMenuItem())
        opc = Gtk.ImageMenuItem((Gtk.STOCK_FIND))
        opc.get_children()[0].set_label('Find...')
        menu.append(opc)
        opc.connect("activate", self.show_search)
        menu.show_all()
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def _populate_menu(self, textview, menu):
        opc = Gtk.ImageMenuItem((Gtk.STOCK_CLEAR))
        opc.get_children()[0].set_label('Clear text')
        menu.prepend(Gtk.SeparatorMenuItem())
        menu.prepend(opc)
        opc.connect("activate", self._clear, iter)
        menu.show_all()
项目:pomodoroTasks2    作者:liloman    | 项目源码 | 文件源码
def show_change_task(self):
        self.showChangeTask(Gtk.ImageMenuItem())


    # to be called from the daemon
项目: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)
项目:gracer    作者:isamert    | 项目源码 | 文件源码
def on_view_populate_popup(self, view, menu):
        menu_find_definition = Gtk.ImageMenuItem(_("Find Definition"))
        menu_find_definition.connect('activate', self.on_find_definition_active)
        #menu_find_definition.set_image(gtk.image_new_from_stock(gtk.STOCK_COMMENT, gtk.ICON_SIZE_MENU))
        menu_find_definition.show()

        separator = Gtk.SeparatorMenuItem()
        separator.show()

        menu.prepend(separator)
        menu.prepend(menu_find_definition)
项目:any_ping_indicator    作者:leggedrobotics    | 项目源码 | 文件源码
def __init__(self, id, name, address, update_rate, number_of_pings,
                 show_indicator, show_text, is_activated=None):
        """Initialize.
        :param id:
        :param address:
        :param update_rate:
        :param number_of_pings:
        :param show_indicator:
        :param is_activated:
        """
        # init gobject
        GObject.GObject.__init__(self)
        GObject.type_register(PingObject)
        GObject.threads_init()
        # ping object properties
        self.id = id
        self.name = name
        if not self.name:
            self.name = address
        self.address = address
        self.update_rate = update_rate
        self.number_of_pings = number_of_pings
        self.show_indicator = show_indicator
        self.show_text = show_text
        if is_activated is None:
            self.is_activated = True
        else:
            self.is_activated = is_activated
        self.icon = "icon_red"
        if not self.is_activated:
            self.icon = "icon_grey"
        self.ping_warning = 50.0
        # indicator menu item
        self.menu_item = gtk.ImageMenuItem("Ping: " + address)
        # result
        self.result = PingStruct(RESULT_NO_RESPONSE, 0.0, 0.0, 0.0, 0.0)
        # gtk image for menu item
        self.image = gtk.Image()
        self.image.set_from_file(resource.image_path("icon_gray", theme.THEME))
        # ping state
        self.state = "Ping: " + self.address + " initializing."
        # store subprocess
        self.process = None
        # mutex
        self.mutex = threading.Lock()
        # thread
        self.thread = None
        self.is_running = False
        # interruptable sleep function
        self.stop_event = threading.Event()
        # current time
        self.time_last = time.time()

    # signal definition returns (id, name, icon name, show_indicator)
项目:pomodoroTasks2    作者:liloman    | 项目源码 | 文件源码
def right_click_event(self, icon, button, time):
        def toggle_continuous(ImageMenuItem):
            threading.Thread(target=self._toggle_continuous,args=[]).start()

        def _quit_daemon():
            #don't try to close the systray
            self.interface.do_quit(False)

        def quit_daemon():
            threading.Thread(target=_quit_daemon,args=[]).start()

        def quit(ImageMenuItem):
            quit_daemon()
            Gtk.main_quit()

        #the funcs must be declared before menu.append use
        def do_reset(ImageMenuItem):
            threading.Thread(target=self._fsm,args=['reset']).start()

        def do_stop(ImageMenuItem):
            threading.Thread(target=self._fsm,args=['stop']).start()

        def take_a_break(ImageMenuItem):
            threading.Thread(target=self._fsm,args=['take_break']).start()

        def create_menu_item(label, icon_name):
            image = Gtk.Image()
            image.set_from_icon_name(icon_name, 24)
            item = Gtk.ImageMenuItem()
            item.set_label(label)
            item.set_image(image)
            return item  

        def connect_menu_item(label, icon_name, event):
            item = create_menu_item(label, icon_name)
            item.connect("activate", event)
            return item

        self.menu = Gtk.Menu()

        self.menu.append(connect_menu_item("Change task", "edit-paste", self.showChangeTask))
        self.menu.append(connect_menu_item("Toggle continuous", "gtk-goto-last", toggle_continuous))
        self.menu.append(connect_menu_item("Reset", "edit-redo", do_reset))
        self.menu.append(connect_menu_item("Stop", "process-stop", do_stop))
        self.menu.append(connect_menu_item("Take a break", "alarm-symbolic", take_a_break))
        self.menu.append(connect_menu_item("Close app", "application-exit",quit))

        self.menu.show_all()
        self.menu.popup(None, None, None, self.status_icon, button, time)
项目:mate-menu    作者:ubuntu-mate    | 项目源码 | 文件源码
def searchPopup( self, widget=None, event=None ):
        menu = Gtk.Menu()

        menuItem = Gtk.ImageMenuItem(label=_("Search DuckDuckGo"))
        img = Gtk.Image()
        img.set_from_file("/usr/share/mate-menu/icons/search_engines/ddg.png")
        menuItem.set_image(img)
        menuItem.connect("activate", self.search_ddg)
        menu.append(menuItem)

        menuItem = Gtk.ImageMenuItem(label=_("Search Google"))
        img = Gtk.Image()
        img.set_from_file("/usr/share/mate-menu/icons/search_engines/google.png")
        menuItem.set_image(img)
        menuItem.connect("activate", self.search_google)
        menu.append(menuItem)

        menuItem = Gtk.ImageMenuItem(label=_("Search Wikipedia"))
        img = Gtk.Image()
        img.set_from_file("/usr/share/mate-menu/icons/search_engines/wikipedia.png")
        menuItem.set_image(img)
        menuItem.connect("activate", self.search_wikipedia)
        menu.append(menuItem)

        menuItem = Gtk.SeparatorMenuItem()
        menu.append(menuItem)

        menuItem = Gtk.ImageMenuItem(label=_("Lookup Dictionary"))
        img = Gtk.Image()
        img.set_from_file('/usr/share/mate-menu/icons/dictionary.png')
        menuItem.set_image(img)
        menuItem.connect("activate", self.search_dictionary)
        menu.append(menuItem)

        menuItem = Gtk.ImageMenuItem(label=_("Search Computer"))
        img = Gtk.Image()
        img.set_from_icon_name("edit-find", Gtk.IconSize.INVALID)
        img.set_pixel_size( self.iconSize )
        menuItem.set_image(img)
        menuItem.connect("activate", self.Search)
        menu.append(menuItem)

        menu.show_all()

        self.mateMenuWin.stopHiding()
        menu.attach_to_widget(self.searchButton, None)
        if (Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION) >= (3, 22):
            menu.popup_at_widget(widget, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, event)
        else:
            menu.popup(None, None, None, None, event.button, event.time)

        #menu.reposition()
        #menu.reposition()
        #self.mateMenuWin.grab()
        self.focusSearchEntry(clear = False)
        return True