当前位置: 首页>>代码示例>>Python>>正文


Python Gtk.MenuItem方法代码示例

本文整理汇总了Python中gi.repository.Gtk.MenuItem方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.MenuItem方法的具体用法?Python Gtk.MenuItem怎么用?Python Gtk.MenuItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gi.repository.Gtk的用法示例。


在下文中一共展示了Gtk.MenuItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def __init__(self, image_path):
            Gtk.ImageMenuItem.__init__(self)
            self.get_style_context().add_class("KanoComboBox")
            self.set_use_underline(False)
            self.set_always_show_image(True)

            # set the given image
            pixbuf = GdkPixbuf.Pixbuf.new_from_file(image_path)
            image = Gtk.Image.new_from_pixbuf(pixbuf)

            # put the image inside an alignment container for centering
            self.box = Gtk.Alignment()
            self.box.set_padding(0, 0, 0, pixbuf.get_width())
            self.box.add(image)

            # by default, a MenuItem has an AccelLabel widget as it's one and only child
            self.remove(self.get_child())
            self.add(self.box)

            # By overriding this signal we can stop the Menu
            # containing this item from being popped down
            self.connect("button-release-event", self.do_not_popdown_menu) 
开发者ID:KanoComputing,项目名称:kano-toolset,代码行数:24,代码来源:kano_combobox.py

示例2: on_treeview_button_release_event

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def on_treeview_button_release_event(self, widget, event):
        try:
            # define context menu
            popup = Gtk.Menu()
            kd_item = Gtk.MenuItem(_("Open with Kdenlive"))
            # selected row is already caught by on_treeview_selection_changed function
            kd_item.connect("activate", self.on_open_with_kdenlive, self.sel_folder)

            # don"t show menu item if there are no video files
            if self.sel_vid > 0 and cli.kd_supp is True:
                popup.append(kd_item)

            open_item = Gtk.MenuItem(_("Open folder"))
            open_item.connect("activate", self.on_open_folder, self.sel_folder)
            popup.append(open_item)
            popup.show_all()
            # only show on right click
            if event.button == 3:
                popup.popup(None, None, None, None, event.button, event.time)
                return True
        except AttributeError:
            # this error (missing variable self.sel_folder) is returned when clicking on title row
            # ignoring because there is nothing to happen on right click
            pass 
开发者ID:encarsia,项目名称:gpt,代码行数:26,代码来源:modules.py

示例3: gtk_menu_insert_by_path

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def gtk_menu_insert_by_path(menu, menu_path, menu_item):
	"""
	Add a new menu item into the existing menu at the path specified in
	*menu_path*.

	:param menu: The existing menu to add the new item to.
	:type menu: :py:class:`Gtk.Menu` :py:class:`Gtk.MenuBar`
	:param list menu_path: The labels of submenus to traverse to insert the new item.
	:param menu_item: The new menu item to insert.
	:type menu_item: :py:class:`Gtk.MenuItem`
	"""
	utilities.assert_arg_type(menu, (Gtk.Menu, Gtk.MenuBar), 1)
	utilities.assert_arg_type(menu_path, list, 2)
	utilities.assert_arg_type(menu_item, Gtk.MenuItem, 3)
	while len(menu_path):
		label = menu_path.pop(0)
		menu_cursor = gtk_menu_get_item_by_label(menu, label)
		if menu_cursor is None:
			raise ValueError('missing node labeled: ' + label)
		menu = menu_cursor.get_submenu()
	menu.append(menu_item) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:23,代码来源:gui_utilities.py

示例4: add_menu_item

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def add_menu_item(self, menu_path, handler=None):
		"""
		Add a new item into the main menu bar of the application. Menu items
		created through this method are automatically removed when the plugin
		is disabled. If no *handler* is specified, the menu item will be a
		separator, otherwise *handler* will automatically be connected to the
		menu item's ``activate`` signal.

		:param str menu_path: The path to the menu item, delimited with > characters.
		:param handler: The optional callback function to be connected to the new :py:class:`Gtk.MenuItem` instance's activate signal.
		:return: The newly created and added menu item.
		:rtype: :py:class:`Gtk.MenuItem`
		"""
		menu_path = _split_menu_path(menu_path)
		if handler is None:
			menu_item = Gtk.SeparatorMenuItem()
		else:
			menu_item = Gtk.MenuItem.new_with_label(menu_path.pop())
			self.signal_connect('activate', handler, gobject=menu_item)
		return self._insert_menu_item(menu_path, menu_item) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:22,代码来源:plugins.py

示例5: append

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def append(self, label, activate=None, activate_args=()):
		"""
		Create and append a new :py:class:`Gtk.MenuItem` with the specified
		label to the menu.

		:param str label: The label for the new menu item.
		:param activate: An optional callback function to connect to the new
			menu item's ``activate`` signal.
		:return: Returns the newly created and added menu item.
		:rtype: :py:class:`Gtk.MenuItem`
		"""
		if label in self.items:
			raise RuntimeError('label already exists in menu items')
		menu_item = Gtk.MenuItem.new_with_label(label)
		self.items[label] = menu_item
		self.append_item(menu_item)
		if activate:
			menu_item.connect('activate', activate, *activate_args)
		return menu_item 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:21,代码来源:managers.py

示例6: get_popup_copy_submenu

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def get_popup_copy_submenu(self):
		"""
		Create a :py:class:`Gtk.Menu` with entries for copying cell data from
		the treeview.

		:return: The populated copy popup menu.
		:rtype: :py:class:`Gtk.Menu`
		"""
		copy_menu = Gtk.Menu.new()
		for column_title, store_id in self.column_titles.items():
			menu_item = Gtk.MenuItem.new_with_label(column_title)
			menu_item.connect('activate', self.signal_activate_popup_menu_copy, store_id)
			copy_menu.append(menu_item)
		if len(self.column_titles) > 1:
			menu_item = Gtk.SeparatorMenuItem()
			copy_menu.append(menu_item)
			menu_item = Gtk.MenuItem.new_with_label('All')
			menu_item.connect('activate', self.signal_activate_popup_menu_copy, self.column_titles.values())
			copy_menu.append(menu_item)
		return copy_menu 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:22,代码来源:managers.py

示例7: add_nav_portion_to_menu

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def add_nav_portion_to_menu(self, menu):
        """
        This function adds a common history-navigation portion
        to the context menu. Used by both build_nav_menu() and
        build_full_nav_menu() methods.
        """
        hobj = self.uistate.get_history(self.navigation_type(),
                                        self.navigation_group())
        home_sensitivity = True
        if not self.dbstate.db.get_default_person():
            home_sensitivity = False
            # bug 4884: need to translate the home label
        entries = [
            (_("Pre_vious"), self.back_clicked, not hobj.at_front()),
            (_("_Next"), self.fwd_clicked, not hobj.at_end()),
            (_("_Home"), self.cb_home, home_sensitivity),
        ]

        for label, callback, sensitivity in entries:
            item = Gtk.MenuItem.new_with_mnemonic(label)
            item.set_sensitive(sensitivity)
            if callback:
                item.connect("activate", callback)
            item.show()
            menu.append(item) 
开发者ID:gramps-project,项目名称:addons-source,代码行数:27,代码来源:HtreePedigreeView.py

示例8: cb_build_missing_parent_nav_menu

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def cb_build_missing_parent_nav_menu(self, obj, event,
                                         person_handle, family_handle):
        """Builds the menu for a missing parent."""
        self.menu = Gtk.Menu()
        self.menu.set_reserve_toggle_size(False)

        add_item = Gtk.MenuItem.new_with_mnemonic(_('_Add'))
        add_item.connect("activate", self.cb_add_parents, person_handle,
                         family_handle)
        add_item.show()
        self.menu.append(add_item)

        # Add a separator line
        add_item = Gtk.SeparatorMenuItem()
        add_item.show()
        self.menu.append(add_item)

        # Add history-based navigation
        self.add_nav_portion_to_menu(self.menu)
        self.add_settings_to_menu(self.menu)
        self.menu.popup(None, None, None, None, 0, event.time)
        return 1 
开发者ID:gramps-project,项目名称:addons-source,代码行数:24,代码来源:HtreePedigreeView.py

示例9: build_missing_parent_nav_menu_cb

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def build_missing_parent_nav_menu_cb(self, obj, event,
                                         person_handle, family_handle):
        """Builds the menu for a missing parent."""
        menu = Gtk.Menu()
        # need to leave space for toggle items

        add_item = Gtk.MenuItem.new_with_mnemonic(_("_Add"))
        add_item.connect("activate", self.add_parents_cb, person_handle,
                         family_handle)
        add_item.show()
        menu.append(add_item)

        # Add history-based navigation
        self.add_nav_portion_to_menu(menu)
        self.add_settings_to_menu(menu)
        menu.popup(None, None, None, None, 0, event.time)
        return 1 
开发者ID:gramps-project,项目名称:addons-source,代码行数:19,代码来源:TimelinePedigreeView.py

示例10: do_populate_popup

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def do_populate_popup(self, popup):
        """
        Adds link-related options to the context menu.
        """
        if self.__clicked_link:
            item_separator = Gtk.MenuItem()
            popup.prepend(item_separator)

            item_open_link = Gtk.MenuItem()
            item_open_link.set_label(_("Open Link"))
            item_open_link.connect("activate", self.__open_link,
                                   self.__clicked_link)
            popup.prepend(item_open_link)

            item_copy_link = Gtk.MenuItem()
            item_copy_link.set_label(_("Copy Link to Clipboard"))
            item_copy_link.connect("activate", self.__copy_link,
                                   self.__clicked_link)
            popup.prepend(item_copy_link)

            popup.show_all()
            self.__clicked_link = "" 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:24,代码来源:taskview.py

示例11: __on_task_added

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def __on_task_added(self, tid, path):
        self.__task_separator.show()
        task = self.__requester.get_task(tid)
        if task is None:
            return

        # ellipsis of the title
        title = self.__create_short_title(task.get_title())

        # creating the menu item
        # FIXME test for regression: create a task like Hello_world
        # (_ might be converted)
        menu_item = Gtk.MenuItem(label=title)
        menu_item.connect('activate', self.__open_task, tid)
        self.__tasks_menu.add(tid, (task.get_due_date(), title), menu_item)

        self._indicator.update_menu() 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:19,代码来源:notification_area.py

示例12: create_menu_box_with_icon_and_label

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def create_menu_box_with_icon_and_label(label_text):
    """ Creates a MenuItem box, which is a replacement for the former ImageMenuItem. The box contains, a label
        for the icon and one for the text.

    :param label_text: The text, which is displayed for the text label
    :return:
    """
    box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 10)
    box.set_border_width(0)
    icon_label = Gtk.Label()
    text_label = Gtk.AccelLabel.new(label_text)
    text_label.set_xalign(0)

    box.pack_start(icon_label, False, False, 0)
    box.pack_start(text_label, True, True, 0)
    return box, icon_label, text_label 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:18,代码来源:label.py

示例13: createLocalMenu

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def createLocalMenu(self, items):
        ITEM_MAP = {
            ACCEPT: (_("Accept"), self.on_accept),
            ASSESS: (_("Assess"), self.on_assess),
            OBSERVE: (_("Observe"), self.on_observe),
            FOLLOW: (_("Follow"), self.on_follow),
            CHAT: (_("Chat"), self.on_chat),
            CHALLENGE: (_("Challenge"), self.on_challenge),
            FINGER: (_("Finger"), self.on_finger),
            ARCHIVED: (_("Archived"), self.on_archived), }

        self.menu = Gtk.Menu()
        for item in items:
            if item == SEPARATOR:
                menu_item = Gtk.SeparatorMenuItem()
            else:
                label, callback = ITEM_MAP[item]
                menu_item = Gtk.MenuItem(label)
                menu_item.connect("activate", callback)
            self.menu.append(menu_item)
        self.menu.attach_to_widget(self.tv, None) 
开发者ID:pychess,项目名称:pychess,代码行数:23,代码来源:ParrentListSection.py

示例14: get_menu_object

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def get_menu_object(self, menu_name_or_link):
        """
        utility function returns the GtkMenuItem/Gio.MenuItem
        :param menu_name_or_link: `str` to search for in the UI file
        """
        if menu_name_or_link in self._rbmenu_objects:
            return self._rbmenu_objects[menu_name_or_link]
        item = self.builder.get_object(menu_name_or_link)
        if is_rb3(self.shell):
            if item:
                popup_menu = item
            else:
                app = self.shell.props.application
                popup_menu = app.get_plugin_menu(menu_name_or_link)
        else:
            popup_menu = item
        print(menu_name_or_link)
        self._rbmenu_objects[menu_name_or_link] = popup_menu

        return popup_menu 
开发者ID:fossfreedom,项目名称:alternative-toolbar,代码行数:22,代码来源:alttoolbar_rb3compat.py

示例15: __create_menu

# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import MenuItem [as 别名]
def __create_menu(self):
        menu = Gtk.Menu()

        item_settings = Gtk.MenuItem('Settings')
        item_settings.connect("activate", self.__settings_window)
        menu.append(item_settings)

        item_about = Gtk.MenuItem('About')
        item_about.connect("activate", self.__about_window)
        menu.append(item_about)

        item_quit = Gtk.MenuItem('Quit')
        item_quit.connect("activate", self.__quit)
        menu.append(item_quit)
        menu.show_all()

        return menu 
开发者ID:maateen,项目名称:battery-monitor,代码行数:19,代码来源:AppIndicator.py


注:本文中的gi.repository.Gtk.MenuItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。