コード例 #1
0
def get_icon(path, tclass="*"):
    try:
        base = os.path.basename(path)
        if base in desktop_icon_dict:
            for m in desktop_icon_dict[base]:
                icon = m.get_icon()
                if icon:
                    return icon

        rpmver = get_rpm_nvr_by_file_path(path)
        if rpmver in desktop_icon_dict:
            for m in desktop_icon_dict[rpmver]:
                icon = m.get_icon()
                if icon:
                    return icon

        file = gio.File(path)
        info = file.query_info("standard::*", flags=gio.FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)
        icon = info.get_icon()
        if icon:
            icon.append_name("text-x-generic")
            return icon

    except gio.Error:
        pass

    if tclass in dict:
        return gio.content_type_get_icon(dict[tclass])
    else:
        return gio.content_type_get_icon(dict["*"])
コード例 #2
0
def get_icon(path, tclass="*"):
    try:
        base = os.path.basename(path)
        if base in desktop_icon_dict:
            for m in desktop_icon_dict[base]:
                icon = m.get_icon()
                if icon:
                    return icon

        rpmver = get_rpm_nvr_by_file_path(path)
        if rpmver in desktop_icon_dict:
            for m in desktop_icon_dict[rpmver]:
                icon = m.get_icon()
                if icon:
                    return icon

        file = gio.File(path)
        info = file.query_info("standard::*", flags=gio.FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)
        icon = info.get_icon()
        if icon:
            icon.append_name("text-x-generic")
            return icon

    except gio.Error:
        pass

    if tclass in dict:
        return gio.content_type_get_icon(dict[tclass])
    else:
        return gio.content_type_get_icon(dict["*"])
コード例 #3
0
ファイル: edna_function.py プロジェクト: cryptspirit/edna
def get_ico(s, size_ico=True):
    """
    Получение иконки по типу и если такой тип уже есть в словаре иконок то используеться
    словарь если нет то в словарь добавляеться новая иконка
    """
    global dic_icon
    p = gio.content_type_get_icon(s)
    pm = p.get_names()
    if size_ico:
        try:
            dic_icon.keys().index(s)
        except:
            for i in pm:
                try:
                    b = icon_load_try(i, int(rc_dict["style"]["icon_size"]))
                except:
                    pass
                else:
                    dic_icon[s] = b
                    return dic_icon[s]
            if s != "None":
                print s
            return dic_icon["empty"]
        else:
            return dic_icon[s]
    else:
        for i in pm:
            print i
            try:
                b = icon_load_try(i, 24)
            except:
                pass
            else:
                return b
        return icon_load_try("empty", 24)
コード例 #4
0
ファイル: activitiestray.py プロジェクト: nemesiscodex/jarabe
    def __init__(self, file_transfer):
        BaseTransferButton.__init__(self, file_transfer)

        self._ds_object = datastore.create()

        file_transfer.connect('notify::state', self.__notify_state_cb)
        file_transfer.connect('notify::transferred-bytes',
                              self.__notify_transferred_bytes_cb)

        icons = gio.content_type_get_icon(file_transfer.mime_type).props.names
        icons.append('application-octet-stream')
        for icon_name in icons:
            icon_name = 'transfer-from-%s' % icon_name
            file_name = get_icon_file_name(icon_name)
            if file_name is not None:
                self.props.icon_widget.props.icon_name = icon_name
                self.notif_icon.props.icon_name = icon_name
                break

        icon_color = file_transfer.buddy.props.color
        self.props.icon_widget.props.xo_color = icon_color
        self.notif_icon.props.xo_color = icon_color

        frame = jarabe.frame.get_view()
        frame.add_notification(self.notif_icon,
                               gtk.CORNER_TOP_LEFT)
コード例 #5
0
ファイル: edna_function.py プロジェクト: sevka/edna
def get_ico(s, size_ico=True):
    '''
    Получение иконки по типу и если такой тип уже есть в словаре иконок то используеться
    словарь если нет то в словарь добавляеться новая иконка
    '''
    global dic_icon
    p = gio.content_type_get_icon(s)
    pm = p.get_names()
    if size_ico:
        try:
            dic_icon.keys().index(s)
        except:
            for i in pm:
                try:
                    b = get_theme.load_icon(i, int(rc_dict['style']['icon_size']), type_ico_load)
                except:
                    pass
                else:
                    dic_icon[s] = b
                    return dic_icon[s]
            if s != 'None': print s
            return dic_icon['empty']
        else:
            return dic_icon[s]
    else:
        for i in pm:
            print i
            try:
                b = get_theme.load_icon(i, 24, type_ico_load)
            except:
                pass
            else:
                return b
        return get_theme.load_icon('empty', 24, type_ico_load)
コード例 #6
0
def get_ico(s, size_ico=True):
    '''
    Получение иконки по типу и если такой тип уже есть в словаре иконок то используеться
    словарь если нет то в словарь добавляеться новая иконка
    '''
    global edna_builtin

    p = gio.content_type_get_icon(s)
    pm = p.get_names()
    if size_ico:
        try:
            edna_builtin['icons container'].keys().index(s)
        except:
            for i in pm:
                try:
                    b = icon_load_try(i, int(edna_builtin['configuration']['style']['icon_size']))
                except:
                    pass
                else:
                    edna_builtin['icons container'][s] = b
                    return edna_builtin['icons container'][s]
            if s != 'None': print s
            return edna_builtin['icons container']['empty']
        else:
            return edna_builtin['icons container'][s]
    else:
        for i in pm:
            print i
            try:
                b = icon_load_try(i, 24)
            except:
                pass
            else:
                return b
        return icon_load_try('empty', 24)
コード例 #7
0
def get_icon_path(extension, size=16):
    type_, encoding = mimetypes.guess_type('x.' + extension)
    if type_:
        icon = gio.content_type_get_icon(type_)
        theme = gtk.icon_theme_get_default()
        info = theme.choose_icon(icon.get_names(), size, 0)
        if info:
            return info.get_filename()
コード例 #8
0
ファイル: gnome.py プロジェクト: carriercomm/Spark-4
 def icon(self, size):
     iconName = gio.content_type_get_icon(self._type)
     theme = gtk.icon_theme_get_default()
     icon = theme.choose_icon(iconName.get_names(), size, 0)
     if icon:
         return QPixmap(icon.get_filename())
     else:
         return QPixmap()
コード例 #9
0
def get_mimetype_icon(mimetype):
    import gtk, gio
    iconName = gio.content_type_get_icon( mimetype )
    theme = gtk.icon_theme_get_default()
    icon = theme.choose_icon(iconName.get_names(), 48, 0)
    if not icon :
        print mimetype
        return None
    
    return icon.get_filename()
コード例 #10
0
    def load_bookmarks(self):
        liststore = self.bookmarks_treeview.get_model()
        if liststore != None:
            liststore.clear()
            icon_theme = gtk.icon_theme_get_default()

            bookmarks = self.bookmarks_manager.get_bookmarks()
            for bookmark in bookmarks:
                parse_result = urlparse.urlparse(bookmark.url)

                # If the bookmark is read-only I assume it is an operator one, and the
                # favorite icon from the theme must be displayed
                if bookmark.readonly:
                    pixbuf = self.bookmark_icon_pixbuf

                # It is a file-based bookmark, so I'll display the mimetype icon
                elif parse_result.scheme == 'file':
                    filepath = urlparse.urlparse(bookmark.url).path
                    filepath = urllib.url2pathname(filepath)
                    try:
                        mimetype = self.__get_mimetype(filepath)
                        type_names = gio.content_type_get_icon(
                            mimetype).get_names()
                    except:
                        type_names = ['text-x-generic']

                    pixbuf = None
                    for stock_id in type_names:
                        try:
                            pixbuf = icon_theme.load_icon(
                                stock_id, 16, gtk.ICON_LOOKUP_USE_BUILTIN)
                            break
                        except glib.GError:
                            pass

                # Finally, it seems that it is an user bookmark
                else:
                    pixbuf = icon_theme.load_icon('text-html', 16,
                                                  gtk.ICON_LOOKUP_USE_BUILTIN)

                # If something goes wrong and no pixbuf has been selected, just show a boring
                # default icon
                if pixbuf is None:
                    pixbuf = icon_theme.load_icon('text-x-generic', 16,
                                                  gtk.ICON_LOOKUP_USE_BUILTIN)

                # GConf returns encoded URLs, it doesn't look so good
                url = urllib.url2pathname(bookmark.url)

                liststore.append([
                    bookmark, pixbuf, bookmark.name,
                    long(bookmark.timestamp), url
                ])
コード例 #11
0
 def get_for_file(self, fname):
     mime = gio.content_type_guess(fname)
     if mime:
         icon_name = gio.content_type_get_icon(mime)
         icon = self.theme.choose_icon(icon_name.get_names(), 16, 0)
         if icon:
             return gtk.IconInfo.load_icon(icon)
         else:
             name = gtk.STOCK_FILE
     else:
         name = gtk.STOCK_FILE
     return self.theme.load_icon(name, 16, 0)
コード例 #12
0
ファイル: recently_used.py プロジェクト: ju1ius/fluxdgmenu
 def find_icon_by_mime_type(self, mime_type):
     for name in gio.content_type_get_icon(mime_type).get_names():
         cache_key = self.icon_name_get_cache_key(name)      
         cached = self.cache.get_icon(cache_key)
         if cached:
             return cached['path'].encode('utf-8')
         else:
             path = self.lookup_icon(name)
             if path:
                 self.cache.add_icon(cache_key, path)
                 return path.encode('utf-8')
     return self.lookup_default_icon().encode('utf-8')
コード例 #13
0
ファイル: misc.py プロジェクト: nemesiscodex/JukyOS-sugar
def _get_icon_for_mime(mime_type):
    generic_types = mime.get_all_generic_types()
    for generic_type in generic_types:
        if mime_type in generic_type.mime_types:
            file_name = get_icon_file_name(generic_type.icon)
            if file_name is not None:
                return file_name

    icons = gio.content_type_get_icon(mime_type)
    logging.debug('icons for this file: %r', icons.props.names)
    for icon_name in icons.props.names:
        file_name = get_icon_file_name(icon_name)
        if file_name is not None:
            return file_name
コード例 #14
0
def _get_icon_for_mime(mime_type):
    generic_types = mime.get_all_generic_types()
    for generic_type in generic_types:
        if mime_type in generic_type.mime_types:
            file_name = get_icon_file_name(generic_type.icon)
            if file_name is not None:
                return file_name

    icons = gio.content_type_get_icon(mime_type)
    logging.debug('icons for this file: %r' % icons.props.names)
    for icon_name in icons.props.names:
        file_name = get_icon_file_name(icon_name)
        if file_name is not None:
            return file_name
コード例 #15
0
ファイル: strfmt_widgets.py プロジェクト: ju1ius/clisnips
    def _on_completion_timeout(self):
        self._completion_timeout = 0
        self.emit('changed')

        text = self._entry.get_text()
        if not text:
            return False
        self._completion.set_model(None)
        self._model.clear()
        for filepath, filetype in self._get_completions(text):
            gicon = gio.content_type_get_icon(filetype)
            self._model.append((gicon, filepath))
        self._completion.set_model(self._model)
        return False
コード例 #16
0
ファイル: survey.py プロジェクト: freeto/JustOneFile
def get_mimeicon(file_path):
    """
    Return a gtk.gdk.Pixbuf who contain the mime-type icon.

    Arguments:
    - `file_path`: The file to get the icon.
    """
    
    if not os.path.exists (file_path): return False

    # Prend le mimetype du fichier.
    mime = mimetypes.guess_type (os.path.basename (file_path))[0]
    if mime is None:
        mime = 'text/plain'

    theme = gtk.icon_theme_get_default () # Charge le thème.
    icon = gio.content_type_get_icon (mime)
    icon = theme.lookup_by_gicon (icon, 128, gtk.ICON_LOOKUP_USE_BUILTIN)

    if icon is None:            # L'icone n'éxiste pas.
        icon = gio.content_type_get_icon ('text/plain')
        icon = theme.lookup_by_gicon (icon, 128, gtk.ICON_LOOKUP_USE_BUILTIN)

    return icon.load_icon ()
コード例 #17
0
def _get_icon_name(metadata):
    file_name = None

    mime_type = metadata.get('mime_type', '')
    if not file_name and mime_type:
        icons = gio.content_type_get_icon(mime_type)
        for icon_name in icons.props.names:
            file_name = get_icon_file_name(icon_name)
            if file_name is not None:
                break

    if file_name is None or not os.path.exists(file_name):
        file_name = get_icon_file_name('application-octet-stream')

    return file_name
コード例 #18
0
ファイル: icon.py プロジェクト: alix67/ubuntu-tweak
def get_from_mime_type(mime, size=DEFAULT_SIZE):
    try:
        gicon = gio.content_type_get_icon(mime)
        iconinfo = icontheme.choose_icon(gicon.get_names(), size, gtk.ICON_LOOKUP_USE_BUILTIN)
        if not iconinfo:
            pixbuf = get_icon_with_name('application-x-executable', size)
        else:
            pixbuf = iconinfo.load_icon()

        if pixbuf.get_width() != size:
            return pixbuf.scale_simple(size, size, gtk.gdk.INTERP_BILINEAR)
    except:
        return get_from_name(size=size)

    return pixbuf
コード例 #19
0
def _get_icon_name(metadata):
    file_name = None

    mime_type = metadata.get('mime_type', '')
    if not file_name and mime_type:
        icons = gio.content_type_get_icon(mime_type)
        for icon_name in icons.props.names:
            file_name = get_icon_file_name(icon_name)
            if file_name is not None:
                break

    if file_name is None or not os.path.exists(file_name):
        file_name = get_icon_file_name('application-octet-stream')

    return file_name
コード例 #20
0
ファイル: iconview.py プロジェクト: LinuxCNC/linuxcnc
 def _get_icon(self, name):
     theme = gtk.icon_theme_get_default()
     if name == "folder":
         name = gtk.STOCK_DIRECTORY
     else:
         mime = gio.content_type_guess(name)
         if mime:
             iconname = gio.content_type_get_icon(mime)
             icon = theme.choose_icon(iconname.get_names(), self.icon_size, 0)
             if icon:
                 return gtk.IconInfo.load_icon(icon)
             else:
                 name = gtk.STOCK_FILE
         else:
             name = gtk.STOCK_FILE
     return theme.load_icon(name, self.icon_size, 0)
コード例 #21
0
 def _get_icon(self, name):
     theme = gtk.icon_theme_get_default()
     if name == "folder":
         name = gtk.STOCK_DIRECTORY
     else:
         mime = gio.content_type_guess(name)
         if mime:
             iconname = gio.content_type_get_icon(mime)
             icon = theme.choose_icon(iconname.get_names(), self.icon_size, 0)
             if icon:
                 return gtk.IconInfo.load_icon(icon)
             else:
                 name = gtk.STOCK_FILE
         else:
             name = gtk.STOCK_FILE
     return theme.load_icon(name, self.icon_size, 0)
コード例 #22
0
def get_from_mime_type(mime, size=DEFAULT_SIZE):
    try:
        gicon = gio.content_type_get_icon(mime)
        iconinfo = icontheme.choose_icon(gicon.get_names(), size,
                                         gtk.ICON_LOOKUP_USE_BUILTIN)
        if not iconinfo:
            pixbuf = get_icon_with_name('application-x-executable', size)
        else:
            pixbuf = iconinfo.load_icon()

        if pixbuf.get_width() != size:
            return pixbuf.scale_simple(size, size, gtk.gdk.INTERP_BILINEAR)
    except:
        return get_from_name(size=size)

    return pixbuf
コード例 #23
0
ファイル: MSDABookmarks.py プロジェクト: calabozo/tgcmlinux
    def load_bookmarks(self):
        liststore = self.bookmarks_treeview.get_model()
        if liststore != None:
            liststore.clear()
            icon_theme = gtk.icon_theme_get_default()

            bookmarks = self.bookmarks_manager.get_bookmarks()
            for bookmark in bookmarks:
                parse_result = urlparse.urlparse(bookmark.url)

                # If the bookmark is read-only I assume it is an operator one, and the
                # favorite icon from the theme must be displayed
                if bookmark.readonly:
                    pixbuf = self.bookmark_icon_pixbuf

                # It is a file-based bookmark, so I'll display the mimetype icon
                elif parse_result.scheme == 'file':
                    filepath = urlparse.urlparse(bookmark.url).path
                    filepath = urllib.url2pathname(filepath)
                    try:
                        mimetype = self.__get_mimetype(filepath)
                        type_names = gio.content_type_get_icon(mimetype).get_names()
                    except:
                        type_names = ['text-x-generic']

                    pixbuf = None
                    for stock_id in type_names:
                        try:
                            pixbuf = icon_theme.load_icon(stock_id, 16, gtk.ICON_LOOKUP_USE_BUILTIN)
                            break
                        except glib.GError:
                            pass

                # Finally, it seems that it is an user bookmark
                else:
                    pixbuf = icon_theme.load_icon('text-html', 16, gtk.ICON_LOOKUP_USE_BUILTIN)

                # If something goes wrong and no pixbuf has been selected, just show a boring
                # default icon
                if pixbuf is None:
                    pixbuf = icon_theme.load_icon('text-x-generic', 16, gtk.ICON_LOOKUP_USE_BUILTIN)

                # GConf returns encoded URLs, it doesn't look so good
                url = urllib.url2pathname(bookmark.url)

                liststore.append([bookmark, pixbuf , bookmark.name, long(bookmark.timestamp), url])
コード例 #24
0
ファイル: mime.py プロジェクト: melviso/beatle
 def __init__(self):
     """init"""
     import gtk
     import gio
     self._extra_bitmap = {}
     self._handler = wx.MimeTypesManager()
     self._mime = self._handler.EnumAllFileTypes()
     self._mime_themed_icon = dict([(x, gio.content_type_get_icon(x)) for x in self._mime])
     self._themed_icon = []
     for themed_icon in self._mime_themed_icon.values():
         if themed_icon not in self._themed_icon:
             self._themed_icon.append(themed_icon)
     self._theme = gtk.icon_theme_get_default()
     self._size = 24
     self._imageList = None
     self.register_default_extra_bitmaps()
     MimeHandler.instance = self
     super(MimeHandler, self).__init__()
コード例 #25
0
ファイル: __init__.py プロジェクト: dexapier/fluidity
    def _get_icon_pixbuf(self, file_path):
        it = gtk.icon_theme_get_default()
        #short-circuit on folders, since it fails otherwise...  strange.
        if os.path.isdir(file_path):
            return it.load_icon('folder', 16, gtk.ICON_LOOKUP_USE_BUILTIN)

        content_type = gio.content_type_guess(file_path)
        type_names = gio.content_type_get_icon(content_type).get_names()
        for stock_id in type_names:
            # jesus fscking christ.  this is stoopid... for GTK's sake, I HOPE
            # this is the wrong way to do this
            try:
                pixbuf = it.load_icon(stock_id, 16, gtk.ICON_LOOKUP_USE_BUILTIN)
                return pixbuf
            except glib.GError:
                pass
        # FAIL.  just return something completely generic.
        pixbuf = it.load_icon('text-x-generic', 16, gtk.ICON_LOOKUP_USE_BUILTIN)
        return pixbuf
コード例 #26
0
ファイル: icons.py プロジェクト: ArseniyK/Sunflower
	def get_icon_for_file(self, filename, size=gtk.ICON_SIZE_MENU):
		"""Load icon for specified file"""
		result = self._default_file
		mime_type = self._parent.associations_manager.get_mime_type(filename)
		themed_icon = None

		# get icon names
		if mime_type is not None:
			themed_icon = gio.content_type_get_icon(mime_type)

		# get only valid icon names
		if themed_icon is not None:
			icon_list = themed_icon.get_names()
			icon_list = filter(self.has_icon, icon_list)

			if len(icon_list) > 0:
				result = icon_list[0]

		return result
コード例 #27
0
    def get_icon_for_file(self, filename, size=gtk.ICON_SIZE_MENU):
        """Load icon for specified file"""
        result = self._default_file
        mime_type = self._parent.associations_manager.get_mime_type(filename)
        themed_icon = None

        # get icon names
        if mime_type is not None:
            themed_icon = gio.content_type_get_icon(mime_type)

        # get only valid icon names
        if themed_icon is not None:
            icon_list = themed_icon.get_names()
            icon_list = filter(self.has_icon, icon_list)

            if len(icon_list) > 0:
                result = icon_list[0]

        return result
コード例 #28
0
    def get_icon(self):
        mime_type = self.get_mime_type()

        generic_types = mime.get_all_generic_types()
        for generic_type in generic_types:
            if mime_type in generic_type.mime_types:
                return generic_type.icon

        icons = gio.content_type_get_icon(mime_type)
        icon_name = None
        if icons is not None:
            icon_theme = gtk.icon_theme_get_default()
            for icon_name in icons.props.names:
                icon_info = icon_theme.lookup_icon(icon_name,
                                                gtk.ICON_SIZE_LARGE_TOOLBAR, 0)
                if icon_info is not None:
                    icon_info.free()
                    return icon_name

        return 'application-octet-stream'
コード例 #29
0
    def _get_icon_pixbuf(self, file_path):
        it = gtk.icon_theme_get_default()
        #short-circuit on folders, since it fails otherwise...  strange.
        if os.path.isdir(file_path):
            return it.load_icon('folder', 16, gtk.ICON_LOOKUP_USE_BUILTIN)

        content_type = gio.content_type_guess(file_path)
        type_names = gio.content_type_get_icon(content_type).get_names()
        for stock_id in type_names:
            # jesus fscking christ.  this is stoopid... for GTK's sake, I HOPE
            # this is the wrong way to do this
            try:
                pixbuf = it.load_icon(stock_id, 16,
                                      gtk.ICON_LOOKUP_USE_BUILTIN)
                return pixbuf
            except glib.GError:
                pass
        # FAIL.  just return something completely generic.
        pixbuf = it.load_icon('text-x-generic', 16,
                              gtk.ICON_LOOKUP_USE_BUILTIN)
        return pixbuf
コード例 #30
0
ファイル: activitiestray.py プロジェクト: nemesiscodex/jarabe
    def __init__(self, file_transfer):
        BaseTransferButton.__init__(self, file_transfer)

        icons = gio.content_type_get_icon(file_transfer.mime_type).props.names
        icons.append('application-octet-stream')
        for icon_name in icons:
            icon_name = 'transfer-to-%s' % icon_name
            file_name = get_icon_file_name(icon_name)
            if file_name is not None:
                self.props.icon_widget.props.icon_name = icon_name
                self.notif_icon.props.icon_name = icon_name
                break

        client = gconf.client_get_default()
        icon_color = XoColor(client.get_string('/desktop/sugar/user/color'))
        self.props.icon_widget.props.xo_color = icon_color
        self.notif_icon.props.xo_color = icon_color

        frame = jarabe.frame.get_view()
        frame.add_notification(self.notif_icon,
                               gtk.CORNER_TOP_LEFT)
コード例 #31
0
    def get_icon(self):
        mime_type = self.get_mime_type()

        generic_types = mime.get_all_generic_types()
        for generic_type in generic_types:
            if mime_type in generic_type.mime_types:
                return generic_type.icon

        icons = gio.content_type_get_icon(mime_type)
        icon_name = None
        if icons is not None:
            icon_theme = gtk.icon_theme_get_default()
            for icon_name in icons.props.names:
                icon_info = icon_theme.lookup_icon(icon_name,
                                                   gtk.ICON_SIZE_LARGE_TOOLBAR,
                                                   0)
                if icon_info is not None:
                    icon_info.free()
                    return icon_name

        return 'application-octet-stream'
コード例 #32
0
ファイル: fileicon.py プロジェクト: Daksh/file-manager
def get_file_icon_from_name(name):
	gfile = _gio.File(name)
	fileinfo = gfile.query_info("standard::content-type")
	mime_type = _gio.content_type_get_mime_type(fileinfo.get_content_type())
	icon = _gio.content_type_get_icon(mime_type).get_names()
	index = 0
	icon_name = None
	pixbuf = None
	if "image-x-generic" in icon:
		try:
			pixbuf = _gtk.gdk.pixbuf_new_from_file_at_size(name, 64, 64)
		except:
			pixbuf = None
	if not pixbuf:
		while not (icon[index] in icons):
			index += 1
			if index >= len(icon):
				icon_name = "unknown"
				break
		if not icon_name:
			icon_name = icon[index]
	return pixbuf, icon_name
コード例 #33
0
def get_file_icon_from_name(name):
    gfile = _gio.File(name)
    fileinfo = gfile.query_info("standard::content-type")
    mime_type = _gio.content_type_get_mime_type(fileinfo.get_content_type())
    icon = _gio.content_type_get_icon(mime_type).get_names()
    index = 0
    icon_name = None
    pixbuf = None
    if "image-x-generic" in icon:
        try:
            pixbuf = _gtk.gdk.pixbuf_new_from_file_at_size(name, 64, 64)
        except:
            pixbuf = None
    if not pixbuf:
        while not (icon[index] in icons):
            index += 1
            if index >= len(icon):
                icon_name = "unknown"
                break
        if not icon_name:
            icon_name = icon[index]
    return pixbuf, icon_name
コード例 #34
0
ファイル: icon_finder.py プロジェクト: ju1ius/uxdgmenu
 def content_type_get_choices(self, mime_type):
     """Returns a list of possible icon names for a given mime type"""
     return gio.content_type_get_icon(mime_type).get_names()
コード例 #35
0
ファイル: blabrowsers.py プロジェクト: nkoep/blaplay
    def __update_directory(self, directory=None, refresh=False,
                           add_to_history=True):
        if not refresh:
            if directory is None:
                print_w("Directory must not be None")
                return False
            directory = os.path.expanduser(directory)
            # Got a relative path?
            if not os.path.isabs(directory):
                directory = os.path.join(self.__directory, directory)
            if not os.path.exists(directory):
                blaguiutils.error_dialog(
                    "Could not find \"%s\"." % directory,
                    "Please check the spelling and try again.")
                return False
            self.__directory = directory
            self.__entry.set_text(self.__directory)
            blacfg.set("general", "filesystem.directory", self.__directory)
            if add_to_history:
                self.__history.add(self.__directory)

        # FIXME: don't use gtk's model filter capabilities
        # TODO: keep the selection after updating the model
        model = self.__filt.get_model()
        self.__treeview.freeze_child_notify()
        model.clear()

        for dirpath, dirnames, filenames in os.walk(self.__directory):
            for d in sorted(dirnames, key=str.lower):
                if d.startswith("."):
                    continue
                path = os.path.join(self.__directory, d)
                model.append([path, self.__pixbufs["directory"], d])

            for f in sorted(filenames, key=str.lower):
                if f.startswith("."):
                    continue
                path = os.path.join(self.__directory, f)
                # TODO: use this instead (profile the overhead first though):
                #         f = gio.File(path)
                #         info = f.query_info("standard::content-type")
                #         mimetype = info.get_content_type()
                mimetype = gio.content_type_guess(path)
                try:
                    pb = self.__pixbufs[mimetype]
                except KeyError:
                    icon_names = gio.content_type_get_icon(mimetype)
                    pb = self.__pixbufs["file"]
                    if icon_names:
                        for icon_name in icon_names.get_names():
                            pb_new = self.__get_pixbuf(icon_name)
                            if pb_new:
                                self.__pixbufs[mimetype] = pb_new
                                pb = pb_new
                model.append([path, pb, f])
            break

        try:
            self.__monitor.cancel()
        except AttributeError:
            pass

        # FIXME: this seems to cease working after handling an event
        self.__monitor = gio.File(self.__directory).monitor_directory(
            flags=gio.FILE_MONITOR_NONE)
        self.__monitor.connect("changed", self.__process_event)

        self.__treeview.thaw_child_notify()
        return False
コード例 #36
0
ファイル: node.py プロジェクト: rjw57/wood
	def icon(self):
		return gio.content_type_get_icon(self.content_type())