Python gi.repository.Gtk.MenuItem() Examples
The following are 30
code examples of gi.repository.Gtk.MenuItem().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gi.repository.Gtk
, or try the search function
.
Example #1
Source File: notification_area.py From gtg with GNU General Public License v3.0 | 6 votes |
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()
Example #2
Source File: managers.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #3
Source File: plugins.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #4
Source File: gui_utilities.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #5
Source File: managers.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #6
Source File: modules.py From gpt with GNU General Public License v3.0 | 6 votes |
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
Example #7
Source File: kano_combobox.py From kano-toolset with GNU General Public License v2.0 | 6 votes |
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)
Example #8
Source File: indicator.py From coinprice-indicator with MIT License | 6 votes |
def _menu_recents(self): recent_menu = Gtk.Menu() if len(self.coin.settings['recent']) == 0: return for recent in self.coin.settings['recent']: exchange = self.coin.find_exchange_by_code(recent.get('exchange', 'None')) asset_pair = exchange.find_asset_pair_by_code(recent.get('asset_pair', 'None')) base = asset_pair.get('base', 'None') quote = asset_pair.get('quote', 'None') tabs = "\t" * (floor(abs((len(exchange.get_name()) - 8)) / 4) + 1) # 1 tab for every 4 chars less than 8 recent_string = exchange.get_name()[0:8] + ":" + tabs + base + " - " + quote recent_item = Gtk.MenuItem(recent_string) recent_item.connect("activate", self._recent_change, base, quote, exchange) recent_menu.append(recent_item) recent_menu.show_all() return recent_menu
Example #9
Source File: __init__.py From zim-desktop-wiki with GNU General Public License v2.0 | 6 votes |
def gtk_get_menu_item(menu, id): '''Get a menu item from a C{Gtk.Menu} @param menu: a C{Gtk.Menu} @param id: either the menu item label or the stock id @returns: a C{Gtk.MenuItem} or C{None} ''' items = menu.get_children() ids = [i.get_property('label') for i in items] # Gtk.ImageMenuItems that have a stock id happen to use the # 'label' property to store it... assert id in ids, \ 'Menu item "%s" not found, we got:\n' % id \ + ''.join('- %s \n' % i for i in ids) i = ids.index(id) return items[i]
Example #10
Source File: YubiGuard.py From YubiGuard with GNU General Public License v3.0 | 6 votes |
def build_menu(self): menu = Gtk.Menu() item_unlock = Gtk.MenuItem('Unlock') item_unlock.connect('activate', self.unlock) menu.append(item_unlock) self.item_unlock = item_unlock self.item_unlock.set_sensitive(False) # default state item_help = Gtk.MenuItem('Help') item_help.connect('activate', self.open_help) menu.append(item_help) separator = Gtk.SeparatorMenuItem() menu.append(separator) item_quit = Gtk.MenuItem('Quit') item_quit.connect('activate', self.quit) menu.append(item_quit) menu.show_all() return menu
Example #11
Source File: popupmenu.py From autokey with GNU General Public License v3.0 | 6 votes |
def __addItemsToSelf(self, items, service, onDesktop): # Create phrase section if cm.ConfigManager.SETTINGS[cm.SORT_BY_USAGE_COUNT]: items.sort(key=lambda obj: obj.usageCount, reverse=True) else: items.sort(key=lambda obj: str(obj)) i = 1 for item in items: #if onDesktop: # menuItem = Gtk.MenuItem(item.get_description(service.lastStackState), False) #else: menuItem = Gtk.MenuItem(label=self.__getMnemonic(item.description, onDesktop)) menuItem.connect("activate", self.__itemSelected, item) menuItem.set_use_underline(True) self.append(menuItem)
Example #12
Source File: macro.py From autokey with GNU General Public License v3.0 | 6 votes |
def get_menu(self, callback, menu=None): if common.USING_QT: for macro in self.macros: menu.addAction(MacroAction(menu, macro, callback)) else: menu = Gtk.Menu() for macro in self.macros: menuItem = Gtk.MenuItem(macro.TITLE) menuItem.connect("activate", callback, macro) menu.append(menuItem) menu.show_all() return menu
Example #13
Source File: HtreePedigreeView.py From addons-source with GNU General Public License v2.0 | 6 votes |
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)
Example #14
Source File: alttoolbar_rb3compat.py From alternative-toolbar with GNU General Public License v3.0 | 6 votes |
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
Example #15
Source File: HtreePedigreeView.py From addons-source with GNU General Public License v2.0 | 6 votes |
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
Example #16
Source File: ParrentListSection.py From pychess with GNU General Public License v3.0 | 6 votes |
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)
Example #17
Source File: AppIndicator.py From battery-monitor with GNU General Public License v3.0 | 6 votes |
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
Example #18
Source File: taskview.py From gtg with GNU General Public License v3.0 | 6 votes |
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 = ""
Example #19
Source File: label.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
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
Example #20
Source File: TimelinePedigreeView.py From addons-source with GNU General Public License v2.0 | 6 votes |
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
Example #21
Source File: colors_list.py From oomox with GNU General Public License v3.0 | 5 votes |
def build_dropdown_menu(self): self.drop_down = Gtk.Menu() menu_items = [] menu_items.append([ Gtk.MenuItem(label=_("Replace all instances")), self.replace_all_instances ]) for item in menu_items: self.drop_down.append(item[0]) item[0].connect("activate", item[1]) self.drop_down.show_all() return self.drop_down
Example #22
Source File: hexdump_view.py From bokken with GNU General Public License v2.0 | 5 votes |
def hex_view_populate_popup(self, textview, popup): disassemble_item = Gtk.MenuItem('Disassemble') disassemble_item.connect('activate', self.disassemble_item_activate) separator = Gtk.SeparatorMenuItem() popup.prepend(separator) popup.prepend(disassemble_item) separator.show() disassemble_item.show()
Example #23
Source File: run.py From twitch-indicator with zlib License | 5 votes |
def add_streams_menu(self, streams): """Adds streams list to menu.""" # Remove live streams menu if already exists if (len(self.menuItems) > 4): self.menuItems.pop(2) self.menuItems.pop(1) # Create menu self.streams_menu = gtk.Menu() self.menuItems.insert(2, gtk.MenuItem("Live channels ({0})".format(len(streams)))) self.menuItems.insert(3, gtk.SeparatorMenuItem()) self.menuItems[2].set_submenu(self.streams_menu) # Order streams by alphabetical order self.streams_ordered = sorted(streams, key=lambda k: k["name"].lower()) for index, stream in enumerate(self.streams_ordered): self.streams_menu.append(gtk.MenuItem(stream["name"])) self.streams_menu.get_children()[index].connect('activate', self.open_link, stream["url"]) for i in self.streams_menu.get_children(): i.show() # Refresh all menu by removing and re-adding menu items for i in self.menu.get_children(): self.menu.remove(i) for i in self.menuItems: self.menu.append(i) self.menu.show_all()
Example #24
Source File: execution_history.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def append_string_to_menu(self, popup_menu, menu_item_string): final_string = menu_item_string if len(menu_item_string) > 2000: final_string = menu_item_string[:1000] + "\n...\n" + menu_item_string[-1000:] menu_item = Gtk.MenuItem(final_string) menu_item.set_sensitive(False) menu_item.show() popup_menu.append(menu_item)
Example #25
Source File: library_tree.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def get_menu_item_text(self, menu_item): assert isinstance(menu_item, Gtk.MenuItem) menu_box = menu_item.get_child() assert isinstance(menu_box, Gtk.Box) return menu_box.get_children()[1].get_text()
Example #26
Source File: applications.py From zim-desktop-wiki with GNU General Public License v2.0 | 5 votes |
def __init__(self, widget, file, mimetype=None): '''Constructor @param widget: parent widget, needed to pop dialogs correctly @param file: a L{File} object or URL @param mimetype: the mime-type of the application, if already known. Providing this arguments prevents redundant lookups of the type (which is slow). ''' GObject.GObject.__init__(self) self._window = widget.get_toplevel() self.file = file if mimetype is None: mimetype = get_mimetype(file) self.mimetype = mimetype manager = ApplicationManager() for entry in manager.list_applications(mimetype): item = DesktopEntryMenuItem(entry) self.append(item) item.connect('activate', self.on_activate) if not self.get_children(): item = Gtk.MenuItem.new_with_mnemonic(_('No Applications Found')) # T: message when no applications in "Open With" menu item.set_sensitive(False) self.append(item) self.append(Gtk.SeparatorMenuItem()) item = Gtk.MenuItem.new_with_mnemonic(self.CUSTOMIZE) item.connect('activate', self.on_activate_customize, mimetype) self.append(item)
Example #27
Source File: menu_bar.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def set_menu_item_icon(self, menu_item_name, uni_code=None): menu_item = self[menu_item_name] # do not touch e.g. CheckMenuItems, only Gtk.MenuItem if type(menu_item) == Gtk.MenuItem: set_icon_and_text_box_of_menu_item(menu_item, uni_code)
Example #28
Source File: label.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def create_menu_item(label_text="", icon_code=constants.BUTTON_COPY, callback=None, callback_args=(), accel_code=None, accel_group=None): menu_item = Gtk.MenuItem() menu_item.set_label(label_text) set_icon_and_text_box_of_menu_item(menu_item, icon_code) if callback is not None: menu_item.connect("activate", callback, *callback_args) if accel_code is not None and accel_group is not None: key, mod = Gtk.accelerator_parse(accel_code) menu_item.add_accelerator("activate", accel_group, key, mod, Gtk.AccelFlags.VISIBLE) return menu_item
Example #29
Source File: trayicon.py From networkmgr with BSD 3-Clause "New" or "Revised" License | 5 votes |
def wifiListMenu(self, wificard, cbssid, passes, cards): wiconncmenu = Gtk.Menu() avconnmenu = Gtk.MenuItem("Available Connections") avconnmenu.set_submenu(wiconncmenu) for bssid in cards[wificard]['info']: ssid = cards[wificard]['info'][bssid][0] sn = cards[wificard]['info'][bssid][4] caps = cards[wificard]['info'][bssid][6] if passes is True: if cbssid != bssid: menu_item = Gtk.ImageMenuItem(ssid) if caps == 'E' or caps == 'ES': menu_item.set_image(self.openwifi(sn)) menu_item.connect("activate", self.menu_click_open, ssid, bssid, wificard) else: menu_item.set_image(self.securewifi(sn)) menu_item.connect("activate", self.menu_click_lock, ssid, bssid, wificard) menu_item.show() wiconncmenu.append(menu_item) else: menu_item = Gtk.ImageMenuItem(ssid) if caps == 'E' or caps == 'ES': menu_item.set_image(self.openwifi(sn)) menu_item.connect("activate", self.menu_click_open, ssid, bssid, wificard) else: menu_item.set_image(self.securewifi(sn)) menu_item.connect("activate", self.menu_click_lock, ssid, bssid, wificard) menu_item.show() wiconncmenu.append(menu_item) self.menu.append(avconnmenu)
Example #30
Source File: alttoolbar_rb3compat.py From alternative-toolbar with GNU General Public License v3.0 | 5 votes |
def insert_menu_item(self, menubar, section_name, position, action): """ add a new menu item to the popup :param menubar: `str` is the name GtkMenu (or ignored for RB2.99+) :param section_name: `str` is the name of the section to add the item to (RB2.99+) :param position: `int` position to add to GtkMenu (ignored for RB2.99+) :param action: `Action` to associate with the menu item """ label = action.label if is_rb3(self.shell): app = self.shell.props.application item = Gio.MenuItem() action.associate_menuitem(item) item.set_label(label) if section_name not in self._rbmenu_items: self._rbmenu_items[section_name] = [] self._rbmenu_items[section_name].append(label) app.add_plugin_menu_item(section_name, label, item) else: item = Gtk.MenuItem(label=label) action.associate_menuitem(item) self._rbmenu_items[label] = item bar = self.get_menu_object(menubar) if position == -1: bar.append(item) else: bar.insert(item, position) bar.show_all() uim = self.shell.props.ui_manager uim.ensure_update() return item