~markjtully/icon-library/gtk3

« back to all changes in this revision

Viewing changes to trunk/editor.py

  • Committer: Matthew McGowan
  • Date: 2009-09-27 11:31:55 UTC
  • Revision ID: matthew.joseph.mcgowan@gmail.com-20090927113155-1bvwq76xp4daem6f
on loading of iconset properties actually check the filesystem for discoverable icons as some themes report more (or less) than actually exists.  A note is displayed at the bottom of the properties dialog if there is a mismatch between reported and discoverable icons in the set

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
        self.notebook.set_size_request(300, -1)
33
33
        self.notebook.set_scrollable(True)
34
34
 
 
35
        self.dialog.set_border_width(3)
35
36
        self.dialog.vbox.pack_start(self.header, padding=6)
36
37
        self.dialog.vbox.pack_start(self.notebook, padding=8)
37
38
        return
39
40
    def run(self, Theme, IconDB, Store, iconset_data):
40
41
        context = iconset_data[2]
41
42
        name = iconset_data[1]
42
 
 
43
 
        iconset = ()
44
 
        sizes = list(Theme.get_icon_sizes(name))
45
 
        sizes.sort()
46
 
 
47
 
        if sizes[0] == -1:
48
 
            del sizes[0]
49
 
            sizes += "scalable",
 
43
        sizes, msizes = self.get_sizes(Theme, name)
50
44
 
51
45
        self.header.set_markup(
52
46
            "<b>%s</b>\n<span size=\"small\">%s - %s</span>" % (name, Theme.info[1], context)
53
47
            )
54
48
        self.header.set_justify(gtk.JUSTIFY_CENTER)
55
49
 
 
50
        iconset = ()
56
51
        l_color = self.dialog.get_style().text[gtk.STATE_INSENSITIVE].to_string()
57
 
        for size in sizes:
 
52
        for size in msizes:
58
53
            Icon = self.make_and_append_page(
59
54
                Theme,
60
55
                context,
64
59
                )
65
60
            if Icon: iconset += Icon,
66
61
 
 
62
        if len(sizes) != len(msizes):
 
63
            note = gtk.Label()
 
64
            note.set_line_wrap(True)
 
65
            note.set_markup("<small><b>Note</b>: There is a mismatch between the reported and discoverable sizes for this icon-set.\nSizes discovered: %s\nSizes reported by Gtk: %s</small>" % (msizes, sizes))
 
66
            self.dialog.vbox.pack_start(note, False, padding=3)
 
67
 
67
68
        self.dialog.vbox.show_all()
68
69
        response = self.dialog.run()
69
70
        self.dialog.destroy()
70
71
        return
71
72
 
 
73
    def get_sizes(self, Theme, name):
 
74
        theme_sizes = list(Theme.get_icon_sizes(name))
 
75
 
 
76
        path = Theme.lookup_icon(name, 24, 0).get_filename()
 
77
        if self.is_size_context_fstruct(path):
 
78
            manual_sizes = self.size_context_manually_find_sizes(path, name)
 
79
        else:
 
80
            manual_sizes = self.context_size_manually_find_sizes(path, name)
 
81
 
 
82
        theme_sizes.sort()
 
83
        manual_sizes.sort()
 
84
        return theme_sizes, manual_sizes
 
85
 
 
86
    def is_size_context_fstruct(self, path):
 
87
        search_path = '/'+os.path.join(*path.split('/')[:-3])
 
88
 
 
89
        is_digit = False
 
90
        i = 0
 
91
        for f in os.listdir(search_path):
 
92
            p = os.path.join(search_path, f)
 
93
            if os.path.isdir(p) and f[0].isdigit():
 
94
                if i > 2:
 
95
                    break
 
96
                is_digit = True
 
97
                break
 
98
            elif os.path.isdir(p):
 
99
                i += 1
 
100
 
 
101
        return is_digit
 
102
 
 
103
    def size_context_manually_find_sizes(self, path, name):
 
104
        search_path = '/'+os.path.join(*path.split('/')[:-3])
 
105
        ctx = path.split('/')[-2]
 
106
 
 
107
        manual_sizes = []
 
108
        for f in os.listdir(search_path):
 
109
            d = os.path.join(search_path, f, ctx)
 
110
            if os.path.isdir(d):
 
111
                for fn in os.listdir(d):
 
112
                    if os.path.splitext(fn)[0] == name:
 
113
                        manual_sizes.append(self.parse_size(f))
 
114
        return manual_sizes
 
115
 
 
116
    def context_size_manually_find_sizes(self, path, name):
 
117
        search_path = '/'+os.path.join(*path.split('/')[:-2])
 
118
        manual_sizes = []
 
119
        for f in os.listdir(search_path):
 
120
            d = os.path.join(search_path, f)
 
121
            if os.path.isdir(d):
 
122
                for fn in os.listdir(d):
 
123
                    if os.path.splitext(fn)[0] == name:
 
124
                        manual_sizes.append(self.parse_size(f))
 
125
        return manual_sizes
 
126
 
 
127
    def parse_size(self, size):
 
128
        if isinstance(size, int) or size == 'scalable':
 
129
            return size
 
130
        try:
 
131
            size = int(size)
 
132
            return size
 
133
        except:
 
134
            pass
 
135
        try:
 
136
            size = int(size.split('x')[0])
 
137
            return size
 
138
        except:
 
139
            print 'Size not parsable:', size
 
140
        return size
 
141
 
72
142
    def make_and_append_page(self, Theme, context, name, size, l_color):
73
 
        if type(size) == int:
 
143
        if isinstance(size, int):
74
144
            path = Theme.lookup_icon(name, size, 0).get_filename()
 
145
            pixbuf = Theme.load_icon(name, size, 0)
75
146
            tab_label = "%sx%s" % (size, size)
76
147
        else:
77
148
            path = Theme.lookup_icon(name, 64, gtk.ICON_LOOKUP_FORCE_SVG).get_filename()
 
149
            pixbuf = Theme.load_icon(name, 64, gtk.ICON_LOOKUP_FORCE_SVG)
78
150
            tab_label = size
79
151
 
80
152
        Icon = IconInfo(l_color)
83
155
            context,
84
156
            name,
85
157
            size,
86
 
            path
 
158
            path,
 
159
            pixbuf
87
160
            )
88
161
 
89
162
        info_table = Icon.get_table()
188
261
            table.attach(r_label, 1, 2, i, j, xpadding=10, ypadding=3)
189
262
        return
190
263
 
191
 
    def set_info(self, theme, context, name, size, path):
 
264
    def set_info(self, theme, context, name, size, path, pixbuf):
192
265
        self.theme = theme
193
266
        self.context = context
194
267
        self.name = name
195
268
        self.size = size
196
269
        self.path = path
 
270
        self.pixbuf = pixbuf
197
271
        self.target = None
198
272
 
199
 
        self.preview = IconPreview(path, size)
 
273
        self.preview = IconPreview(pixbuf)
200
274
        self.update_table(path)
201
275
        return
202
276