def update_model(self): self.model.clear() if len(self.types) > 1: app_dict = {} default_list = [] for type in self.types: def_app = gio.app_info_get_default_for_type(type, False) for appinfo in gio.app_info_get_all_for_type(type): appname = appinfo.get_name() if def_app.get_name() == appname and appname not in default_list: default_list.append(appname) if not app_dict.has_key(appname): app_dict[appname] = appinfo for appname, appinfo in app_dict.items(): applogo = icon.get_from_app(appinfo) iter = self.model.append() if len(default_list) == 1 and appname in default_list: enabled = True else: enabled = False self.model.set( iter, TYPE_EDIT_ENABLE, enabled, TYPE_EDIT_TYPE, "", TYPE_EDIT_APPINFO, appinfo, TYPE_EDIT_APPLOGO, applogo, TYPE_EDIT_APPNAME, appname, ) else: type = self.types[0] def_app = gio.app_info_get_default_for_type(type, False) for appinfo in gio.app_info_get_all_for_type(type): applogo = icon.get_from_app(appinfo) appname = appinfo.get_name() iter = self.model.append() self.model.set( iter, TYPE_EDIT_ENABLE, def_app.get_name() == appname, TYPE_EDIT_TYPE, type, TYPE_EDIT_APPINFO, appinfo, TYPE_EDIT_APPLOGO, applogo, TYPE_EDIT_APPNAME, appname, )
def getDefaultAppCommand(fpath): mime_type = gio.content_type_guess(fpath) try: app = gio.app_info_get_all_for_type(mime_type)[0] except IndexError: return return app.get_executable()
def get_action_menu(self, it): filename, mimetype = self.model_filter.get(it, model.COLUMN_NAME, model.COLUMN_MIMETYPE) filepath = os.path.join(self.last_visited, filename) gfile = gio.File(path=filepath) menu = gtk.Menu() menu.append(gtk.MenuItem('Open with...')) menu.append(gtk.SeparatorMenuItem()) for app_info in gio.app_info_get_all_for_type(mimetype): gicon = app_info.get_icon() if gicon: if hasattr(gicon, 'get_file'): name = gicon.get_file().get_path() else: name = gicon.get_names() icon = self.icon_finder.find_by_name(name) if gicon else '' if icon: img = gtk.Image() img.set_from_file(icon) menuitem = gtk.ImageMenuItem(gtk.STOCK_EXECUTE) menuitem.set_image(img) menuitem.set_label(app_info.get_name()) else: menuitem = gtk.MenuItem(app_info.get_name()) menuitem.appinfo = app_info menuitem.file = gfile menu.append(menuitem) return menu
def _load_applications(self): treestore = self.treeviewApplications.get_model() treestore.clear() self.added_applications = [] #self.interfacetype = 'text/xml' app_list = gio.app_info_get_default_for_type(self.interfacetype, False) row = self._load_application_group(_('Default application'), '', [app_list], treestore) app_list = gio.app_info_get_all_for_type(self.interfacetype) self._load_application_group(_('Recommended applications'), '', app_list, treestore) app_list = gio.app_info_get_all() self._load_application_group(_('Other applications'), '', app_list, treestore) self.treeviewApplications.set_model(treestore) #self.treeviewApplications.expand_all() try: self.treeviewApplications.expand_row((0,), False) except: pass
def generate_run_menu(self): fi = self.model[self.view.get_cursor()][2] cfile = self.current_folder.get_child(fi.get_name()) current_folder = self.current_folder.get_path() for info in gio.app_info_get_all_for_type(fi.get_content_type()): yield info.get_name(), info.get_id(), (self.launch_file, (info, cfile, current_folder))
def getDefaultAppCommand(fpath): import gio mime_type = gio.content_type_guess(fpath) try: app = gio.app_info_get_all_for_type(mime_type)[0] except IndexError: return return app.get_executable()
def __init__(self, filetype, apps=False): gtk.TreeView.__init__(self) self.set_rules_hint(True) #self.set_grid_lines(False) self.get_selection().set_mode(gtk.SELECTION_BROWSE) if apps: self.Apps_list = [i for i in gio.app_info_get_all_for_type(filetype) if i != gio.app_info_get_default_for_type(filetype, False)] else: self.Apps_list = [i for i in gio.app_info_get_all() if i != gio.app_info_get_default_for_type(filetype, False)]
def update_model(self): self.model.clear() if len(self.types) > 1: app_dict = {} default_list = [] for type in self.types: def_app = gio.app_info_get_default_for_type(type, False) for appinfo in gio.app_info_get_all_for_type(type): appname = appinfo.get_name() if def_app.get_name( ) == appname and appname not in default_list: default_list.append(appname) if not app_dict.has_key(appname): app_dict[appname] = appinfo for appname, appinfo in app_dict.items(): applogo = icon.get_from_app(appinfo) iter = self.model.append() if len(default_list) == 1 and appname in default_list: enabled = True else: enabled = False self.model.set(iter, TYPE_EDIT_ENABLE, enabled, TYPE_EDIT_TYPE, '', TYPE_EDIT_APPINFO, appinfo, TYPE_EDIT_APPLOGO, applogo, TYPE_EDIT_APPNAME, appname) else: type = self.types[0] def_app = gio.app_info_get_default_for_type(type, False) for appinfo in gio.app_info_get_all_for_type(type): applogo = icon.get_from_app(appinfo) appname = appinfo.get_name() iter = self.model.append() self.model.set(iter, TYPE_EDIT_ENABLE, def_app.get_name() == appname, TYPE_EDIT_TYPE, type, TYPE_EDIT_APPINFO, appinfo, TYPE_EDIT_APPLOGO, applogo, TYPE_EDIT_APPNAME, appname)
def get_launch(gioFile): ''' Определяет по типу какой программой открывать файл по умолчанию ''' temp = get_mime(gioFile.get_path(), True) if temp != None: list_apps = gio.app_info_get_all_for_type(temp) return list_apps[0] else: return None
def resolve_run_menu_entry(self, name): fi = self.model[self.view.get_cursor()][2] cfile = self.current_folder.get_child(fi.get_name()) current_folder = self.current_folder.get_path() for info in gio.app_info_get_all_for_type(fi.get_content_type()): if info.get_id() == name: return self.launch_file, (info, cfile, current_folder), info.get_name() return None, None
def get_launch_apps(path): ''' Определяет по типу какими програмамми можно открывать файл ''' mime_type = get_mime(path, True) print mime_type apps_list = gio.app_info_get_all_for_type(mime_type) ret_list = [] for i in apps_list: ret_list.append({'app_name':i.get_name(), 'desktop':i.get_id(), 'icon':i.get_icon().get_names()[0]}) return ret_list
def get_all_for_type(self, content_type): apps = gio.app_info_get_all_for_type(content_type) default_app = self.get_default_for_type(content_type) if default_app and default_app.get_id().startswith("userapp"): apps.remove(default_app) # get real default app = filter(lambda a: a.get_commandline().split(" ")[0] == default_app.get_commandline().split(" ")[0], apps) if app: apps.remove(app[0]) apps.insert(0, app[0]) return apps
def is_unregistered_mime(mimetype): """Returns True if the MIME type is known to be unregistered. If registered or unknown, conservatively returns False.""" try: import gio if 0 == len(gio.app_info_get_all_for_type(mimetype)): return True except: logger = logging.getLogger(__name__) logger.warning( 'error calling gio.app_info_get_all_for_type(%s)' % mimetype) return False
def is_unregistered_mime(mimetype): """Returns True if the MIME type is known to be unregistered. If registered or unknown, conservatively returns False.""" try: import gio if 0 == len(gio.app_info_get_all_for_type(mimetype)): return True except: logger = logging.getLogger(__name__) logger.warning('error calling gio.app_info_get_all_for_type(%s)' % mimetype) return False
def default_application_for_leaf(cls, leaf): content_attr = gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE gfile = gio.File(leaf.object) info = gfile.query_info(content_attr) content_type = info.get_attribute_string(content_attr) def_app = gio.app_info_get_default_for_type(content_type, False) if not def_app: apps_for_type = gio.app_info_get_all_for_type(content_type) raise NoDefaultApplicationError( _("No default application for %(file)s (%(type)s)") % {"file": unicode(leaf), "type": content_type} ) return def_app
def get_all_for_type(self, content_type): apps = gio.app_info_get_all_for_type(content_type) default_app = self.get_default_for_type(content_type) if default_app and default_app.get_id().startswith("userapp"): apps.remove(default_app) # get real default app = filter( lambda a: a.get_commandline().split(" ")[0] == default_app. get_commandline().split(" ")[0], apps) if app: apps.remove(app[0]) apps.insert(0, app[0]) return apps
def _get_popup_for_cell(self, row, col): col = self.get_model_index(col) model = self.get_model() data = model.on_get_value(row, col+len(self.description)-1) popup = gtk.Menu() if data != None: if not isinstance(data, buffer): item = gtk.MenuItem(_(u"Copy value to clipboard")) item.connect("activate", self.on_copy_value_to_clipboard, data) item.show() popup.append(item) sep = gtk.SeparatorMenuItem() sep.show() popup.append(sep) if isinstance(data, buffer) and HAVE_GIO: mime = gio.content_type_guess(None, data) item = gtk.MenuItem(_(u"Save as...")) item.connect("activate", self.on_save_blob, data, mime) item.show() popup.append(item) if mime: apps = gio.app_info_get_all_for_type(mime) if apps: default = gio.app_info_get_default_for_type(mime, False) if default is not None and default in apps: apps.remove(default) apps.insert(0, default) # make sure it's first item = gtk.MenuItem(_(u"Open with...")) smenu = gtk.Menu() item.set_submenu(smenu) item.show() popup.append(item) for app_info in apps: item = gtk.MenuItem(app_info.get_name()) item.connect("activate", self.on_open_blob, data, app_info, mime) item.show() smenu.append(item) else: item = gtk.MenuItem(_(u"View value")) item.connect("activate", self.on_view_data, data) item.show() popup.append(item) else: item = gtk.MenuItem(_(u"This cell contains a 'NULL' value.")) item.set_sensitive(False) item.show() popup.append(item) return popup
def _get_popup_for_cell(self, row, col): col = self.get_model_index(col) model = self.get_model() data = model.on_get_value(row, col + len(self.description) - 1) popup = gtk.Menu() if data != None: if not isinstance(data, buffer): item = gtk.MenuItem(_(u"Copy value to clipboard")) item.connect("activate", self.on_copy_value_to_clipboard, data) item.show() popup.append(item) sep = gtk.SeparatorMenuItem() sep.show() popup.append(sep) if isinstance(data, buffer) and HAVE_GIO: mime = gio.content_type_guess(None, data) item = gtk.MenuItem(_(u"Save as...")) item.connect("activate", self.on_save_blob, data, mime) item.show() popup.append(item) if mime: apps = gio.app_info_get_all_for_type(mime) if apps: default = gio.app_info_get_default_for_type( mime, False) if default is not None and default in apps: apps.remove(default) apps.insert(0, default) # make sure it's first item = gtk.MenuItem(_(u"Open with...")) smenu = gtk.Menu() item.set_submenu(smenu) item.show() popup.append(item) for app_info in apps: item = gtk.MenuItem(app_info.get_name()) item.connect("activate", self.on_open_blob, data, app_info, mime) item.show() smenu.append(item) else: item = gtk.MenuItem(_(u"View value")) item.connect("activate", self.on_view_data, data) item.show() popup.append(item) else: item = gtk.MenuItem(_(u"This cell contains a 'NULL' value.")) item.set_sensitive(False) item.show() popup.append(item) return popup
def default_application_for_leaf(cls, leaf): content_attr = gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE gfile = gio.File(leaf.object) info = gfile.query_info(content_attr) content_type = info.get_attribute_string(content_attr) def_app = gio.app_info_get_default_for_type(content_type, False) if not def_app: apps_for_type = gio.app_info_get_all_for_type(content_type) raise NoDefaultApplicationError( (_("No default application for %(file)s (%(type)s)") % { "file": unicode(leaf), "type": content_type }) + "\n" + _('Please use "%s"') % _("Set Default Application...")) return def_app
def __init__(self, filetype, apps=False): gtk.TreeView.__init__(self) self.set_rules_hint(True) #self.set_grid_lines(False) self.get_selection().set_mode(gtk.SELECTION_BROWSE) if apps: self.Apps_list = [ i for i in gio.app_info_get_all_for_type(filetype) if i != gio.app_info_get_default_for_type(filetype, False) ] else: self.Apps_list = [ i for i in gio.app_info_get_all() if i != gio.app_info_get_default_for_type(filetype, False) ]
def update_model(self): self.model.clear() def_app = gio.app_info_get_default_for_type(self.type, False) for appinfo in gio.app_info_get_all_for_type(self.type): applogo = get_icon_with_app(appinfo, 24) appname = appinfo.get_name() iter = self.model.append() self.model.set(iter, TYPE_EDIT_ENABLE, def_app.get_name() == appname, TYPE_EDIT_TYPE, self.type, TYPE_EDIT_APPINFO, appinfo, TYPE_EDIT_APPLOGO, applogo, TYPE_EDIT_APPNAME, appname)
def get_application_list_for_type(self, mime_type): """Get list of associated programs for specified type""" result = [] for app_info in gio.app_info_get_all_for_type(mime_type): application = ApplicationInfo( id=app_info.get_id(), name=app_info.get_name(), description=app_info.get_description(), executable=app_info.get_executable(), command_line=app_info.get_commandline(), icon=self.__get_icon(app_info.get_icon())) result.append(application) return result
def get_meta_info(filename): try: filetype = gio.content_type_guess(filename) info = gio.app_info_get_all_for_type(filetype) except: return False apps = [] for i in info: ret = {} ret['name'] = i.get_name() ret['description'] = i.get_description() ret['exec'] = i.get_executable() apps.append(ret) return apps
def right_clicl_callback(self): self.menu = gtk.Menu() elem = self.get_selected_element() if elem: apps = gio.app_info_get_all_for_type(elem[1].get_content_type()) self.apps_list = [] self.apps_execs = {} for app in apps: self.apps_list.append(app.get_name()) self.apps_execs[app.get_name()] = app.get_executable() + ' ' + '"' +elem[0].get_path() + '"' self.add_submenuitem(_("Open with"),_("Open with"),self.apps_list) self.add_submenuitem(_("Actions"), _("Actions"),[_('Copy'),_('Paste'),_('Delete')]) self.cp = "file://" + elem[0].get_path() self.add_menuitem("export", _("Save Theme")) self.add_default_menuitems()
def get_application_list_for_type(self, mime_type): """Get list of associated programs for specified type""" result = [] for app_info in gio.app_info_get_all_for_type(mime_type): application = ApplicationInfo( id = app_info.get_id(), name = app_info.get_name(), description = app_info.get_description(), executable = app_info.get_executable(), command_line = app_info.get_commandline(), icon = self.__get_icon(app_info.get_icon()) ) result.append(application) return result
def get_actions_for_file(fileleaf): acts = [RevealFile(), ] app_actions = [] default = None if fileleaf.is_dir(): acts.append(OpenTerminal()) default = OpenDirectory() elif fileleaf.is_valid(): gfile = gio.File(fileleaf.object) info = gfile.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) content_type = info.get_attribute_string(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) def_app = gio.app_info_get_default_for_type(content_type, False) def_key = def_app.get_id() if def_app else None apps_for_type = gio.app_info_get_all_for_type(content_type) apps = {} for info in apps_for_type: key = info.get_id() if key not in apps: try: is_default = (key == def_key) app = OpenWith(info, is_default) apps[key] = app except InvalidDataError: pass if def_key: if not def_key in apps: pretty.print_debug("No default found for %s, but found %s" % (fileleaf, apps)) else: app_actions.append(apps.pop(def_key)) # sort the non-default OpenWith actions open_with_sorted = utils.locale_sort(apps.values()) app_actions.extend(open_with_sorted) if fileleaf._is_executable(): acts.extend((Execute(), Execute(in_terminal=True))) elif app_actions: default = app_actions.pop(0) else: app_actions.append(Show()) if app_actions: acts.extend(app_actions) if default: acts.insert(0, default) return acts
def actions(self): actions = [] def app_info_to_action(action): return (lambda: action.launch([self.file_]), 'Open with ' + action.get_name(), action.get_icon()) default = gio.app_info_get_default_for_type(self.content_type(), not self.file_.is_native()) actions.append(app_info_to_action(default)) all_app_infos = [ai for ai in gio.app_info_get_all_for_type(self.content_type()) if ai != default] if len(all_app_infos) > 0: actions.append(Node.SEPARATOR) for ai in all_app_infos: if not self.file_.is_native() and not ai.supports_uris(): continue actions.append(app_info_to_action(ai)) return actions
def get_launch_apps(path): """ Определяет по типу какими програмамми можно открывать файл """ mime_type = get_mime(path, True) print mime_type apps_list = gio.app_info_get_all_for_type(mime_type) ret_list = [] for i in apps_list: name = i.get_name() if name: pass else: name = "" icon = i.get_icon() if icon: icon = icon.get_names()[0] else: icon = "" ret_list.append({"app_name": name, "desktop": i.get_id(), "icon": icon}) return ret_list
def is_broken_xdg_desktop(pathname): """Returns boolean whether the given XDG desktop entry file is broken. Reference: http://standards.freedesktop.org/desktop-entry-spec/latest/""" config = ConfigParser.RawConfigParser() config.read(pathname) if not config.has_section('Desktop Entry'): print "info: is_broken_xdg_menu: missing required section " \ "'Desktop Entry': '%s'" % (pathname) return True if not config.has_option('Desktop Entry', 'Type'): print "info: is_broken_xdg_menu: missing required option 'Type': '%s'" % ( pathname) return True file_type = config.get('Desktop Entry', 'Type').strip().lower() if 'link' == file_type: if not config.has_option('Desktop Entry', 'URL') and \ not config.has_option('Desktop Entry', 'URL[$e]'): print "info: is_broken_xdg_menu: missing required option 'URL': '%s'" % ( pathname) return True return False if 'mimetype' == file_type: if not config.has_option('Desktop Entry', 'MimeType'): print "info: is_broken_xdg_menu: missing required option 'MimeType': '%s'" % ( pathname) return True mimetype = config.get('Desktop Entry', 'MimeType').strip().lower() if HAVE_GIO and 0 == len(gio.app_info_get_all_for_type(mimetype)): print "info: is_broken_xdg_menu: MimeType '%s' not " \ "registered '%s'" % (mimetype, pathname) return True return False if 'application' != file_type: print "Warning: unhandled type '%s': file '%s'" % (file_type, pathname) return False if __is_broken_xdg_desktop_application(config, pathname): return True return False
def ButtonClick(self, index, event=0): """Callback when buttons are clicked""" # 0 Subfolder # 1 Application # 2 places, settings, back. # 3,4 Recents self.etype = self.L_Types[index] if event == 0: event_button = 1 else: if event.type == gtk.gdk.KEY_PRESS: event_button = 1 elif event.type == gtk.gdk.BUTTON_PRESS: event_button = event.button elif event.type == gtk.gdk.BUTTON_RELEASE: event_button = event.button if event_button == 1: if self.etype == 0: # Subfolder self.PrevMenu.append(self.Menu) if self.menuparser.has_matemenu: self.Menu = self.L_Paths[index] else: self.Menu = self.BaseMenu.getMenu(self.L_Paths[index]) self.ConstructMenu() elif self.etype == 1 or self.etype == 3 or self.etype == 4: # Application self.Launcher.Launch(self.L_Execs[index], self.etype) self.Restart("previous") return 1 elif self.etype == 2: # Menu special buttons places, settings, back. if self.L_Names[index] == _("Back"): try: self.Menu = self.PrevMenu.pop() except: self.Menu = self.BaseMenu = self.menuparser.CacheApplications if self.Menu == self.menuparser.CacheApplications: self.BaseMenu = self.Menu self.ConstructMenu() elif self.L_Names[index] == _("System"): self.PrevMenu.append(self.Menu) self.Restart("settings") elif self.L_Names[index] == _("Places"): self.PrevMenu.append(self.Menu) self.Restart("places") elif self.etype == 5 or self.etype == 6: # Items in the menu have changed self.Launcher.Launch(self.L_Execs[index], self.etype) elif self.etype == 7: # Properties of the menu have changed self.Launcher.Launch(self.L_Execs[index], self.etype) Globals.ReloadSettings() elif self.etype == 10: # Clear Recent self.recent_manager.purge_items() self.Restart("previous") elif event_button == 3: self.m = gtk.Menu() name = self.L_Names[index] favlist = backend.load_setting("favorites") try: thismenu = add_image_menuitem(self.m, self.L_Icons_menu[index], name, self.dummy, "1") except: return if zg and self.allgio is not None: self.recent_files = None self.most_used_files = None for z in self.allgio: if z.get_name() == name: desk = z.get_id() self.recent_files = zg.get_recent_for_app(desk, Globals.RI_numberofitems) self.most_used_files = zg.get_most_used_for_app(desk, Globals.RI_numberofitems) break if self.recent_files or self.most_used_files: self.menuitem = add_menuitem(self.m, "-") for files, menu_name in ( (self.recent_files, _("Recently Used")), (self.most_used_files, _("Most Used")), ): if files: self.submenu = gtk.Menu() menu_item = gtk.MenuItem(menu_name) menu_item.set_submenu(self.submenu) self.m.append(menu_item) menu_item.show() for ev in files: for subject in ev.get_subjects(): label = subject.text or subject.uri submenu_item = gtk.MenuItem(label, use_underline=False) self.submenu.append(submenu_item) # "activate" doesn't seem to work on sub menus # so "button-press-event" is used instead. submenu_item.connect("button-press-event", self.launch_item, subject.uri) submenu_item.show() if self.etype != 0 and name != _("Back"): if self.etype != 3: self.menuitem = add_menuitem(self.m, "-") self.menuitem = add_image_menuitem( self.m, gtk.STOCK_DIALOG_AUTHENTICATION, _("Open as Administrator"), self.runasadmin, name, self.L_Execs[index], self.L_Icons_menu[index], self.L_Types[index], ) else: def searchfolder(folder, me): dirs = os.listdir(folder) dirs.sort(key=str.upper) for item in dirs: if not item.startswith("."): if os.path.isdir(os.path.abspath(folder) + "/" + item): add_image_menuitem( me, gtk.STOCK_DIRECTORY, item, self.launch_item, '"' + os.path.abspath(folder.replace("file://", "")) + "/" + item + '"', ) else: submenu_item = gtk.MenuItem(item, use_underline=False) me.append(submenu_item) # "activate" doesn't seem to work on sub menus # so "button-press-event" is used instead. submenu_item.connect( "button-press-event", self.launch_item, '"' + os.path.abspath(folder) + "/" + item + '"', ) submenu_item.show() f = os.path.abspath(urllib.url2pathname(self.L_Execs[index]).replace("file://", "")) if os.path.exists(f): if os.path.isdir(f): self.submenu = gtk.Menu() thismenu.set_submenu(self.submenu) searchfolder(f, self.submenu) elif os.path.isfile(f): if isgio: add_menuitem(self.m, "-") self.openwith = add_image_menuitem(self.m, gtk.STOCK_OPEN, _("Open with")) Gfile = gio.File(f) tuble = [Gfile, Gfile.query_info("standard::*"), []] name = tuble[1].get_name() # ff = gio.file_parse_name(f) apps = gio.app_info_get_all_for_type(tuble[1].get_content_type()) self.submenu = gtk.Menu() self.openwith.set_submenu(self.submenu) for app in apps: self.menuitem = add_menuitem( self.submenu, app.get_name(), self.custom_launch, "'" + f + "'", app.get_executable(), ) if name == _("Trash"): self.menuitem = add_menuitem(self.m, "-") self.menuitem = add_image_menuitem(self.m, gtk.STOCK_CLEAR, _("Empty Trash"), self.emptytrash) if ( "%s::%s::%s::%s" % (name, self.L_Execs[index], self.L_Icons_menu[index], str(self.L_Types[index])) not in favlist ): self.menuitem = add_menuitem(self.m, "-") self.menuitem = add_image_menuitem( self.m, gtk.STOCK_ADD, _("Add to Favorites"), self.addfav, name, self.L_Execs[index], self.L_Icons_menu[index], self.L_Types[index], ) else: self.menuitem = add_menuitem(self.m, "-") self.menuitem = add_image_menuitem( self.m, gtk.STOCK_REMOVE, _("Remove from Favorites"), self.removefav, name, self.L_Execs[index], self.L_Icons_menu[index], self.L_Types[index], ) self.menuitem = add_menuitem(self.m, "-") self.menuitem = add_image_menuitem( self.m, gtk.STOCK_HOME, _("Create Desktop Shortcut"), self.addshort, name, self.L_Execs[index], self.L_Icons_menu[index], self.L_Types[index], ) self.menuitem = add_menuitem(self.m, "-") if ("%s.desktop" % name) in os.listdir(Globals.AutoStartDirectory): self.menuitem = add_image_menuitem( self.m, gtk.STOCK_REMOVE, _("Remove from System Startup"), self.remove_autostarter, name, self.L_Execs[index], self.L_Icons_menu[index], self.L_Types[index], ) else: self.menuitem = add_image_menuitem( self.m, gtk.STOCK_ADD, _("Add to System Startup"), self.create_autostarter, name, self.L_Execs[index], self.L_Icons_menu[index], self.L_Types[index], ) self.m.show_all() self.m.popup(None, None, None, event.button, event.time) self.submenu = None self.menuitem = None gc.collect()
# If we have a directory only return one action if isdir(path): return [CopyToClipboardAction(_("Location"), gfile.get_path())] try: fileinfo = gfile.query_info("standard::content-type") except Exception, msg: LOGGER.error("Could not retrieve content type of %s: %s", gfile.get_path(), msg) return [] actions = [] default_appinfo = gio.app_info_get_default_for_type( fileinfo.get_content_type(), True) for appinfo in gio.app_info_get_all_for_type(fileinfo.get_content_type()): if default_appinfo == None \ or appinfo.get_executable() != default_appinfo.get_executable(): cmd = appinfo.get_executable() args = [gfile.get_path()] cmd_args = cmd.split(" ") if len(cmd_args) > 0: cmd = cmd_args[0] args = cmd_args[1:] + args actions.append( OpenWithApplicationAction( display_name, cmd, args,
def get_apps_for_type(mimetype): return gio.app_info_get_all_for_type(mimetype)
return [] # If we have a directory only return one action if isdir(path): return [CopyToClipboardAction( _("Location"), gfile.get_path())] try: fileinfo = gfile.query_info("standard::content-type") except Exception, msg: LOGGER.error("Could not retrieve content type of %s: %s", gfile.get_path(), msg) return [] actions = [] default_appinfo = gio.app_info_get_default_for_type(fileinfo.get_content_type(), True) for appinfo in gio.app_info_get_all_for_type(fileinfo.get_content_type()): if default_appinfo == None \ or appinfo.get_executable() != default_appinfo.get_executable(): cmd = appinfo.get_executable() args = [gfile.get_path ()] cmd_args = cmd.split(" ") if len(cmd_args) > 0: cmd = cmd_args[0] args = cmd_args[1:] + args actions.append( OpenWithApplicationAction(display_name, cmd, args, display_program_name=appinfo.get_name()) ) actions.append( GoToLocationAction(display_name, gfile.get_uri ()) ) actions.append( SendFileViaEmailAction(display_name, gfile.get_uri ()) )
def app_info_get_all_for_type(itype): return gio.app_info_get_all_for_type(itype)
def app_info_get_all_for_type(itype): return gio.app_info_get_all_for_type(itype)