~flimm/epidermis/icon-theme-bugfix

« back to all changes in this revision

Viewing changes to epidermis/pigments/theme_preview.py

  • Committer: David D Lowe
  • Author(s): GNOME Control Center contributers, David D Lowe
  • Date: 2011-04-25 16:16:59 UTC
  • Revision ID: daviddlowe.flimm@gmail.com-20110425161659-46zlmh3iw1okr0np
Changed GTK thumbnailer to match GNOME Control Center

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
or:
15
15
 
16
 
GTK2_RC_FILES=/path/to/themename/gtk-2.0/gtkrcfiles python theme_preview.py gtk /path/out.png [/path/to/icondir]
 
16
(GTK disable in this revision)
17
17
 
18
18
or:
19
19
 
36
36
 
37
37
METACITY_THUMBNAIL_WIDTH = 120
38
38
METACITY_THUMBNAIL_HEIGHT = 60
39
 
 
40
 
def main():
 
39
GTK_THUMBNAIL_SIZE = 96
 
40
 
 
41
 
 
42
def main():    
41
43
    
42
44
    if len(sys.argv) < 3:
43
45
        print >> sys.stderr,  "Invalid command line arguments passed"
56
58
        else:
57
59
            icon_generate(themePath,  outImage)
58
60
    elif sys.argv[1] == "gtk":
59
 
        outImage = os.path.abspath(os.path.expanduser(sys.argv[2]))
60
 
        iconDir = None
61
 
        if len(sys.argv) > 3:
62
 
            iconDir = sys.argv[3]
63
 
        gtk_generate(outImage,  iconDir)
 
61
        raise(Exception("GTK disable in this revision"))
64
62
    elif sys.argv[1] == "multiple":
65
63
        outImage = os.path.abspath(os.path.expanduser(sys.argv[2]))
66
64
        opts = {}
199
197
    else:
200
198
        return None
201
199
 
202
 
def gtk_generate(outImage,  iconDir=None):
203
 
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
204
 
    window.connect("destroy",  lambda widget: sys.exit(1))
205
 
    window.resize(100, 35)
206
 
    window.set_property("skip-pager-hint", True)
207
 
    window.set_property("skip-taskbar-hint",  True)
208
 
    
209
 
    hbox = gtk.HBox()
210
 
    window.add(hbox)
211
 
    button = gtk.Button()
212
 
    button.set_label("_Abc")
213
 
    hbox.pack_start(button)
214
 
    chkbox = gtk.CheckButton()
215
 
    chkbox.set_active(True)
216
 
    hbox.pack_end(chkbox,  False)
217
 
    radiobox = gtk.RadioButton()
218
 
    hbox.pack_end(radiobox,  False)
219
 
    
220
 
    window.show_all()
221
 
 
222
 
    take_screenshot(hbox,  outImage)
223
 
    
224
 
    print "Done"
225
 
    sys.exit(0)
 
200
def gtk_generate(themePath, outImage):
 
201
    # This code was ported from GNOME Control Center version 2.32.1,
 
202
    # released under the GPLv2, from theme-thumbnail.c
 
203
    # Modifications were made.
 
204
    
 
205
    themePath = os.path.normpath(os.path.abspath(themePath))
 
206
    split = os.path.split(themePath)
 
207
    
 
208
    with _ThemeNameCollisionResolver(themePath, "gtk") as theme:
 
209
        load_gtk_theme(theme.theme_path, os.path.join(theme.theme_path, "gtk-2.0/gtkrc"))
 
210
        
 
211
        window = gtk.OffscreenWindow()
 
212
        
 
213
        vbox = gtk.VBox(False, 0)
 
214
        window.add(vbox)
 
215
        box = gtk.HBox(False, 0)
 
216
        box.set_border_width(6)
 
217
        vbox.pack_start(box, False, False, 0)
 
218
        stock_button = gtk.Button(stock=gtk.STOCK_OPEN)
 
219
        box.pack_start(stock_button, False, False, 0)
 
220
        checkbox = gtk.CheckButton()
 
221
        checkbox.set_active(True)
 
222
        box.pack_start(checkbox, False, False, 0)
 
223
        radio = gtk.RadioButton()
 
224
        box.pack_start(radio, False, False, 0)
 
225
        
 
226
        vbox.show_all()
 
227
        
 
228
        size = window.size_request()
 
229
        allocation = gtk.gdk.Rectangle(0, 0, size[0], size[1])
 
230
        window.size_allocate(allocation)
 
231
        window.size_request()
 
232
        
 
233
        size = window.get_size()
 
234
        window.show_all()
 
235
        
 
236
        window.window.process_updates(True)
 
237
        
 
238
        pb = window.get_pixbuf()
 
239
        
 
240
        pb = pb.scale_simple(GTK_THUMBNAIL_SIZE, int(GTK_THUMBNAIL_SIZE * (size[1] / float(size[0]))), gtk.gdk.INTERP_BILINEAR)
 
241
        pb.save(outImage, outImage.split(".")[-1].lower())
 
242
  
226
243
 
227
244
def icon_generate(themePath, outImage=None):
228
245
    """Return Pixbuf if outImage is None.