def launch_selected(self, mdl, it): #{{{ t = mdl.get_value(it, model.COLUMN_TYPE) if mdl is self.apps_model.get_model(): id = mdl.get_value(it, model.COLUMN_ID) item = self.apps_model.data[id] if t == model.TYPE_APP: self.execute_command(item['command']) elif t == model.TYPE_DIR: self.execute_command(item['command']) elif t == model.TYPE_FILE: appinfo = gio.app_info_get_default_for_type( item['mimetype'], False) if appinfo: appinfo.launch_uris([item['url']], None) elif t == model.TYPE_CMD: pass elif mdl is self.fs_model.get_model(): name, mimetype = mdl.get(it, model.COLUMN_NAME, model.COLUMN_MIMETYPE) path = self.fs_model.last_visited filepath = os.path.join(path, name) appinfo = gio.app_info_get_default_for_type(mimetype, False) gfile = gio.File(filepath) if appinfo: appinfo.launch([gfile], None)
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 __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, filter=False, all=False): self.model.clear() mainwindow = self.get_toplevel().window if mainwindow: mainwindow.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) while gtk.events_pending(): gtk.main_iteration() for type in gio.content_types_get_registered(): if filter and filter != type.split('/')[0]: continue pixbuf = icon.get_from_mime_type(type) description = gio.content_type_get_description(type) app = gio.app_info_get_default_for_type(type, False) if app: appname = app.get_name() applogo = icon.get_from_app(app) elif all and not app: appname = _('None') applogo = None else: continue iter = self.model.append() self.model.set(iter, TYPE_MIME, type, TYPE_ICON, pixbuf, TYPE_DESCRIPTION, description, TYPE_APPICON, applogo, TYPE_APP, appname) if mainwindow: mainwindow.set_cursor(None)
def update_model(self, filter = False, all = False): self.model.clear() mainwindow = self.get_toplevel().window if mainwindow: mainwindow.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) for type in gio.content_types_get_registered(): while gtk.events_pending (): gtk.main_iteration () if filter and filter != type.split('/')[0]: continue pixbuf = mime_type_get_icon(type, 24) description = gio.content_type_get_description(type) app = gio.app_info_get_default_for_type(type, False) if app: appname = app.get_name() applogo = get_icon_with_app(app, 24) elif all and not app: appname = _('None') applogo = None else: continue iter = self.model.append() self.model.set(iter, TYPE_MIME, type, TYPE_ICON, pixbuf, TYPE_DESCRIPTION, description, TYPE_APPICON, applogo, TYPE_APP, appname) if mainwindow: mainwindow.set_cursor(None)
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 on_item_activated(self, view, path): """Open selected items in a view.""" store = view.get_model() # If the same viewer is associated to multiple types, then merge the # associated URIs to be launched. # # This code is convoluted because the gtk.AppInfo type is not hashable. app_on_uris = [] for p in view.get_selected_items(): uri = store[p].uri mime = gio.content_type_guess(uri) app = gio.app_info_get_default_for_type(mime, True) l_apps = map(lambda x: x[0], app_on_uris) if app in l_apps: idx = l_apps.index(app) app_on_uris[idx][1].add(mime) app_on_uris[idx][2].append(uri) else: app_on_uris.append((app, set(mime), [uri,])) # Launch the associated viewers for all items. for app, mime, uris in app_on_uris: if app: if not app.launch_uris(uris): self.alert("Couldn't launch %s." % app.get_name()) else: self.alert("No associated viewer for type '%s'." % mime)
def finish_initializing(self, builder, interface, execute_callback): """Called when we're finished initializing. finish_initalizing should be called after parsing the ui definition and creating a ActionSelectorDialog object with it in order to finish initializing the start of the new ActionSelectorDialog instance. """ self.treeviewApplications = builder.get_object('treeviewApplications') self.lblDescription = builder.get_object('lblDescription') self.chkDefaultApplication = builder.get_object('chkDefaultApplication') self.btnSelect = builder.get_object('btnSelect') self.btnCancel = builder.get_object('btnCancel') # Get a reference to the builder and set up the signals. self.builder = builder self.interface = interface self.interfacetype = self.interface.get_interface_class().get_interface_type() self.default_app = gio.app_info_get_default_for_type(self.interfacetype, True) self.added_applications = [] self.selected_app = None self.builder.connect_signals(self) if type(execute_callback) == types.FunctionType or type(execute_callback) == types.MethodType: self.connect('execute-application', execute_callback) self._translate() self._init_treeview() self._load_applications() self.show()
def __init__(self, message, name, mimetype, coding, key): self.message = message extension = mimetypes.guess_extension(mimetype) or "" self.name = mail.decode(name) if name else _("Untitled") + extension part_folder = gio.File(config.get("path", "part")) path = part_folder.get_path() folder = key filename = os.path.join(path, folder, self.name) exists = os.path.exists(filename) self.file = gio.File(filename) if not exists: self.file.replace_contents(self.message.encode(coding), None, False) if mimetype == "application/octet-stream": self.mimetype = self.file.query_info("*").get_content_type() else: self.mimetype = mimetype self.app = gio.app_info_get_default_for_type(self.mimetype, False) if self.app: self.icon_name = self.app.get_icon().get_names()[0] else: self.icon_name = None
def on_item_activated(self, view, path): """Open selected items in a view.""" store = view.get_model() # If the same viewer is associated to multiple types, then merge the # associated URIs to be launched. # # This code is convoluted because the gtk.AppInfo type is not hashable. app_on_uris = [] for p in view.get_selected_items(): uri = store[p].uri mime = gio.content_type_guess(uri) app = gio.app_info_get_default_for_type(mime, True) l_apps = map(lambda x: x[0], app_on_uris) if app in l_apps: idx = l_apps.index(app) app_on_uris[idx][1].add(mime) app_on_uris[idx][2].append(uri) else: app_on_uris.append((app, set(mime), [ uri, ])) # Launch the associated viewers for all items. for app, mime, uris in app_on_uris: if app: if not app.launch_uris(uris): self.alert("Couldn't launch %s." % app.get_name()) else: self.alert("No associated viewer for type '%s'." % mime)
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 icon_item_double_click(self, x, y): ''' Handle double click event. ''' app_info = gio.app_info_get_default_for_type(self.gfile.query_info("standard::content-type").get_content_type(), False) if app_info: app_info.launch([self.gfile], None) else: print "Don't know how to open file: %s" % (self.name)
def _prefill_spreadsheet(self): app_info = gio.app_info_get_default_for_type( 'application/vnd.ms-excel', False) options = [(_("Ask (default)"), None)] if app_info: options.append((_("Open with %s") % app_info.get_name(), 'open')) options.append((_("Save to disk"), 'save')) self.spreadsheet.prefill(options)
def _prefill_spreadsheet(self): app_info = gio.app_info_get_default_for_type( 'application/vnd.ms-excel', False) options = [(_("Ask (default)"), None)] if app_info: options.append((_("Open with %s") % app_info.get_name(), 'open')) options.append((_("Save to disk"), 'save')) self.spreadsheet.prefill(options)
def on_button_pressed(self, treeview, event): if event.type == gtk.gdk._2BUTTON_PRESS: x = int(event.x) y = int(event.y) time = event.time pthinfo = treeview.get_path_at_pos(x, y) if pthinfo is not None: path, col, cellx, celly = pthinfo if col == self.get_columns()[0]: return col = self.get_model_index(col) model = self.get_model() data = model.on_get_value(path[0], col + len(self.description) - 1) if data == None: return if not isinstance(data, buffer): self.on_view_data(None, data) elif isinstance(data, buffer) and HAVE_GIO: mime = gio.content_type_guess(None, data) default = gio.app_info_get_default_for_type(mime, False) if default is not None: self.on_open_blob(None, data, default, mime) elif event.button == 3: x = int(event.x) y = int(event.y) time = event.time pthinfo = treeview.get_path_at_pos(x, y) if pthinfo is not None: path, col, cellx, celly = pthinfo if col == self.get_columns()[0]: return self.select_cell(path[0], col, not self.cell_is_selected(path[0], col)) treeview.grab_focus() treeview.set_cursor(path, col, 0) popup = self._get_popup_for_cell(path[0], col) if not popup: return popup.popup(None, None, None, event.button, time) elif event.button == 1: x = int(event.x) y = int(event.y) pthinfo = treeview.get_path_at_pos(x, y) if not pthinfo: return path, col, cellx, celly = pthinfo if col == self.get_columns()[0]: self.select_row(path[0], not self.row_is_selected(path[0])) else: self.select_cell(path[0], col, not self.cell_is_selected(path[0], col))
def get_command_for_type(mime): try: return gio.app_info_get_default_for_type('text/plain', False).get_executable() except: if os.path.exists('/usr/bin/gedit'): return 'gedit' elif os.path.exists('/usr/bin/leafpad'): return 'leafpad' elif os.path.exists('/usr/bin/gvim'): return 'gvim' else: return None
def icon_item_double_click(self, x, y): ''' Handle double click event. ''' app_info = gio.app_info_get_default_for_type( self.gfile.query_info("standard::content-type").get_content_type(), False) if app_info: app_info.launch([self.gfile], None) else: print "Don't know how to open file: %s" % (self.name)
def launchApplicationByUrl(url, mimeType): """Launches an application in the background for displaying a url which is of a specific mimeType @param url: the url to display @param mimeType: the mime type of the content """ try: import gnomevfs except ImportError: gnomevfs = None try: from win32com.shell import shell as win32shell except ImportError: win32shell = None try: import gio except ImportError: gio = None if gio: app = gio.app_info_get_default_for_type(mimeType, True) if not app: return args = '%s %s' % (app.get_executable(), url) executable = None shell = True elif gnomevfs: app = gnomevfs.mime_get_default_application(mimeType) if not app: return args = '%s %s' % (app[2], url) executable = None shell = True elif win32shell: assoc = win32shell.AssocCreate() ext = _EXTENSIONS.get(mimeType) if ext is None: return assoc.Init(0, '.' + ext) args = assoc.GetString(0, _ASSOCSTR_COMMAND) executable = assoc.GetString(0, _ASSOCSTR_EXECUTABLE) args = args.replace("%1", url) args = args.replace("%L", url) shell = False else: return import subprocess subprocess.Popen(args, executable=executable, shell=shell)
def on_button_pressed(self, treeview, event): if event.type == gtk.gdk._2BUTTON_PRESS: x = int(event.x) y = int(event.y) time = event.time pthinfo = treeview.get_path_at_pos(x, y) if pthinfo is not None: path, col, cellx, celly = pthinfo if col == self.get_columns()[0]: return col = self.get_model_index(col) model = self.get_model() data = model.on_get_value(path[0], col+len(self.description)-1) if data == None: return if not isinstance(data, buffer): self.on_view_data(None, data) elif isinstance(data, buffer) and HAVE_GIO: mime = gio.content_type_guess(None, data) default = gio.app_info_get_default_for_type(mime, False) if default is not None: self.on_open_blob(None, data, default, mime) elif event.button == 3: x = int(event.x) y = int(event.y) time = event.time pthinfo = treeview.get_path_at_pos(x, y) if pthinfo is not None: path, col, cellx, celly = pthinfo if col == self.get_columns()[0]: return self.select_cell(path[0], col, not self.cell_is_selected(path[0], col)) treeview.grab_focus() treeview.set_cursor( path, col, 0) popup = self._get_popup_for_cell(path[0], col) if not popup: return popup.popup( None, None, None, event.button, time) elif event.button == 1: x = int(event.x) y = int(event.y) pthinfo = treeview.get_path_at_pos(x, y) if not pthinfo: return path, col, cellx, celly = pthinfo if col == self.get_columns()[0]: self.select_row(path[0], not self.row_is_selected(path[0])) else: self.select_cell(path[0], col, not self.cell_is_selected(path[0], col))
def open_with(path): context = gtk.gdk.AppLaunchContext() path = os.path.abspath(path) if os.path.isdir(path): path += "/" mime_type = gio.content_type_guess(path) app_info = gio.app_info_get_default_for_type(mime_type, False) if app_info != None: app_info.launch([gio.File(path)], context) else: sys.stderr.write('no application related to "%s"\n' % mime_type)
def __init__(self, store, model, sellable=None, visual_mode=False): self.image_model = model self._updating_widgets = False self._sellable = sellable BaseEditorSlave.__init__(self, store, model, visual_mode) self._setup_thumbnail() self._setup_widgets() self._app_info = gio.app_info_get_default_for_type('image/png', False) if not self._app_info: # Hide view item if we don't have any app to visualize it. self.view_item.hide()
def on_item_activated(self, view, path): row = self.model[path] fi = row[2] cfile = self.current_folder.get_child(fi.get_name()) ft = fi.get_file_type() if ft == gio.FILE_TYPE_REGULAR: if not self.process_archive(cfile, fi): app_info = gio.app_info_get_default_for_type(fi.get_content_type(), False) if app_info: os.chdir(self.current_folder.get_path()) app_info.launch([cfile]) else: self.set_uri(cfile.get_uri())
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 _on_open_button__clicked(self, widget): assert self.attachment assert self.attachment.blob name = '%s-%s' % ('stoq-attachment', self.attachment.get_description()) with tempfile.NamedTemporaryFile(suffix=name, delete=False) as f: filename = f.name f.write(self.attachment.blob) gfile = gio.File(path=filename) app_info = gio.app_info_get_default_for_type( self.attachment.mimetype, False) app_info.launch([gfile])
def do_update_for_type(self, model, path, iter, type): this_type = model.get_value(iter, TYPE_MIME) if this_type == type: app = gio.app_info_get_default_for_type(type, False) if app: appname = app.get_name() applogo = icon.get_from_app(app) model.set(iter, TYPE_APPICON, applogo, TYPE_APP, appname) else: model.set(iter, TYPE_APPICON, None, TYPE_APP, _('None'))
def _on_open_button__clicked(self, widget): assert self.attachment assert self.attachment.blob name = '%s-%s' % ('stoq-attachment', self.attachment.get_description()) with tempfile.NamedTemporaryFile(suffix=name, delete=False) as f: filename = f.name f.write(self.attachment.blob) gfile = gio.File(path=filename) app_info = gio.app_info_get_default_for_type( self.attachment.mimetype, False) app_info.launch([gfile])
def execute(self, interface_entry): self.interface_entry = interface_entry interfacetype = interface_entry.get_interface_class().get_interface_type() app_info = gio.app_info_get_default_for_type(interfacetype, False) # NOTE: 1 == 1, for now always show the dialog if app_info == None or 1 == 1: self._open_dialog(interface_entry) else: self._execute(app_info, interfacetype, False)
def goto_dir(editor): import gio import os.path f = gio.file_parse_name(os.path.dirname(editor.uri)) ct = f.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE).get_content_type() ai = gio.app_info_get_default_for_type(ct, False) if ai: ai.launch([f]) editor.message('File manager started', 1000) else: editor.message('Unknown content type for launch %s' % ct)
def open_with(path): context = gtk.gdk.AppLaunchContext() path = os.path.abspath(path) if os.path.isdir(path): path += "/" mime_type = gio.content_type_guess(path) app_info = gio.app_info_get_default_for_type(mime_type, False) if app_info != None: app_info.launch([gio.File(path)], context) else: sys.stderr.write('no application related to "%s"\n' % mime_type)
def do_update_for_type(self, model, path, iter, type): this_type = model.get_value(iter, TYPE_MIME) if this_type == type: app = gio.app_info_get_default_for_type(type, False) if app: appname = app.get_name() applogo = icon.get_from_app(app) model.set(iter, TYPE_APPICON, applogo, TYPE_APP, appname) else: model.set(iter, TYPE_APPICON, None, TYPE_APP, _("None"))
def launchApplicationByUrl(url, mimeType): """Launches an application in the background for displaying a url which is of a specific mimeType @param url: the url to display @param mimeType: the mime type of the content """ try: import gnomevfs except ImportError: gnomevfs = None try: from win32com.shell import shell as win32shell except ImportError: win32shell = None try: import gio except ImportError: gio = None if gio: app = gio.app_info_get_default_for_type(mimeType, True) if not app: return args = '%s %s' % (app.get_executable(), url) executable = None shell = True elif gnomevfs: app = gnomevfs.mime_get_default_application(mimeType) if not app: return args = '%s %s' % (app[2], url) executable = None shell = True elif win32shell: assoc = win32shell.AssocCreate() ext = _EXTENSIONS.get(mimeType) if ext is None: return assoc.Init(0, '.' + ext) args = assoc.GetString(0, _ASSOCSTR_COMMAND) executable = assoc.GetString(0, _ASSOCSTR_EXECUTABLE) args = args.replace("%1", url) args = args.replace("%L", url) shell = False else: return import subprocess subprocess.Popen(args, executable=executable, shell=shell)
def get_default_player(): '''获取默认播放器路径''' if sys.platform == "win32": return "C:\\Program Files\\Windows Media Player\\wmplayer.exe"; else: try: import gio app = gio.app_info_get_default_for_type('audio/mpeg', False) cmd = app.get_commandline() # 命令中可能有 “%F” 或 “%f”,要去掉。例如 “exaile %F”, 之需要 “exaile”. return cmd.split()[0]; except: return ""
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 is_valid(self): gfile = gio.File (uri=self._url) if not gfile.query_exists(): LOGGER.debug("File %s does not exist", gfile.get_uri ()) return False else: try: fileinfo = gfile.query_info("standard::content-type") returnval = gio.app_info_get_default_for_type( fileinfo.get_content_type(), True) != None except Exception, e: # get_mime_type throws a RuntimeException when something went wrong returnval = False
def is_valid(self): gfile = gio.File(uri=self._url) if not gfile.query_exists(): LOGGER.debug("File %s does not exist", gfile.get_uri()) return False else: try: fileinfo = gfile.query_info("standard::content-type") returnval = gio.app_info_get_default_for_type( fileinfo.get_content_type(), True) != None except Exception, e: # get_mime_type throws a RuntimeException when something went wrong returnval = False
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 launch_selected(self, mdl, it): #{{{ t = mdl.get_value(it, model.COLUMN_TYPE) if mdl is self.apps_model.get_model(): id = mdl.get_value(it, model.COLUMN_ID) item = self.apps_model.data[id] if t == model.TYPE_APP: self.execute_command(item['command']) elif t == model.TYPE_DIR: self.execute_command(item['command']) elif t == model.TYPE_FILE: appinfo = gio.app_info_get_default_for_type(item['mimetype'], False) if appinfo: appinfo.launch_uris([item['url']], None) elif t == model.TYPE_CMD: pass elif mdl is self.fs_model.get_model(): name, mimetype = mdl.get(it, model.COLUMN_NAME, model.COLUMN_MIMETYPE) path = self.fs_model.last_visited filepath = os.path.join(path, name) appinfo = gio.app_info_get_default_for_type(mimetype, False) gfile = gio.File(filepath) if appinfo: appinfo.launch([gfile], None)
def open_mime(self): fname, name, root, top = self.get_selected_file() if fname: import gio self.hide() refresh_gui() f = gio.file_parse_name(fname) ct = f.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE).get_content_type() ai = gio.app_info_get_default_for_type(ct, False) if ai: ai.launch([f]) else: self.pwindow().emessage('Unknown content type for launch %s' % ct, 'error')
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 __init__(self, store, model, can_change=True, can_erase=True, visual_mode=False): self._image_model = model model = _DummyImageModel() BaseEditorSlave.__init__(self, store, model, visual_mode) self._setup_image_model() self._setup_widgets() if not can_change: self.edit_item.hide() if not can_erase: self.erase_item.hide() self._app_info = gio.app_info_get_default_for_type('image/png', False) if not self._app_info: # Hide view item if we don't have any app to visualize it. self.view_item.hide()
def __init__(self, store, model, can_change=True, can_erase=True, visual_mode=False): self._image_model = model model = _DummyImageModel() BaseEditorSlave.__init__(self, store, model, visual_mode) self._setup_image_model() self._setup_widgets() if not can_change: self.edit_item.hide() if not can_erase: self.erase_item.hide() self._app_info = gio.app_info_get_default_for_type('image/png', False) if not self._app_info: # Hide view item if we don't have any app to visualize it. self.view_item.hide()
def export_temporary(self, temporary): mime_type = 'application/vnd.ms-excel' app_info = gio.app_info_get_default_for_type(mime_type, False) if app_info: action = api.user_settings.get('spreadsheet-action') if action is None: action = 'open' else: action = 'save' if action == 'ask': action = self._ask(app_info) if action == 'open': temporary.close() self._open_application(mime_type, temporary.name) elif action == 'save': self._save(temporary)
def export_temporary(self, temporary): mime_type = 'application/vnd.ms-excel' app_info = gio.app_info_get_default_for_type(mime_type, False) if app_info: action = api.user_settings.get('spreadsheet-action') if action is None: action = 'open' else: action = 'save' if action == 'ask': action = self._ask(app_info) if action == 'open': temporary.close() self._open_application(mime_type, temporary.name) elif action == 'save': self._save(temporary)
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 _update_widget(self): has_attachment = bool(self.attachment and self.attachment.blob) if has_attachment: self._label.set_label(self.attachment.get_description()) app_info = gio.app_info_get_default_for_type( self.attachment.mimetype, must_support_uris=False) if app_info: gicon = app_info.get_icon() self.image.set_from_gicon(gicon, gtk.ICON_SIZE_SMALL_TOOLBAR) else: self._label.set_label(self.no_attachment_lbl) can_open = bool(has_attachment and app_info) self._open_button__set_sensitive(can_open) self.add_button.set_sensitive(not has_attachment) self.edit_button.set_sensitive(has_attachment) self.delete_button.set_sensitive(has_attachment)
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_default_application_for_type(self, mime_type): """Get default application for specified type""" app_info = gio.app_info_get_default_for_type(mime_type, must_support_uris=False) if app_info is not None: # create application container 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()) ) else: # return None if there is no default application for this type application = None return application
def _update_widget(self): has_attachment = bool(self.attachment and self.attachment.blob) if has_attachment: self._label.set_label(self.attachment.get_description()) app_info = gio.app_info_get_default_for_type( self.attachment.mimetype, must_support_uris=False) if app_info: gicon = app_info.get_icon() self.image.set_from_gicon(gicon, gtk.ICON_SIZE_SMALL_TOOLBAR) else: self._label.set_label(self.no_attachment_lbl) can_open = bool(has_attachment and app_info) self._open_button__set_sensitive(can_open) self.add_button.set_sensitive(not has_attachment) self.edit_button.set_sensitive(has_attachment) self.delete_button.set_sensitive(has_attachment)
def __init__(self, promt, filetype): gtk.Frame.__init__(self) self.filetype = filetype self.set_label('%s %s:' % (promt, filetype)) self.icon_image = gtk.Image() self.label_name_app = gtk.Label('Test') self.label_name_app.set_alignment(0.0, 0.5) self.label_description_app = gtk.Label('Test') self.label_description_app.set_alignment(0.0, 0.5) self.__set_new_app__(gio.app_info_get_default_for_type( filetype, False)) vbox2 = gtk.VBox(False, 10) hbox1 = gtk.HBox(False, 10) vbox2.pack_start(self.label_name_app) vbox2.pack_start(self.label_description_app) hbox1.set_border_width(5) hbox1.pack_start(self.icon_image, False) hbox1.pack_start(vbox2) self.add(hbox1)
def get_default_for_type(self, content_type, must_support_uris=False): return gio.app_info_get_default_for_type(content_type, must_support_uris)
def double_click(self, column, offset_x, offset_y): app_info = gio.app_info_get_default_for_type(self.gfile.query_info("standard::content-type").get_content_type(), False) if app_info: app_info.launch([self.gfile], None) else: print "Don't know how to open file: %s" % (self.name)
def _open_application(self, mime_type, filename): app_info = gio.app_info_get_default_for_type(mime_type, False) gfile = gio.File(path=filename) app_info.launch([gfile])
def app_info_get_default_for_type(mime): return gio.app_info_get_default_for_type(mime)
def launch(self): appinfo = gio.app_info_get_default_for_type(self.mime_type, False) appinfo.launch([ self._file_object, ], None)
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,