def content_type_description_(self, column, cell, model, iter): content_type = model.get(iter, 2)[0] if content_type == 'inode/directory': description = '' else: description = gio.content_type_get_description(content_type) cell.set_property('text', description)
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 get_file_mime(): file = "./data/2946117692.01.180" gio_file = gio.File(file) # gio_file_info = gio_file.query_info(",".join([ # gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, # gio.FILE_ATTRIBUTE_STANDARD_TYPE, # gio.FILE_ATTRIBUTE_STANDARD_NAME, # gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, # gio.FILE_ATTRIBUTE_STANDARD_SIZE, # gio.FILE_ATTRIBUTE_STANDARD_ICON, # gio.FILE_ATTRIBUTE_TIME_MODIFIED, # gio.FILE_ATTRIBUTE_TIME_CHANGED,])) gio_file_info = gio_file.query_info(",".join([ gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, ])) info_attr = gio_file_info.get_attribute_as_string( gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) type_description = gio.content_type_get_description(info_attr) #print type_description mime_tye = gio.content_type_get_mime_type(info_attr) print mime_tye
def get_mime_description(mime_type): generic_type = _get_generic_type_for_mime(mime_type) if generic_type: return generic_type['name'] import gio return gio.content_type_get_description(mime_type)
def __init__(self, type, parent): super(AddAppDialog, self).__init__() worker = GuiWorker('type_edit.ui') self.dialog = worker.get_object('add_app_dialog') self.dialog.set_modal(True) self.dialog.set_transient_for(parent) self.app_view = worker.get_object('app_view') self.setup_treeview() self.app_selection = self.app_view.get_selection() self.app_selection.connect('changed', self.on_app_selection_changed) self.info_label = worker.get_object('info_label') self.description_label = worker.get_object('description_label') self.info_label.set_markup( _('Open files of type "%s" with:') % gio.content_type_get_description(type)) self.add_button = worker.get_object('add_button') self.add_button.connect('clicked', self.on_add_button_clicked) self.command_entry = worker.get_object('command_entry') self.browse_button = worker.get_object('browse_button') self.browse_button.connect('clicked', self.on_browse_button_clicked)
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 get_gfile_content_type(gfile): ''' Get type of gfile. @param gfile: The GFile. @return: Return content type with given gfile, use \"standard::content-type\" to query info from gfile. ''' return gio.content_type_get_description(gfile.query_info("standard::content-type").get_content_type())
def get_gfile_content_type(gfile): ''' Get type of gfile. @param gfile: The GFile. @return: Return content type with given gfile, use \"standard::content-type\" to query info from gfile. ''' return gio.content_type_get_description( gfile.query_info("standard::content-type").get_content_type())
def get_song_attr(song): if song.get_type() in ["cue", "local", "cdda"]: try: gio_file = gio.File(song.get_path()) gio_file_info = gio_file.query_info(",".join([gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,])) info_attr = gio_file_info.get_attribute_as_string(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) return gio.content_type_get_description(info_attr) except: return song.get_ext(False).upper() else: return song.get_ext(False).upper()
def get_ext_type(self): gio_file = gio.File(self.output_path) gio_file_info = gio_file.query_info(",".join([gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, gio.FILE_ATTRIBUTE_STANDARD_TYPE, gio.FILE_ATTRIBUTE_STANDARD_NAME, gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, gio.FILE_ATTRIBUTE_STANDARD_SIZE, gio.FILE_ATTRIBUTE_STANDARD_ICON, gio.FILE_ATTRIBUTE_TIME_MODIFIED, gio.FILE_ATTRIBUTE_TIME_CHANGED,])) info_attr = gio_file_info.get_attribute_as_string(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) return gio.content_type_get_description(info_attr)
def get_ext_type(self): gio_file = gio.File(self.output_path) gio_file_info = gio_file.query_info(",".join([gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, gio.FILE_ATTRIBUTE_STANDARD_TYPE, gio.FILE_ATTRIBUTE_STANDARD_NAME, gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, gio.FILE_ATTRIBUTE_STANDARD_SIZE, gio.FILE_ATTRIBUTE_STANDARD_ICON, gio.FILE_ATTRIBUTE_TIME_MODIFIED, gio.FILE_ATTRIBUTE_TIME_CHANGED,])) info_attr = gio_file_info.get_attribute_as_string(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) return gio.content_type_get_description(info_attr)
def get_song_attr(song): if song.get_type() in ["cue", "local", "cdda"]: try: gio_file = gio.File(song.get_path()) gio_file_info = gio_file.query_info(",".join([ gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, ])) info_attr = gio_file_info.get_attribute_as_string( gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) return gio.content_type_get_description(info_attr) except: return song.get_ext(False).upper() else: return song.get_ext(False).upper()
def __init__(self, types, parent): super(TypeEditDialog, self).__init__() self.types = types type_pixbuf = mime_type_get_icon(self.types[0], 64) worker = GuiWorker("type_edit.ui") self.dialog = worker.get_object("type_edit_dialog") self.dialog.set_transient_for(parent) self.dialog.set_modal(True) self.dialog.connect("destroy", self.on_dialog_destroy) type_logo = worker.get_object("type_edit_logo") type_logo.set_from_pixbuf(type_pixbuf) type_label = worker.get_object("type_edit_label") if len(self.types) > 1: markup_text = ", ".join([gio.content_type_get_description(filetype) for filetype in self.types]) else: markup_text = self.types[0] type_label.set_markup( ngettext( "Select an application to open files of type: <b>%s</b>", "Select an application to open files for these types: <b>%s</b>", len(self.types), ) % markup_text ) self.type_edit_view = worker.get_object("type_edit_view") self.setup_treeview() add_button = worker.get_object("type_edit_add_button") add_button.connect("clicked", self.on_add_button_clicked) remove_button = worker.get_object("type_edit_remove_button") # remove button should not available in multiple selection if len(self.types) > 1: add_button.hide() remove_button.hide() remove_button.connect("clicked", self.on_remove_button_clicked) close_button = worker.get_object("type_edit_close_button") close_button.connect("clicked", self.on_dialog_destroy)
def get_song_attr(self, song, song_type=True): gio_file = gio.File(self.song.get_path()) gio_file_info = gio_file.query_info(",".join([gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, gio.FILE_ATTRIBUTE_STANDARD_TYPE, gio.FILE_ATTRIBUTE_STANDARD_NAME, gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, gio.FILE_ATTRIBUTE_STANDARD_SIZE, gio.FILE_ATTRIBUTE_STANDARD_ICON, gio.FILE_ATTRIBUTE_TIME_MODIFIED, gio.FILE_ATTRIBUTE_TIME_CHANGED,])) info_attr = gio_file_info.get_attribute_as_string(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) if song_type: return gio.content_type_get_description(info_attr) else: return info_attr
def __init__(self, types, parent): super(TypeEditDialog, self).__init__() self.types = types type_pixbuf = icon.get_from_mime_type(self.types[0], 64) worker = GuiWorker('type_edit.ui') self.dialog = worker.get_object('type_edit_dialog') self.dialog.set_transient_for(parent) self.dialog.set_modal(True) self.dialog.connect('destroy', self.on_dialog_destroy) type_logo = worker.get_object('type_edit_logo') type_logo.set_from_pixbuf(type_pixbuf) type_label = worker.get_object('type_edit_label') if len(self.types) > 1: markup_text = ", ".join([ gio.content_type_get_description(filetype) for filetype in self.types ]) else: markup_text = self.types[0] type_label.set_markup( ngettext( 'Select an application to open files of type: <b>%s</b>', 'Select an application to open files for these types: <b>%s</b>', len(self.types)) % markup_text) self.type_edit_view = worker.get_object('type_edit_view') self.setup_treeview() add_button = worker.get_object('type_edit_add_button') add_button.connect('clicked', self.on_add_button_clicked) remove_button = worker.get_object('type_edit_remove_button') # remove button should not available in multiple selection if len(self.types) > 1: remove_button.hide() remove_button.connect('clicked', self.on_remove_button_clicked) close_button = worker.get_object('type_edit_close_button') close_button.connect('clicked', self.on_dialog_destroy)
def _get_markup_for_value(self, value, strip_length=True, markup=True): style = self.style if value == None: if markup: value = '<span foreground="%s"><NULL></span>' % style.dark[ gtk.STATE_PRELIGHT].to_string() else: value = 'null' elif isinstance(value, buffer): if markup: if HAVE_GIO: mime = gio.content_type_guess(None, value) else: mime = None if mime is None: mime = 'LOB' else: mime = ( '%s (%s)' # e.g. "Python-Skript (text/x-python)" % (gio.content_type_get_description(mime), mime)) value = ('<span foreground="%s"><%s></span>' % (style.dark[gtk.STATE_PRELIGHT].to_string(), mime)) else: value = str(buffer) else: if isinstance(value, str): value = unicode(value, self.coding_hint, 'replace') elif isinstance(value, unicode): pass else: value = unicode(value) value = value.splitlines() if value: if strip_length and len(value[0]) > GRID_LABEL_MAX_LENGTH: value = ('%s <span foreground="%s">[...]</span>' % (gobject.markup_escape_text( value[0][:GRID_LABEL_MAX_LENGTH]), style.dark[gtk.STATE_NORMAL].to_string())) else: value = gobject.markup_escape_text("\n".join(value)) else: value = "" return value
def _get_markup_for_value(self, value, strip_length=True, markup=True): style = self.style if value == None: if markup: value = '<span foreground="%s"><NULL></span>' % style.dark[gtk.STATE_PRELIGHT].to_string() else: value = 'null' elif isinstance(value, buffer): if markup: if HAVE_GIO: mime = gio.content_type_guess(None, value) else: mime = None if mime is None: mime = 'LOB' else: mime = ('%s (%s)' # e.g. "Python-Skript (text/x-python)" % (gio.content_type_get_description(mime), mime)) value = ('<span foreground="%s"><%s></span>' % (style.dark[gtk.STATE_PRELIGHT].to_string(), mime)) else: value = str(buffer) else: if isinstance(value, str): value = unicode(value, self.coding_hint, 'replace') elif isinstance(value, unicode): pass else: value = unicode(value) value = value.splitlines() if value: if strip_length and len(value[0]) > GRID_LABEL_MAX_LENGTH: value = ('%s <span foreground="%s">[...]</span>' % (gobject.markup_escape_text( value[0][:GRID_LABEL_MAX_LENGTH]), style.dark[gtk.STATE_NORMAL].to_string())) else: value = gobject.markup_escape_text("\n".join(value)) else: value = "" return value
def get_song_attr(self, song, song_type=True): try: gio_file = gio.File(self.song.get_path()) gio_file_info = gio_file.query_info(",".join([gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, gio.FILE_ATTRIBUTE_STANDARD_TYPE, gio.FILE_ATTRIBUTE_STANDARD_NAME, gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, gio.FILE_ATTRIBUTE_STANDARD_SIZE, gio.FILE_ATTRIBUTE_STANDARD_ICON, gio.FILE_ATTRIBUTE_TIME_MODIFIED, gio.FILE_ATTRIBUTE_TIME_CHANGED,])) info_attr = gio_file_info.get_attribute_as_string(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) if song_type: return gio.content_type_get_description(info_attr) else: return info_attr except: return ""
def get_file_mime(): file = "./data/2946117692.01.180" gio_file = gio.File(file) # gio_file_info = gio_file.query_info(",".join([ # gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, # gio.FILE_ATTRIBUTE_STANDARD_TYPE, # gio.FILE_ATTRIBUTE_STANDARD_NAME, # gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, # gio.FILE_ATTRIBUTE_STANDARD_SIZE, # gio.FILE_ATTRIBUTE_STANDARD_ICON, # gio.FILE_ATTRIBUTE_TIME_MODIFIED, # gio.FILE_ATTRIBUTE_TIME_CHANGED,])) gio_file_info = gio_file.query_info(",".join([ gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,])) info_attr = gio_file_info.get_attribute_as_string(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) type_description = gio.content_type_get_description(info_attr) #print type_description mime_tye = gio.content_type_get_mime_type(info_attr) print mime_tye
def __init__(self, type, parent): super(AddAppDialog, self).__init__() worker = GuiWorker("type_edit.ui") self.dialog = worker.get_object("add_app_dialog") self.dialog.set_modal(True) self.dialog.set_transient_for(parent) self.app_view = worker.get_object("app_view") self.setup_treeview() self.app_selection = self.app_view.get_selection() self.app_selection.connect("changed", self.on_app_selection_changed) self.info_label = worker.get_object("info_label") self.description_label = worker.get_object("description_label") self.info_label.set_markup(_('Open files of type "%s" with:') % gio.content_type_get_description(type)) self.add_button = worker.get_object("add_button") self.add_button.connect("clicked", self.on_add_button_clicked) self.command_entry = worker.get_object("command_entry") self.browse_button = worker.get_object("browse_button") self.browse_button.connect("clicked", self.on_browse_button_clicked)
def __init__(self, type, parent): super(AddAppDialog, self).__init__() worker = GuiWorker('type_edit.glade') self.dialog = worker.get_object('add_app_dialog') self.dialog.set_modal(True) self.dialog.set_transient_for(parent) self.app_view = worker.get_object('app_view') self.setup_treeview() self.app_selection = self.app_view.get_selection() self.app_selection.connect('changed', self.on_app_selection_changed) self.info_label = worker.get_object('info_label') self.description_label = worker.get_object('description_label') self.info_label.set_markup(_('Open the files of type "%s" with:') % gio.content_type_get_description(type)) self.add_button = worker.get_object('add_button') self.add_button.connect('clicked', self.on_add_button_clicked) self.command_entry = worker.get_object('command_entry') self.browse_button = worker.get_object('browse_button') self.browse_button.connect('clicked', self.on_browse_button_clicked)
def get_mime_description(self, mime_type): """Get description from mime type""" return gio.content_type_get_description(mime_type)
def get_gfile_content_type(gfile): ''' Get type of gfile. ''' return gio.content_type_get_description(gfile.query_info("standard::content-type").get_content_type())
def get_mime_description(self, mime_type): """Get description from mime type""" return gio.content_type_get_description(mime_type)
def type(self): content_type = gio.File(self._path).query_info("standard::*").get_content_type() return gio.content_type_get_description(content_type).title().split(" ")[0]
def __init__(self, type, parent): super(TypeEditDialog, self).__init__() self.type = type type_pixbuf = mime_type_get_icon(type, 64) worker = GuiWorker('type_edit.glade') self.dialog = worker.get_object('type_edit_dialog') self.dialog.set_transient_for(parent) self.dialog.set_modal(True) self.dialog.connect('destroy', self.on_dialog_destroy) type_logo = worker.get_object('type_edit_logo') type_logo.set_from_pixbuf(type_pixbuf) type_label = worker.get_object('type_edit_label') type_label.set_markup(_('Select an application to open the type <b>%s</b>') % gio.content_type_get_description(type)) self.type_edit_view = worker.get_object('type_edit_view') self.setup_treeview() add_button = worker.get_object('type_edit_add_button') add_button.connect('clicked', self.on_add_button_clicked) remove_button = worker.get_object('type_edit_remove_button') remove_button.connect('clicked', self.on_remove_button_clicked) close_button = worker.get_object('type_edit_close_button') close_button.connect('clicked', self.on_dialog_destroy)
def __init__(self, type): self._type = type self.mimeType = gio.content_type_get_mime_type(type) self.description = gio.content_type_get_description(type)