Subversion Repositories basico

Rev

Rev 4 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 74
Line 29... Line 29...
29
    for path in paths:
29
    for path in paths:
30
        if os.path.isfile(path):
30
        if os.path.isfile(path):
31
            return path
31
            return path
32
    return pkg_resources.resource_filename(
32
    return pkg_resources.resource_filename(
33
        pkg_resources.Requirement.parse("basico"), file_name)
33
        pkg_resources.Requirement.parse("basico"), file_name)
-
 
34
34
35
35
class IconManager(Service):
36
class IconManager(Service):
36
    def initialize(self):
37
    def initialize(self):
37
        APP_DIR_ICONS = self.app.get_var('ICONS')
38
        APP_DIR_ICONS = self.app.get_var('ICONS')
38
        self.icondict = {}
39
        self.icondict = {}
Line 40... Line 41...
40
        self.theme.prepend_search_path (APP_DIR_ICONS)
41
        self.theme.prepend_search_path (APP_DIR_ICONS)
41
42
42
    def get_themed_icon(self, icon_name):
43
    def get_themed_icon(self, icon_name):
43
        APP_DIR_ICONS = self.app.get_var('ICONS')
44
        APP_DIR_ICONS = self.app.get_var('ICONS')
44
        ICON = APP_DIR_ICONS + icon_name + '.png'
45
        ICON = APP_DIR_ICONS + icon_name + '.png'
45
        #~ self.log.debug(resource_filename(ICON))
-
 
46
        icon = Gio.ThemedIcon.new(ICON)
46
        icon = Gio.ThemedIcon.new(ICON)
47
        #~ self.log.debug(type(icon))
-
 
48
        #~ self.log.debug(dir(icon))
-
 
49
47
50
        return icon
48
        return icon
51
49
52
50
53
51
Line 55... Line 53...
55
        key = "%s-%d-%d" % (name, width, height)
53
        key = "%s-%d-%d" % (name, width, height)
56
54
57
        # Get icon from cache if exists or add a new one
55
        # Get icon from cache if exists or add a new one
58
        try:
56
        try:
59
            icon = self.icondict[key]
57
            icon = self.icondict[key]
-
 
58
            #~ print ("ICON TRY: %s: %s" % (type(icon), icon))
60
        except:
59
        except:
61
            #~ OLD WAY: icon = Pixbuf.new_from_file_at_scale(icon_name, width, height, True)
60
            #~ OLD WAY: icon = Pixbuf.new_from_file_at_scale(icon_name, width, height, True)
62
            iconinfo = self.theme.lookup_icon(name, width, Gtk.IconLookupFlags.GENERIC_FALLBACK)
61
            iconinfo = self.theme.lookup_icon(name, width, Gtk.IconLookupFlags.GENERIC_FALLBACK)
63
            icon = iconinfo.load_icon()
62
            icon = iconinfo.load_icon()
-
 
63
            #~ print ("ICON EXCEPT: %s: %s" % (type(icon), icon))
64
            self.icondict[key] = icon
64
            self.icondict[key] = icon
-
 
65
            #~ icon = None
65
        return icon
66
        return icon
66
67
67
68
68
    def get_pixbuf_icon(self, name, width=36, height=36):
69
    def get_pixbuf_icon(self, name, width=36, height=36):
69
        key = "%s-%d-%d" % (name, width, height)
70
        key = "%s-%d-%d" % (name, width, height)
70
71
71
        # Get icon from cache if exists or add a new one
72
        # Get icon from cache if exists or add a new one
72
        try:
73
        try:
73
            icon = self.icondict[key]
74
            icon = self.icondict[key]
74
        except:
75
        except:
-
 
76
            icon = None
75
            #~ OLD WAY: icon = Pixbuf.new_from_file_at_scale(icon_name, width, height, True)
77
            #~ OLD WAY: icon = Pixbuf.new_from_file_at_scale(icon_name, width, height, True)
76
            iconinfo = self.theme.lookup_icon(name, width, Gtk.IconLookupFlags.GENERIC_FALLBACK)
-
 
77
            icon = iconinfo.load_icon()
-
 
78
            self.icondict[key] = icon
-
 
-
 
78
            #~ fout = open('icons.txt', 'w')
-
 
79
            #~ for icon in self.theme.list_icons():
-
 
80
                #~ fout.write('%s\n' % icon)
-
 
81
            #~ fout.close()
-
 
82
            if name in self.theme.list_icons():
-
 
83
                return self.theme.load_icon(name, width, Gtk.IconLookupFlags.GENERIC_FALLBACK)
-
 
84
            #~ if self.theme.has_icon(name):
-
 
85
-
 
86
            #~ iconinfo = self.theme.lookup_icon(name, width, Gtk.IconLookupFlags.GENERIC_FALLBACK)
-
 
87
            #~ icon = iconinfo.load_icon()
-
 
88
            #~ self.icondict[key] = icon
79
        return icon
89
        return icon
80
90
81
91
82
    def get_image_icon(self, name, width=36, height=36):
92
    def get_image_icon(self, name, width=36, height=36):
83
        pixbuf = self.get_pixbuf_icon(name, width, height)
93
        pixbuf = self.get_pixbuf_icon(name, width, height)