def get_file_items(self, window, files): top_menuitem = FileManager.MenuItem( name='NewEmblemsMenuProvider::Gtk-emblems-top', label=_('Emblems'), tip=_('Set and unset emblems')) submenu = FileManager.Menu() top_menuitem.set_submenu(submenu) for sub, emblems in [("Standard", free_desktop_emblems), ("User", NewEmblemsMenuProvider.extra_emblems)]: if not emblems: continue sub_menuitem = FileManager.MenuItem( name='NewEmblemsMenuProvider::Gtk-emblems-' + sub, label=sub, tip=sub) emblems_menu = FileManager.Menu() sub_menuitem.set_submenu(emblems_menu) submenu.append_item(sub_menuitem) for e in emblems: display_name = NewEmblemsMenuProvider.emblem_names.get( e, e[len("emblem-"):]) # TODO: How do we get the emblem icon image, and how # do we attach it to the menu as item? emblem_item = FileManager.MenuItem( name='NewEmblemsMenuProvider::Gtk-emblems-sub-' + sub + '-' + e, label=display_name, tip=display_name) emblem_item.connect('activate', self.emblemize, files, e, window) emblems_menu.append_item(emblem_item) sub_menuitem_clear = FileManager.MenuItem( name='NewEmblemsMenuProvider::Gtk-emblems-clear', label='Clear', tip='Remove the emblem') sub_menuitem_clear.connect('activate', self.emblemize, files, None, window) submenu.append_item(sub_menuitem_clear) sub_menuitem_about = FileManager.MenuItem( name='NewEmblemsMenuProvider::Gtk-emblems-about', label=_('About'), tip=_('About')) sub_menuitem_about.connect('activate', self.about, window) submenu.append_item(sub_menuitem_about) return top_menuitem,
def get_file_items(self, window, sel_items): """ Adds the 'Replace in Filenames' menu item to the File Manager\ right-click menu, connects its 'activate' signal to the 'run'\ method passing the selected Directory/File """ top_menuitem = FileManager.MenuItem( name='ExtImagesODTFileMenuProvider::Gtk-extimaagesfodt-top', label=_('Extract images from LibreOffice files') + '...', tip=_('Tool to extract images from LibreOffice files')) submenu = FileManager.Menu() top_menuitem.set_submenu(submenu) sub_menuitem_00 = FileManager.MenuItem( name='ExtImagesODTFileMenuProvider::Gtk-extimaagesfodt-sub-00', label=_('Extract images from LibreOffice files'), tip=_('Tool to extract images from LibreOffice files')) if self.all_are_odt_files(sel_items): sub_menuitem_00.connect('activate', self.extractimages, sel_items, window) else: sub_menuitem_00.set_property('sensitive', False) submenu.append_item(sub_menuitem_00) sub_menuitem_02 = FileManager.MenuItem( name='ExtImagesODTFileMenuProvider::Gtk-extimaagesfodt-sub-02', label=_('About'), tip=_('About')) sub_menuitem_02.connect('activate', self.about, window) submenu.append_item(sub_menuitem_02) return top_menuitem,
def _buildMenu(self, menus): '''Build one level of a menu''' items = [] if self.files: passcwd = None else: #bg passcwd = self.cwd for menu_info in menus: idstr = '%s::%02d%s' % (idstr_prefix, self.pos, menu_info.hgcmd) self.pos += 1 if menu_info.isSep(): # can not insert a separator till now pass elif menu_info.isSubmenu(): if hasattr(Nautilus, 'Menu'): item = Nautilus.MenuItem(name=idstr, label=menu_info.menutext, tip=menu_info.helptext) submenu = Nautilus.Menu() item.set_submenu(submenu) for subitem in self._buildMenu(menu_info.get_menus()): submenu.append_item(subitem) items.append(item) else: #submenu not suported for subitem in self._buildMenu(menu_info.get_menus()): items.append(subitem) else: if menu_info.state: item = Nautilus.MenuItem.new(idstr, menu_info.menutext, menu_info.helptext, self.icon(menu_info.icon)) item.connect('activate', self.run_dialog, menu_info.hgcmd, passcwd) items.append(item) return items
def _generate_menu(self, file_items): """Generate the menu item and its submenu.""" possible_apps = [] self.files = file_items for item in file_items: item_type = item.get_mime_type() if len(possible_apps) == 0: possible_apps = Gio.AppInfo.get_all_for_type(item_type) else: possible_apps_new = Gio.AppInfo.get_all_for_type(item_type) possible_apps_common = [] for app in possible_apps: for app2 in possible_apps_new: if app.equal(app2): possible_apps_common.append(app) possible_apps = possible_apps_common menu = Nautilus.Menu() for app in possible_apps: menu.append_item(self.add_app_item(app, possible_apps.index(app))) menuitem = Nautilus.MenuItem(name='OpenWithMenu', label="Open With…") menuitem.set_submenu(menu) return menuitem, None
def get_file_items_full(self, provider, window, files): if self.get_mount_point() != -1: panbox_folder = 'file://' + self.get_mount_point() else: panbox_folder = PANBOX_FOLDER if any(urllib.unquote(file.get_uri()).startswith(panbox_folder) for file in files): files_to_string = [] for f in files: files_to_string.append(urllib.unquote(f.get_uri())) item_name = 'Panbox::Panbox' item_label = 'Panbox' item_icon = os.path.join(os.path.dirname(__file__), 'img/panbox-icon.png') menu = Nautilus.MenuItem(name=item_name, label=item_label, tip='', icon=item_icon) submenu = Nautilus.Menu() menu.set_submenu(submenu) file_path = urllib.unquote(f.get_uri()) if os.path.dirname(file_path) == panbox_folder: # Item item_name = 'Panbox::RemoveShare' if len(files) == 1: item_label = _('Remove Share') # item_label = 'Remove Share' else: item_label = _('Remove Shares') # item_label = 'Remove Shares' remove_share = Nautilus.MenuItem(name=item_name, label=item_label) submenu.append_item(remove_share) remove_share.connect('activate', self.remove_share) file = files[0].get_uri()[7:] # if len(files) == 1 and self.get_file_status(file) != 3 and self.get_file_status(file) != -1: share_name = file_path.replace(PANBOX_FOLDER, "").split("/")[1] share_type = self.get_share_storage_backend_type(share_name) if share_type == "Dropbox" and len(files) == 1: # Item item_name = 'Panbox::ShareFolder' item_label = _('Share Folder') # item_label = 'Share Folder' share_dir = Nautilus.MenuItem(name=item_name, label=item_label) submenu.append_item(share_dir) share_dir.connect('activate', self.share_directory, file_path[7:]) file = file_path[7:] if os.path.isfile(file) and len(files) == 1: share_name = file_path.replace(PANBOX_FOLDER, "").split("/")[1] share_type = self.get_share_storage_backend_type(share_name) if not share_type == "Directory": # Item item_name = 'Panbox::ShowRevs' item_label = _('Show Revisions') show_revs = Nautilus.MenuItem(name=item_name, label=item_label) submenu.append_item(show_revs) show_revs.connect('activate', self.open_restore_revision_gui, file_path[7:]) return menu, else: pass
def get_file_items(self, window, sel_items): """ Adds the 'Replace in Filenames' menu item to the File Manager\ right-click menu, connects its 'activate' signal to the 'run'\ method passing the selected Directory/File """ if self.all_are_files(sel_items): if len(sel_items) > 1: label = _('Email them') else: label = _('Email it') top_menuitem = FileManager.MenuItem( name='EmailItMenuProvider::Gtk-emailit-top', label=label + '...', tip=_('Email files directly')) submenu = FileManager.Menu() top_menuitem.set_submenu(submenu) sub_menuitem_00 = FileManager.MenuItem( name='EmailItMenuProvider::Gtk-emailit-sub-01', label=label, tip=_('Email files directly')) sub_menuitem_00.connect('activate', self.emailit, sel_items, window) submenu.append_item(sub_menuitem_00) sub_menuitem_01 = FileManager.MenuItem( name='EmailItMenuProvider::Gtk-emailit-sub-02', label=_('About'), tip=_('About')) sub_menuitem_01.connect('activate', self.about, window) submenu.append_item(sub_menuitem_01) # return top_menuitem, return
def get_background_items_full(self, provider, window, path): unquoted_path = urllib.unquote(path.get_uri()) if self.get_mount_point() != -1: panbox_folder = 'file://' + self.get_mount_point() else: panbox_folder = PANBOX_FOLDER if unquoted_path == panbox_folder or unquoted_path.startswith(panbox_folder + "/"): item_name = 'Panbox::Panbox' item_label = 'Panbox' menu = Nautilus.MenuItem(name=item_name, label=item_label) submenu = Nautilus.Menu() menu.set_submenu(submenu) if unquoted_path == panbox_folder: # Item item_name = 'Panbox::AddShare' item_label = _('Add Share') add_share = Nautilus.MenuItem(name=item_name, label=item_label) submenu.append_item(add_share) # Bind menu entries to functions add_share.connect('activate', self.add_share) return menu, else: pass
def get_file_items(self, window, sel_items): top_menuitem = FileManager.MenuItem( name='TelegramCliUploaderMenuProvider::Gtk-telegram-top', label=_('telegram...'), tip=_('Send files to telegram')) submenu = FileManager.Menu() top_menuitem.set_submenu(submenu) sub_menuitem_00 = FileManager.MenuItem( name='TelegramCliUploaderMenuProvider::Gtk-telegram-sub-00', label=_('Send...'), tip='Send files to telegram') sub_menuitem_00.connect('activate', self.send_files, sel_items, window) submenu.append_item(sub_menuitem_00) if self.all_files_are_files(sel_items) and \ os.path.exists(os.path.join(CONFIG_APP_DIR, 'auth')): sub_menuitem_00.set_property('sensitive', True) else: sub_menuitem_00.set_property('sensitive', False) sub_menuitem_02 = FileManager.MenuItem( name='TelegramCliUploaderMenuProvider::Gtk-telegram-sub-02', label=_('About'), tip=_('About')) sub_menuitem_02.connect('activate', self.about, window) submenu.append_item(sub_menuitem_02) return top_menuitem,
def get_background_items(self, window, file): submenu = Nautilus.Menu() createnew = Nautilus.MenuItem(name='ExampleMenuProvider::Foo', label='Create new ...', tip='', icon='') createnew.set_submenu(submenu) newfile = Nautilus.MenuItem(name='ExampleMenuProvider::Foo', label='Text file', tip='', icon='') newdoc = Nautilus.MenuItem(name='ExampleMenuProvider::Foo', label='LibreOffice document', tip='', icon='') newsheet = Nautilus.MenuItem(name='ExampleMenuProvider::Foo', label='LibreOffice spreadsheet', tip='', icon='') newpreso = Nautilus.MenuItem(name='ExampleMenuProvider::Foo', label='LibreOffice presentation', tip='', icon='') submenu.append_item(newfile) newfile.connect('activate', self.menu_create_text, window, file) if os.path.isfile("/usr/bin/libreoffice"): submenu.append_item(newdoc) submenu.append_item(newsheet) submenu.append_item(newpreso) newdoc.connect('activate', self.menu_create_odt, window, file) newsheet.connect('activate', self.menu_create_ods, window, file) newpreso.connect('activate', self.menu_create_odp, window, file) return createnew,
def get_file_items(self, window, sel_items): """ Adds the 'Replace in Filenames' menu item to the File Manager\ right-click menu, connects its 'activate' signal to the 'run'\ method passing the selected Directory/File """ if self.all_are_jpeg_files(sel_items): top_menuitem = FileManager.MenuItem( name='CompressJPGFileMenuProvider::Gtk-compressjpeg-top', label=_('Compress JPEG files') + '...', tip=_('Tool to compress jpeg')) submenu = FileManager.Menu() top_menuitem.set_submenu(submenu) sub_menuitem_00 = FileManager.MenuItem( name='CompressJPGFileMenuProvider::Gtk-compressjpeg-sub-00', label=_('Compress JPEG files'), tip=_('Tool to compress png files by reducing colors')) sub_menuitem_00.connect('activate', self.comprespng, sel_items, window) submenu.append_item(sub_menuitem_00) sub_menuitem_01 = FileManager.MenuItem( name='CompressJPGFileMenuProvider::Gtk-compressjpeg-sub-01', label=_('About'), tip=_('About')) sub_menuitem_01.connect('activate', self.about, window) submenu.append_item(sub_menuitem_01) return top_menuitem, return
def get_file_items(self, window, files): # variables strFiles = "" onlyPDF = True # check if array is only composed of PDF files for file in files: strFiles += file.get_uri() + " " if file.get_mime_type() not in ('application/pdf' 'application/x-pdf' 'application/x-bzpdf' 'application/x-gzpdf'): onlyPDF = False # if all files are images if onlyPDF == True: # create menu item for right click menu pdf_tools = Nautilus.MenuItem( name='PDFToolsMenuProvider::pdf_tools', label='PDF - Misc tools ...', icon='pdf-menu') submenu = Nautilus.Menu() pdf_tools.set_submenu(submenu) # create sub-menu item PDF Compress file = pathlib.Path("/usr/local/bin/pdf-compress") if file.exists(): pdf_compress = Nautilus.MenuItem( name='PDFToolsMenuProvider::pdf_compress', label='Compress scanned document', icon='pdf-compress') pdf_compress.connect('activate', self.pdf_compress, strFiles) submenu.append_item(pdf_compress) # create sub-menu item PDF Repair file = pathlib.Path("/usr/local/bin/pdf-repair") if file.exists(): # ghostscript method pdf_repair_ghost = Nautilus.MenuItem( name='PDFToolsMenuProvider::pdf_repair_ghost', label='Repair (Ghostscript)', icon='pdf-repair') pdf_repair_ghost.connect('activate', self.pdf_repair_ghost, strFiles) submenu.append_item(pdf_repair_ghost) # mutool method pdf_repair_mutool = Nautilus.MenuItem( name='PDFToolsMenuProvider::pdf_repair_mutool', label='Repair (MU Tool)', icon='pdf-repair') pdf_repair_mutool.connect('activate', self.pdf_repair_mutool, strFiles) submenu.append_item(pdf_repair_mutool) # return created menus return [pdf_tools] else: return
def get_file_items(self, window, files): # lightweight filter on file type and extension if not any(f.is_directory() or f.get_name().endswith(VIDEO_EXTENSIONS) for f in files): return # create subliminal menu subliminal_menuitem = Nautilus.MenuItem( name='SubliminalMenu::Subliminal', label='Subliminal') sub_menus = Nautilus.Menu() subliminal_menuitem.set_submenu(sub_menus) # create choose submenu on single file if len(files) == 1 and not files[0].is_directory(): choose_menuitem = Nautilus.MenuItem( name='SubliminalSubMenu::Choose', label=_('Choose subtitles')) choose_menuitem.connect('activate', self.choose_callback, files) sub_menus.append_item(choose_menuitem) # create download submenu download_menuitem = Nautilus.MenuItem( name='SubliminalSubMenu::Download', label=_('Download subtitles')) download_menuitem.connect('activate', self.download_callback, files) sub_menus.append_item(download_menuitem) # create configure submenu configure_menuitem = Nautilus.MenuItem( name='SubliminalSubMenu::Configure', label=_('Configure...')) configure_menuitem.connect('activate', self.config_callback) sub_menus.append_item(configure_menuitem) return subliminal_menuitem,
def get_background_items(self, window, file): current_directory = urllib.unquote(file.get_uri()[7:]) submenu = Nautilus.Menu() for item in os.listdir(self.template_folders_directory): if os.path.isdir(self.template_folders_directory + "/" + item): menu_item = Nautilus.MenuItem( name='NewFolderFromTemplate::Template', label=item, tip='', icon='') menu_item.connect("activate", self.button_clicked, item, current_directory) submenu.append_item(menu_item) menuitem = Nautilus.MenuItem( name='NewFolderFromTemplate::FolderTemplates', label='New Folder from Template', tip='', icon='') menuitem.set_submenu(submenu) return menuitem,
def get_file_items(self, window, sel_items): """ Adds the 'Replace in Filenames' menu item to the File Manager\ right-click menu, connects its 'activate' signal to the 'run'\ method passing the selected Directory/File """ if self.all_are_jpeg_files(sel_items): top_menuitem = FileManager.MenuItem( name='Images2dxfCreatorMenuProvider::Gtk-images2dxf-top', label=_('Create dxf from images'), tip=_('Tool to create a dxf from jpeg images')) submenu = FileManager.Menu() top_menuitem.set_submenu(submenu) sub_menuitem_00 = FileManager.MenuItem( name='Images2dxfCreatorMenuProvider::Gtk-images2dxf-sub-01', label=_('Create dxf'), tip=_('Tool to create a dxf from jpeg images')) sub_menuitem_00.connect('activate', self.convert, sel_items, window) submenu.append_item(sub_menuitem_00) sub_menuitem_01 = FileManager.MenuItem( name='Images2dxfCreatorMenuProvider::Gtk-images2dxf-sub-02', label=_('About'), tip=_('About')) sub_menuitem_01.connect('activate', self.about, window) submenu.append_item(sub_menuitem_01) # return top_menuitem, return
def get_file_items(self, window, sel_items): """ Adds the 'Replace in Filenames' menu item to the File Manager\ right-click menu, connects its 'activate' signal to the 'run'\ method passing the selected Directory/File """ if self.all_files_are_sounds(sel_items): top_menuitem = FileManager.MenuItem( name='GPXConverterMenuProvider::Gtk-convert2gpx-top', label=_('Convert to gpx'), tip=_('Tool to convert to gpx')) submenu = FileManager.Menu() top_menuitem.set_submenu(submenu) sub_menuitem_00 = FileManager.MenuItem( name='GPXConverterMenuProvider::Gtk-convert2gpx-sub-01', label=_('Convert'), tip=_('Tool to convert to gpx')) sub_menuitem_00.connect('activate', self.convert, sel_items, window) submenu.append_item(sub_menuitem_00) sub_menuitem_01 = FileManager.MenuItem( name='GPXConverterMenuProvider::Gtk-convert2gpx-sub-02', label=_('About'), tip=_('About')) sub_menuitem_01.connect('activate', self.about, window) submenu.append_item(sub_menuitem_01) # return top_menuitem, return
def legacy_menu_items(self, files): # No legacy menu for a selection of several files if len(files) != 1: return [] filename = files[0] entry = socketConnect.nautilusVFSFile_table.get(filename) if not entry: return [] # Currently 'sharable' also controls access to private link actions, # and we definitely don't want to show them for IGNORED. shareable = False state = entry['state'] state_ok = state.startswith('OK') state_sync = state.startswith('SYNC') isDir = os.path.isdir(filename + os.sep) if state_ok: shareable = True elif state_sync and isDir: # some file below is OK or SYNC for key, value in socketConnect.nautilusVFSFile_table.items(): if key != filename and key.startswith(filename): state = value['state'] if state.startswith('OK') or state.startswith('SYNC'): shareable = True break if not shareable: return [] # Set up the 'ownCloud...' submenu item_owncloud = Nautilus.MenuItem( name='IntegrationMenu', label=self.strings.get('CONTEXT_MENU_TITLE', appname)) menu = Nautilus.Menu() item_owncloud.set_submenu(menu) # Add share menu option item = Nautilus.MenuItem( name='NautilusPython::ShareItem', label=self.strings.get('SHARE_MENU_TITLE', 'Share...')) item.connect("activate", self.context_menu_action, 'SHARE', filename) menu.append_item(item) # Add permalink menu options, but hide these options for older clients # that don't have these actions. if 'COPY_PRIVATE_LINK_MENU_TITLE' in self.strings: item_copyprivatelink = Nautilus.MenuItem( name='CopyPrivateLink', label=self.strings.get('COPY_PRIVATE_LINK_MENU_TITLE', 'Copy private link to clipboard')) item_copyprivatelink.connect("activate", self.context_menu_action, 'COPY_PRIVATE_LINK', filename) menu.append_item(item_copyprivatelink) if 'EMAIL_PRIVATE_LINK_MENU_TITLE' in self.strings: item_emailprivatelink = Nautilus.MenuItem( name='EmailPrivateLink', label=self.strings.get('EMAIL_PRIVATE_LINK_MENU_TITLE', 'Send private link by email...')) item_emailprivatelink.connect("activate", self.context_menu_action, 'EMAIL_PRIVATE_LINK', filename) menu.append_item(item_emailprivatelink) return [item_owncloud]
def get_file_items(self, window, files): menuitem = Nautilus.MenuItem(name='OnionShare::Nautilus', label=self.label, tip='', icon='') menu = Nautilus.Menu() menu.append_item(menuitem) menuitem.connect("activate", self.menu_activate_cb, files) return menuitem,
def get_file_items(self, window, files): # Read files if len(files) != 1: return file = files[0] if file.is_directory() or file.get_uri_scheme() != 'file': return if not file.get_uri().lower().endswith(".tex"): return filepath = get_path(file) folderpath = os.path.dirname(filepath) # Top Menu top_menuitem = Nautilus.MenuItem(name='LatexExtension::Latex', label='LaTex', tip='', icon='') # Main Sub Menu top_submenu = Nautilus.Menu() # Menu Item: LaTex Compilation compile_menuitem = Nautilus.MenuItem(name='LatexExtension::Compile', label='Compile File', tip='', icon='') compile_menuitem.connect('activate', self.compile_menu_cb, filepath) # Sub Menu Item: Ĺatexmk latexmk_menuitem = Nautilus.MenuItem(name='LatexExtension::Latexmk', label='Latexmk', tip='', icon='') latexmk_menuitem.connect('activate', self.latexmk_menu_cb, folderpath) # Sub Menu Item: LaTex Cleanup cleanup_menuitem = Nautilus.MenuItem( name='LatexExtension::Cleanup', label='Cleanup temporary LaTex files', tip='', icon='') cleanup_menuitem.connect('activate', self.cleanup_menu_cb, folderpath) # Add menu items to main submenu top_submenu.append_item(cleanup_menuitem) top_submenu.append_item(latexmk_menuitem) top_submenu.append_item(compile_menuitem) # Add main submenu top_menuitem.set_submenu(top_submenu) return top_menuitem,
def ask_for_menu_items(self, files): record_separator = '\x1e' filesstring = record_separator.join(files) socketConnect.sendCommand('GET_MENU_ITEMS:{}\n'.format(filesstring)) done = False start = time.time() timeout = 0.1 # 100ms menu_items = [] while not done: dt = time.time() - start if dt >= timeout: break if not socketConnect.read_socket_data_with_timeout(timeout - dt): break for line in socketConnect.get_available_responses(): # Process lines we don't care about if done or not (line.startswith('GET_MENU_ITEMS:') or line.startswith('MENU_ITEM:')): socketConnect.handle_server_response(line) continue if line == 'GET_MENU_ITEMS:END': done = True # don't break - we'd discard other responses if line.startswith('MENU_ITEM:'): args = line.split(':') if len(args) < 4: continue menu_items.append( [args[1], 'd' not in args[2], ':'.join(args[3:])]) if not done: return self.legacy_menu_items(files) if len(menu_items) == 0: return [] # Set up the 'ownCloud...' submenu item_owncloud = Nautilus.MenuItem(name='IntegrationMenu', label=self.strings.get( 'CONTEXT_MENU_TITLE', appname)) menu = Nautilus.Menu() item_owncloud.set_submenu(menu) for action, enabled, label in menu_items: item = Nautilus.MenuItem(name=action, label=label, sensitive=enabled) item.connect("activate", self.context_menu_action, action, filesstring) menu.append_item(item) return [item_owncloud]
def get_file_items(self, window, files): """ args: files: a list of Nautilus.FileInfo,未选中文件时,len(files) = 0 """ top_menuitem = None if len(files) != 0 and self.inside(files[0].get_uri()[7:]): top_menuitem = Nautilus.MenuItem(name = 'Kuaipan::KuaipanMenu1', \ label = '快盘', \ tip = '', \ icon = '') submenu = Nautilus.Menu() top_menuitem.set_submenu(submenu) #sub_menutime 1 立即同步 sub_menuitem = Nautilus.MenuItem(name='Kuaipan::Sync', \ label = '立即同步', \ tip = '', \ icon = '') submenu.append_item(sub_menuitem) sub_menuitem.connect('activate', self.menu_cb_sync_file, files[0]) #事件与处理函数绑定 #sub_menutime 2 分享 sub_menuitem = Nautilus.MenuItem(name='Kuaipan::Share', \ label = '分享', \ tip = '', \ icon = '') submenu.append_item(sub_menuitem) sub_menuitem.connect('activate', self.menu_cb_share, files[0]) #事件与处理函数绑定 #sub_menutime 3 生成下载链接 sub_menuitem = Nautilus.MenuItem(name='Kuaipan::Link', \ label = '生成下载链接', \ tip = '', \ icon = '') submenu.append_item(sub_menuitem) sub_menuitem.connect('activate', self.menu_cb_generate_link, files[0]) #事件与处理函数绑定 #sub_menutime 4 查看修改历史 sub_menuitem = Nautilus.MenuItem(name='Kuaipan::FileHistory', \ label = '查看修改历史', \ tip = '', \ icon = '') submenu.append_item(sub_menuitem) sub_menuitem.connect('activate', self.menu_cb_show_history, files[0]) #事件与处理函数绑定 return top_menuitem,
def _generate_background_menu(self, items): top_background_menuitem = Nautilus.MenuItem(name='FolderCleanerMenu::Background', label=_("Sort Files")) background_submenu = Nautilus.Menu() top_background_menuitem.set_submenu(background_submenu) item = Nautilus.MenuItem(name="name3", label=_("By Type")) item.connect('activate', self.background_sort_by_type, items) background_submenu.append_item(item) item2 = Nautilus.MenuItem(name="name4", label=_("By Extension")) item2.connect('activate', self.background_sort_by_ext, items) background_submenu.append_item(item2) return top_background_menuitem,
def get_background_items(self, window, file): submenu = Nautilus.Menu() submenu.append_item( Nautilus.MenuItem(name='ExampleMenuProvider::Bar2', label='Bar2', tip='', icon='')) menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Foo2', label='Foo2', tip='', icon='') menuitem.set_submenu(submenu) return menuitem,
def get_file_items(self, window, files): top_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Foo', label='Foo', tip='', icon='') submenu = Nautilus.Menu() top_menuitem.set_submenu(submenu) sub_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::Bar', label='Bar', tip='', icon='') submenu.append_item(sub_menuitem) return top_menuitem,
def get_file_items(self, window, files): if self.coherence == None: return if len(files) == 0: return for file in files: if file.is_directory() or file.get_uri_scheme() != 'file': return #pin = self.coherence.get_pin('Nautilus::MediaServer::%d'%os.getpid()) #print 'Pin:',pin #if pin == 'Coherence::Pin::None': # return devices = self.coherence.get_devices(dbus_interface=BUS_NAME) i = 0 menuitem = None for device in devices: print device['friendly_name'], device['device_type'] if device['device_type'].split(':')[3] == 'MediaRenderer': if i == 0: menuitem = Nautilus.MenuItem( name='CoherencePlayExtension::Play', label='Play on MediaRenderer', tip= 'Play the selected file(s) on a DLNA/UPnP MediaRenderer', icon='media') submenu = Nautilus.Menu() menuitem.set_submenu(submenu) item = Nautilus.MenuItem( name='CoherencePlayExtension::Play%d' % i, label=device['friendly_name'], tip='') for service in device['services']: service_type = service.split('/')[-1] if service_type == 'AVTransport': item.connect('activate', self.play, service, device['path'], files) break submenu.append_item(item) i += 1 if i == 0: return return menuitem,
def get_file_items(self, window, files): jdfExtension = ".jdf" #os.system("echo 'Context Menu Activated' > /tmp/log_menu.log") #os.system("echo '"+str(Gio.FileType.REGULAR)+"' > /tmp/log_menu.log") for selectedFile in files: fileType = selectedFile.get_file_type() #os.system("echo 'Files received "+str(file_type)+" ' >> /tmp/log_menu.log") #os.system("echo 'Name "+str(selectedFile.get_name())+" ' >> /tmp/log_menu.log") filename, file_extension = os.path.splitext( str(selectedFile.get_name())) #os.system("echo 'filename "+str(filename)+" ' >> /tmp/log_menu.log") #os.system("echo 'file_extension "+str(file_extension)+" ' >> /tmp/log_menu.log") if str(fileType) == str( Gio.FileType.REGULAR) and file_extension == jdfExtension: submenu = Nautilus.Menu() sub_menuitem_execute = Nautilus.MenuItem( name='ArrebolMenuProvider::execute_jdf', label='Execute JDF', tip='', icon='') sub_menuitem_execute.connect('activate', self.menu_activate_execute, selectedFile) submenu.append_item(sub_menuitem_execute) #sub_menuitem_monitor = Nautilus.MenuItem(name='ArrebolMenuProvider::monitor_jdf', # label='Monitor JDF', # tip='', # icon='') #sub_menuitem_monitor.connect('activate', self.menu_activate_monitor, selectedFile) #submenu.append_item(sub_menuitem_monitor) top_menuitem = Nautilus.MenuItem( name='ArrebolMenuProvider::Arrebol', label='Arrebol', tip='', icon='') top_menuitem.set_submenu(submenu) return top_menuitem, else: return
def get_file_items(self, window, files): # create set of each mime type all_mimes = set() number_mimes = 0 mime_type = None for file in files: mime_type = file.get_mime_type() if mime_type not in all_mimes: number_mimes += 1 all_mimes.add(mime_type) # find group of read formats which contain all the mime types valid_group = None for key in READ_FORMATS.keys(): if all_mimes <= READ_FORMATS[key]: valid_group = key break # if no valid groups exit if not valid_group: return # if only one type of file selected, do not convert to same type again if number_mimes != 1: mime_type = None # create main menu called 'Convert to..' convert_menu = Nautilus.MenuItem(name='ExampleMenuProvider::ConvertTo', label='Convert to...', tip='', icon='') submenu1 = Nautilus.Menu() convert_menu.set_submenu(submenu1) # make submenu for write_format in WRITE_FORMATS[valid_group]: if mime_type not in write_format['mimes']: sub_menuitem = Nautilus.MenuItem(name='ExampleMenuProvider::' + write_format['name'], label=write_format['name'], tip='', icon='') sub_menuitem.connect('activate', self.on_click, files, write_format, valid_group) submenu1.append_item(sub_menuitem) return convert_menu,
def get_file_items(self, window, files): menu = self.new_menu() submenu = Nautilus.Menu() menu.set_submenu(submenu) vscodemenu = self.new_vscode_menu_item() vscodemenu.connect('activate', self.launch_vscode, files) ideamenu = self.new_idea_menu_item() ideamenu.connect('activate', self.launch_idea, files) submenu.append_item(vscodemenu) submenu.append_item(ideamenu) return [menu]
def get_background_items(self, window, current_folder): menu = self.new_menu() submenu = Nautilus.Menu() menu.set_submenu(submenu) vscodemenu = self.new_vscode_menu_item() vscodemenu.connect('activate', self.launch_vscode, [current_folder]) ideamenu = self.new_idea_menu_item() ideamenu.connect('activate', self.launch_idea, [current_folder]) submenu.append_item(vscodemenu) submenu.append_item(ideamenu) return [menu]
def get_background_items(self, window, file): self.window = window menuitem = Nautilus.MenuItem( name="TemplateMenuProvider::Templates", label=_("Templates"), tip="", icon="", ) submenu = Nautilus.Menu() item_odt = Nautilus.MenuItem(name="TemplateMenuProvider::ODT", label=_("New Document"), tip="", icon="") item_odt.connect("activate", self.create_odt, file) item_ods = Nautilus.MenuItem( name="TemplateMenuProvider::ODS", label=_("New Spreadsheet"), tip="", icon="", ) item_ods.connect("activate", self.create_ods, file) item_odp = Nautilus.MenuItem( name="TemplateMenuProvider::ODP", label=_("New Presentation"), tip="", icon="", ) item_odp.connect("activate", self.create_odp, file) item_txt = Nautilus.MenuItem(name="TemplateMenuProvider::TXT", label=_("New Textfile"), tip="", icon="") item_txt.connect("activate", self.create_txt, file) submenu.append_item(item_odt) submenu.append_item(item_ods) submenu.append_item(item_odp) submenu.append_item(item_txt) menuitem.set_submenu(submenu) return (menuitem, )
def get_file_items(self, window, files): """Return a list of select files to be sent""" # Try to get devices try: devices = self.get_reachable_devices() except Exception as e: raise Exception('Error while getting reachable devices') # No devices, don't show menu entry if not devices: return # Only accept regular files for uri in files: if uri.get_uri_scheme() != 'file' or uri.is_directory(): return # Do this elsewhere? self.init_gettext() # Context Menu Item menu = Nautilus.MenuItem( name='MConnectShareExtension::Devices', label=_('Send To Mobile Device'), icon='smartphone-symbolic' ) # Context Menu submenu = Nautilus.Menu() menu.set_submenu(submenu) # Context Submenu Items for device in devices: item = Nautilus.MenuItem( name='MConnectShareExtension::Device' + device['id'], label=device['name'], icon='smartphone-symbolic' ) item.connect('activate', self.send_files, files, device) submenu.append_item(item) return menu,