Python gi.repository.Gtk.SeparatorMenuItem() Examples

The following are 30 code examples of gi.repository.Gtk.SeparatorMenuItem(). 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: utility.py    From SafeEyes with GNU General Public License v3.0 6 votes vote down vote up
def create_gtk_builder(glade_file):
    """
    Create a Gtk builder and load the glade file.
    """
    builder = Gtk.Builder()
    builder.set_translation_domain('safeeyes')
    builder.add_from_file(glade_file)
    # Tranlslate all sub components
    for obj in builder.get_objects():
        if (not isinstance(obj, Gtk.SeparatorMenuItem)) and hasattr(obj, "get_label"):
            label = obj.get_label()
            if label is not None:
                obj.set_label(_(label))
        elif hasattr(obj, "get_title"):
            title = obj.get_title()
            if title is not None:
                obj.set_title(_(title))
    return builder 
Example #2
Source File: __init__.py    From zim-desktop-wiki with GNU General Public License v2.0 6 votes vote down vote up
def do_initialize_popup(self, menu):
		model, treeiter = self.get_selection().get_selected()
		if treeiter is None:
			popup_name, path = PAGE_ROOT_ACTIONS, None
		else:
			mytreeiter = model.get_user_data(treeiter)
			if mytreeiter.hint == IS_PAGE:
				popup_name = PAGE_EDIT_ACTIONS
				path = self.get_selected_path()
			else:
				popup_name, path = None, None

		if popup_name:
			uiactions = UIActions(
				self,
				self.notebook,
				path,
				self.navigation,
			)
			uiactions.populate_menu_with_actions(popup_name, menu)

		sep = Gtk.SeparatorMenuItem()
		menu.append(sep)
		self.populate_popup_expand_collapse(menu)
		menu.show_all() 
Example #3
Source File: YubiGuard.py    From YubiGuard with GNU General Public License v3.0 6 votes vote down vote up
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 #4
Source File: __init__.py    From pychess with GNU General Public License v3.0 6 votes vote down vote up
def set_perspective_menuitems(self, name, menuitems, default=True):
        perspective, button, index = self.perspectives[name]
        for item in perspective.menuitems:
            if item in self.viewmenu:
                self.viewmenu.remove(item)
        perspective.menuitems = []

        item = Gtk.SeparatorMenuItem()
        perspective.menuitems.append(item)
        self.viewmenu.append(item)
        item.show()
        for item in menuitems:
            perspective.menuitems.append(item)
            self.viewmenu.append(item)
            if default:
                item.set_active(True)
            item.show() 
Example #5
Source File: ParrentListSection.py    From pychess with GNU General Public License v3.0 6 votes vote down vote up
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 #6
Source File: gui.py    From zim-desktop-wiki with GNU General Public License v2.0 6 votes vote down vote up
def on_populate_popup(self, o, menu):
			sep = Gtk.SeparatorMenuItem()
			menu.append(sep)

			item = Gtk.CheckMenuItem(_('Show Tasks as Flat List'))
				# T: Checkbox in task list - hides parent items
			item.set_active(self.uistate['show_flatlist'])
			item.connect('toggled', self.on_show_flatlist_toggle)
			item.show_all()
			menu.append(item)

			item = Gtk.CheckMenuItem(_('Only Show Active Tasks'))
				# T: Checkbox in task list - this options hides tasks that are not yet started
			item.set_active(self.uistate['only_show_act'])
			item.connect('toggled', self.on_show_active_toggle)
			item.show_all()
			menu.append(item) 
Example #7
Source File: HtreePedigreeView.py    From addons-source with GNU General Public License v2.0 6 votes vote down vote up
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 #8
Source File: alttoolbar_rb3compat.py    From alternative-toolbar with GNU General Public License v3.0 6 votes vote down vote up
def insert_separator(self, menubar, at_position):
        """
        add a separator to the popup (only required for RB2.98 and earlier)
        :param menubar: `str` is the name GtkMenu (or ignored for RB2.99+)
        :param position: `int` position to add to GtkMenu (ignored for RB2.99+)
        """
        if not is_rb3(self.shell):
            menu_item = Gtk.SeparatorMenuItem().new()
            menu_item.set_visible(True)
            self._rbmenu_items['separator' + str(self._unique_num)] = menu_item
            self._unique_num = self._unique_num + 1
            bar = self.get_menu_object(menubar)
            bar.insert(menu_item, at_position)
            bar.show_all()
            uim = self.shell.props.ui_manager
            uim.ensure_update() 
Example #9
Source File: plugins.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #10
Source File: widgets.py    From zim-desktop-wiki with GNU General Public License v2.0 6 votes vote down vote up
def populate_popup_add_separator(menu, prepend=False):
	'''Convenience function that adds a C{Gtk.SeparatorMenuItem}
	to a context menu. Checks if the menu already contains items,
	if it is empty does nothing. Also if the menu already has a
	seperator in the required place this function does nothing.
	This helps with building menus more dynamically.
	@param menu: the C{Gtk.Menu} object for the popup
	@param prepend: if C{False} append, if C{True} prepend
	'''
	items = menu.get_children()
	if not items:
		pass # Nothing to do
	elif prepend:
		if not isinstance(items[0], Gtk.SeparatorMenuItem):
			sep = Gtk.SeparatorMenuItem()
			menu.prepend(sep)
	else:
		if not isinstance(items[-1], Gtk.SeparatorMenuItem):
			sep = Gtk.SeparatorMenuItem()
			menu.append(sep) 
Example #11
Source File: managers.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #12
Source File: pomodoro_indicator.py    From pomodoro-indicator with GNU General Public License v3.0 6 votes vote down vote up
def add2menu(menu, text=None, icon=None, conector_event=None,
             conector_action=None):
    if text is not None:
        menu_item = Gtk.ImageMenuItem.new_with_label(text)
        if icon:
            image = Gtk.Image.new_from_file(icon)
            menu_item.set_image(image)
            menu_item.set_always_show_image(True)
    else:
        if icon is None:
            menu_item = Gtk.SeparatorMenuItem()
        else:
            menu_item = Gtk.ImageMenuItem.new_from_file(icon)
            menu_item.set_always_show_image(True)
    if conector_event is not None and conector_action is not None:
        menu_item.connect(conector_event, conector_action)
    menu_item.show()
    menu.append(menu_item)
    return menu_item 
Example #13
Source File: trayicon.py    From zim-desktop-wiki with GNU General Public License v2.0 6 votes vote down vote up
def get_trayicon_menu(self):
		'''Returns the main 'tray icon menu'''
		menu = Gtk.Menu()

		item = Gtk.MenuItem.new_with_mnemonic(_('_Quick Note...')) # T: menu item in tray icon menu
		item.connect_object('activate', self.__class__.do_quick_note, self)
		menu.append(item)

		menu.append(Gtk.SeparatorMenuItem())

		notebooks = self.list_all_notebooks()
		self.populate_menu_with_notebooks(menu, notebooks)

		item = Gtk.MenuItem.new_with_mnemonic('  ' + _('_Other...'))  # Hack - using '  ' to indent visually
			# T: menu item in tray icon menu
		item.connect_object('activate', self.__class__.do_open_notebook, self)
		menu.append(item)

		menu.append(Gtk.SeparatorMenuItem())

		item = Gtk.MenuItem.new_with_mnemonic(_('_Quit')) # T: menu item in tray icon menu
		item.connect_object('activate', self.__class__.do_quit, self)
		menu.append(item)

		return menu 
Example #14
Source File: directory.py    From king-phisher-plugins with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_popup_menu(self):
		self._menu_items_req_selection = []
		self.popup_menu = Gtk.Menu.new()

		self.menu_item_transfer = Gtk.MenuItem.new_with_label(self.transfer_direction.title())
		self.popup_menu.append(self.menu_item_transfer)

		self.menu_item_edit = Gtk.MenuItem.new_with_label('Edit')
		self.popup_menu.append(self.menu_item_edit)

		menu_item = Gtk.MenuItem.new_with_label('Collapse All')
		menu_item.connect('activate', self.signal_menu_activate_collapse_all)
		self.popup_menu.append(menu_item)

		menu_item = Gtk.MenuItem.new_with_label('Set Working Directory')
		menu_item.connect('activate', self.signal_menu_activate_set_working_directory)
		self.popup_menu.append(menu_item)
		self._menu_items_req_selection.append(menu_item)

		menu_item = Gtk.MenuItem.new_with_label('Create Folder')
		menu_item.connect('activate', self.signal_menu_activate_create_folder)
		self.popup_menu.append(menu_item)

		menu_item = Gtk.MenuItem.new_with_label('Rename')
		menu_item.connect('activate', self.signal_menu_activate_rename)
		self.popup_menu.append(menu_item)
		self._menu_items_req_selection.append(menu_item)

		menu_item = Gtk.SeparatorMenuItem()
		self.popup_menu.append(menu_item)

		menu_item = Gtk.MenuItem.new_with_label('Delete')
		menu_item.connect('activate', self.signal_menu_activate_delete_prompt)
		self.popup_menu.append(menu_item)
		self._menu_items_req_selection.append(menu_item)

		self.popup_menu.show_all() 
Example #15
Source File: shell.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
def menu_setup(self):
        self.menu = Gtk.Menu()

        self.open_item = Gtk.MenuItem.new_with_label(base.STR_OPEN_FOLDER)
        self.open_item.connect("activate", self.on_open_folder)
        # self.open_item.show()
        self.open_webfront = Gtk.MenuItem.new_with_label(
            base.STR_OPEN_WEBFRONT)
        self.open_webfront.connect("activate", self.on_open_webfront)

        self.quit_item = Gtk.MenuItem.new_with_label(base.STR_EXIT)
        self.quit_item.connect("activate", self.quit)
        # self.quit_item.show()

        self.status_item = Gtk.MenuItem.new_with_label('Status')
        self.status_menu = self.create_status_menu()
        self.status_item.set_submenu(self.status_menu)
        self.notices_item = Gtk.MenuItem.new_with_label('Notices')

        self.notices_menu = Gtk.Menu()
        # self.notices_menu.append(Gtk.MenuItem.new_with_label('First notice'))
        self.notices_item.set_submenu(self.notices_menu)
        self.menu.append(self.open_webfront)
        self.menu.append(self.open_item)
        self.menu.append(Gtk.SeparatorMenuItem())
        self.menu.append(self.status_item)
        self.menu.append(Gtk.SeparatorMenuItem())
        self.menu.append(self.notices_item)
        self.menu.append(Gtk.SeparatorMenuItem())
        self.menu.append(self.quit_item)

        self.menu.show_all() 
Example #16
Source File: sourceview.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def on_populate_popup(self, view, menu):
		menu.prepend(Gtk.SeparatorMenuItem())

		def activate_linenumbers(item):
			self.buffer.set_show_line_numbers(item.get_active())

		item = Gtk.CheckMenuItem(_('Show Line Numbers'))
			# T: preference option for sourceview plugin
		item.set_active(self.buffer.object_attrib['linenumbers'])
		item.set_sensitive(self.view.get_editable())
		item.connect_after('activate', activate_linenumbers)
		menu.prepend(item)

		def activate_lang(item):
			self.buffer.set_language(item.zim_sourceview_languageid)

		item = Gtk.MenuItem.new_with_mnemonic(_('Syntax'))
		item.set_sensitive(self.view.get_editable())
		submenu = Gtk.Menu()
		for lang in sorted(LANGUAGES, key=lambda k: k.lower()):
			langitem = Gtk.MenuItem.new_with_mnemonic(lang)
			langitem.connect('activate', activate_lang)
			langitem.zim_sourceview_languageid = LANGUAGES[lang]
			submenu.append(langitem)
		item.set_submenu(submenu)
		menu.prepend(item)

		menu.show_all() 
Example #17
Source File: osx_menubar.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, plugin, window):
		MainWindowExtension.__init__(self, plugin, window)

		# Define OS X menu bar for this window and remove menubar from window
		self.menubar = self.window.menubar
		self.window._zim_window_main.remove(self.menubar) # XXX - use private arg, should patch Window.remove() instead ...

		# Define global items - one time action for process
		global _global_osx_application
		_global_osx_application.set_use_quartz_accelerators(False)

		quit = self.window.uimanager.get_widget('/menubar/file_menu/quit')
		quit.hide()

		_global_osx_application.set_menu_bar(self.menubar)
		help = self.window.uimanager.get_widget('/menubar/help_menu')
		_global_osx_application.set_help_menu(help)

		about = self.window.uimanager.get_widget('/menubar/help_menu/show_about')
		_global_osx_application.insert_app_menu_item(about, 0)

		prefs = self.window.uimanager.get_widget('/menubar/edit_menu/show_preferences')
		_global_osx_application.insert_app_menu_item(Gtk.SeparatorMenuItem(), 1)
		_global_osx_application.insert_app_menu_item(prefs, 2)
		_global_osx_application.insert_app_menu_item(Gtk.SeparatorMenuItem(), 3)

		_global_osx_application.ready() 
Example #18
Source File: coin.py    From coinprice-indicator with MIT License 5 votes vote down vote up
def _menu(self):
        menu = Gtk.Menu()

        self.add_item = Gtk.MenuItem.new_with_label("Add Ticker")
        self.discover_item = Gtk.MenuItem.new_with_label("Discover Assets")
        self.plugin_item = Gtk.MenuItem.new_with_label("Plugins" + u"\u2026")
        self.about_item = Gtk.MenuItem.new_with_label("About")
        self.quit_item = Gtk.MenuItem.new_with_label("Quit")

        self.add_item.connect("activate", self._add_ticker)
        self.discover_item.connect("activate", self._discover_assets)
        self.plugin_item.connect("activate", self._select_plugins)
        self.about_item.connect("activate", self._about)
        self.quit_item.connect("activate", self._quit_all)

        menu.append(self.add_item)
        menu.append(self.discover_item)
        menu.append(self.plugin_item)
        menu.append(self.about_item)
        menu.append(Gtk.SeparatorMenuItem())
        menu.append(self.quit_item)
        menu.show_all()

        return menu

    # Adds a ticker and starts it 
Example #19
Source File: run.py    From twitch-indicator with zlib License 5 votes vote down vote up
def abort_refresh(self, message, description):
    """Updates menu with failure state message."""
    # Remove previous message if already exists
    if (len(self.menuItems) > 4):
      self.menuItems.pop(2)
      self.menuItems.pop(1)

    self.menuItems.insert(2, gtk.MenuItem(message))
    self.menuItems.insert(3, gtk.SeparatorMenuItem())
    self.menuItems[2].set_sensitive(False)

    # Re-enable "Check now" button
    self.menuItems[0].set_sensitive(True)
    self.menuItems[0].set_label("Check now")

    # Refresh all 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()

    # Push notification
    Notify.init("image")
    self.n = Notify.Notification.new(message,
      description,
      "error"
    ).show() 
Example #20
Source File: console_textview.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
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() 
Example #21
Source File: searchable.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
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() 
Example #22
Source File: hexdump_view.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
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: IconWindow.py    From bcloud with GNU General Public License v3.0 5 votes vote down vote up
def popup_folder_menu(self, event):
        # create folder; upload files; reload; share; properties
        menu = Gtk.Menu()
        self.menu = menu
        
        new_folder_item = Gtk.MenuItem.new_with_label(_('New Folder'))
        new_folder_item.connect('activate', self.on_new_folder_activated)
        menu.append(new_folder_item)

        sep_item = Gtk.SeparatorMenuItem()
        menu.append(sep_item)
        upload_files_item = Gtk.MenuItem.new_with_label(_('Upload Files...'))
        upload_files_item.connect('activate', self.on_upload_files_activated)
        menu.append(upload_files_item)
        upload_folders_item = Gtk.MenuItem.new_with_label(
                _('Upload Folders...'))
        upload_folders_item.connect('activate',
                                    self.on_upload_folders_activated)
        menu.append(upload_folders_item)

        sep_item = Gtk.SeparatorMenuItem()
        menu.append(sep_item)
        reload_item = Gtk.MenuItem.new_with_label(_('Reload (F5)'))
        reload_item.connect('activate', self.on_reload_activated)
        menu.append(reload_item)

        sep_item = Gtk.SeparatorMenuItem()
        menu.append(sep_item)
        props_item = Gtk.MenuItem.new_with_label(_('Properties'))
        props_item.connect('activate', self.on_props_activated)
        menu.append(props_item)

        menu.show_all()
        menu.popup(None, None, None, None, event.button, event.time) 
Example #24
Source File: bookmarksbar.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def on_populate_popup(self, treeview, menu):
		'''Add 'Add Bookmark' option to the Index popup menu.'''
		path = treeview.get_selected_path()
		if path:
			item = Gtk.SeparatorMenuItem()
			menu.prepend(item)
			item = Gtk.MenuItem.new_with_mnemonic(_('Add Bookmark')) # T: menu item bookmark plugin
			page = self.window.notebook.get_page(path)
			item.connect('activate', lambda o: self.widget.add_new_page(page))
			menu.prepend(item)
			menu.show_all() 
Example #25
Source File: cric_indicator.py    From cricket-score-applet with GNU General Public License v3.0 5 votes vote down vote up
def create_scorecard_menu(self):
        self.scoreboardMenu = Gtk.Menu.new()
        descriptionItem = Gtk.MenuItem("This is desctiption item")
        scorecardItem = Gtk.MenuItem("This is sorecard")
        commentaryItem = Gtk.MenuItem("Commentary is Loading")
        quitItem = Gtk.MenuItem("Quit")
        aboutItem = Gtk.MenuItem("About")
        toogleItem = Gtk.MenuItem("Back to List")
        quitItem.connect("activate",quit_indicator)
        aboutItem.connect("activate",about)

        self.scoreboardMenu.append(descriptionItem)
        self.scoreboardMenu.append(Gtk.SeparatorMenuItem())

        self.scoreboardMenu.append(scorecardItem)
        self.scoreboardMenu.append(Gtk.SeparatorMenuItem())
        self.scoreboardMenu.append(commentaryItem)

        self.scoreboardMenu.append(Gtk.SeparatorMenuItem())
        self.scoreboardMenu.append(toogleItem)
        self.scoreboardMenu.append(aboutItem)
        self.scoreboardMenu.append(quitItem)
        descriptionItem.show()
        scorecardItem.show()
        commentaryItem.show()
        quitItem.show()
        #toogleItem.show()
        aboutItem.show()
        self.scoreboardMenu.get_children()[1].show()
        self.scoreboardMenu.get_children()[3].show()
        self.scoreboardMenu.get_children()[5].show() 
Example #26
Source File: applications.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
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: filebrowser.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def on_drag_data_received(self, iconview, dragcontext, x, y, selectiondata, info, time):
		assert selectiondata.get_target().name() in URI_TARGET_NAMES
		names = unpack_urilist(selectiondata.get_data())
		files = [LocalFile(uri) for uri in names if uri.startswith('file://')]
		action = dragcontext.get_selected_action()
		logger.debug('Drag received %s, %s', action, files)

		if action == Gdk.DragAction.MOVE:
			self._move_files(files)
		elif action == Gdk.DragAction.ASK:
			menu = Gtk.Menu()

			item = Gtk.MenuItem.new_with_mnemonic(_('_Move Here')) # T: popup menu action on drag-drop of a file
			item.connect('activate', lambda o: self._move_files(files))
			menu.append(item)

			item = Gtk.MenuItem.new_with_mnemonic(_('_Copy Here')) # T: popup menu action on drag-drop of a file
			item.connect('activate', lambda o: self._copy_files(files))
			menu.append(item)

			menu.append(Gtk.SeparatorMenuItem())
			item = Gtk.MenuItem.new_with_mnemonic(_('Cancel')) # T: popup menu action on drag-drop of a file
			# cancel action needs no action
			menu.append(item)

			menu.show_all()
			gtk_popup_at_pointer(menu)
		else:
			# Assume Gdk.DragAction.COPY or Gdk.DragAction.DEFAULT
			# on windows we get "0" which is not mapped to any action
			self._copy_files(files) 
Example #28
Source File: notification_area.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def __init_gtk(self):
        menu = Gtk.Menu()

        # add "new task"
        # FIXME test this label... is it needed? play with it a little
        menuItem = Gtk.MenuItem(label=_('Add New Task'))
        menuItem.connect('activate', self.__open_task)
        menu.append(menuItem)

        # Show Main Window
        show_browser = Gtk.MenuItem(label=_('Show Main Window'))
        show_browser.connect('activate', self.__show_browser)
        menu.append(show_browser)

        # separator (it's intended to be after show_all)
        # separator should be shown only when having tasks
        self.__task_separator = Gtk.SeparatorMenuItem()
        menu.append(self.__task_separator)
        menu_top_length = len(menu)

        menu.append(Gtk.SeparatorMenuItem())

        # quit item
        menuItem = Gtk.MenuItem(label=_('Quit'))
        menuItem.connect('activate', self.__view_manager.close_browser)
        menu.append(menuItem)

        menu.show_all()
        self.__task_separator.hide()

        self.__tasks_menu = SortedLimitedMenu(self.MAX_ITEMS,
                                              menu, menu_top_length)

        self._indicator.activate(self.__show_browser, menu) 
Example #29
Source File: mail.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def signal_textview_populate_popup(self, textview, menu):
		# create and populate the 'Insert' submenu
		menu = managers.MenuManager(menu)
		insert_submenu = menu.append_submenu('Insert')

		insert_submenu.append('Inline Image', self.signal_activate_popup_menu_insert_image)
		insert_submenu.append('Tracking Image Tag', self.signal_activate_popup_menu_insert, activate_args=('{{ tracking_dot_image_tag }}',))
		insert_submenu.append('Webserver URL', self.signal_activate_popup_menu_insert, activate_args=('{{ url.webserver }}',))

		# create and populate the 'Date & Time' submenu
		insert_datetime_submenu = insert_submenu.append_submenu('Date & Time')

		formats = [
			'%a %B %d, %Y',
			'%b %d, %y',
			'%m/%d/%y',
			None,
			'%I:%M %p',
			'%H:%M:%S'
		]
		dt_now = datetime.datetime.now()
		for fmt in formats:
			if fmt:
				insert_datetime_submenu.append(
					dt_now.strftime(fmt),
					self.signal_activate_popup_menu_insert,
					activate_args=("{{{{ time.local | strftime('{0}') }}}}".format(fmt),)
				)
			else:
				insert_datetime_submenu.append_item(Gtk.SeparatorMenuItem())
		return True 
Example #30
Source File: managers.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_popup_menu(self, handle_button_press=True):
		"""
		Create a :py:class:`Gtk.Menu` with entries for copying and optionally
		delete cell data from within the treeview. The delete option will only
		be available if a delete callback was previously set.

		:param bool handle_button_press: Whether or not to connect a handler for displaying the popup menu.
		:return: The populated popup menu.
		:rtype: :py:class:`Gtk.Menu`
		"""
		popup_copy_submenu = self.get_popup_copy_submenu()
		popup_menu = Gtk.Menu.new()
		menu_item = Gtk.MenuItem.new_with_label('Copy')
		menu_item.set_submenu(popup_copy_submenu)
		popup_menu.append(menu_item)
		self._menu_items['Copy'] = menu_item
		if self.cb_delete:
			menu_item = Gtk.SeparatorMenuItem()
			popup_menu.append(menu_item)
			menu_item = Gtk.MenuItem.new_with_label('Delete')
			menu_item.connect('activate', self.signal_activate_popup_menu_delete)
			popup_menu.append(menu_item)
			self._menu_items['Delete'] = menu_item
		popup_menu.show_all()
		if handle_button_press:
			self.treeview.connect('button-press-event', self.signal_button_pressed, popup_menu)
		return popup_menu