~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 18:14:49 UTC
  • Revision ID: daviddlowe.flimm@gmail.com-20110425181449-3tx8yr72yrokc7u7
Ported icon thumbnail generation from GNOME Control Center

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
METACITY_THUMBNAIL_HEIGHT = 60
22
22
GTK_THUMBNAIL_SIZE = 96
23
23
SKIN_THUMBNAIL_SIZE = 128
 
24
ICON_THUMBNAIL_SIZE = 48
24
25
 
25
 
def main():    
 
26
def main():
26
27
    
27
28
    parser = argparse.ArgumentParser(description="Generate Metacity or GTK or icon theme preview thumbnails")
28
29
    subparsers = parser.add_subparsers(dest='command', help='theme type')
223
224
    If outImage is specified, sys.exit will be called after the image is saved4
224
225
    
225
226
    """
226
 
    saved = False
227
 
    for sizefolder in ("scalable",  "64x64",  "48x48",  "32x32",  "24x24",  "22x22",  "16x16",  "12x12","8x8"):
228
 
        if themePath is None: break
229
 
        for folder in ("places",  "filesystems"):
230
 
            for icon in ("folder.svg",  "folder.png"):
231
 
                if os.path.exists(os.path.join(themePath,  sizefolder,  folder,  icon)):
232
 
                    pb = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(themePath,  sizefolder,  folder,  icon),  100,  100)
233
 
                    if outImage is None:
234
 
                        return pb
235
 
                    else:
236
 
                        pb.save(outImage,  "png")
237
 
                    saved =True
238
 
                    break
239
 
    if saved == False:
240
 
        icontheme = gtk.icon_theme_get_default()
241
 
        icc = icontheme.load_icon(gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_BUTTON, 0)
242
 
        if outImage is None:
243
 
            return icc
 
227
    # This code was ported from GNOME Control Center version 2.32.1,
 
228
    # released under the GPLv2, from theme-thumbnail.c
 
229
    # Modifications were made.
 
230
    
 
231
    with _ThemeNameCollisionResolver(themePath, "icon") as theme:
 
232
        
 
233
        icon_theme = gtk.IconTheme()
 
234
        icon_theme.set_custom_theme(theme.theme_name)
 
235
        
 
236
        icon_names = []
 
237
        example_icon_name = icon_theme.get_example_icon_name()
 
238
        if example_icon_name is not None:
 
239
            icon_names.append(example_icon_name)
 
240
        icon_names.extend(["x-directory-normal", "gnome-fs-directory", "folder"])
 
241
        
 
242
        folder_icon_info = icon_theme.choose_icon(icon_names, ICON_THUMBNAIL_SIZE, gtk.ICON_LOOKUP_FORCE_SIZE)
 
243
        
 
244
        folder_icon = None
 
245
        if folder_icon_info is not None:
 
246
            folder_icon = folder_icon_info.load_icon()
 
247
        
 
248
        if folder_icon is None:
 
249
            dummy = gtk.Label()
 
250
            folder_icon = dummy.render_icon(gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_DIALOG)
 
251
        
 
252
        if outImage:
 
253
            folder_icon.save(outImage, outImage.split(".")[-1].lower())
244
254
        else:
245
 
            icc.save(outImage,  "png")
246
 
            print >> sys.stderr, "missing"
247
 
            sys.exit(5)
248
 
    
249
 
    print "Done"
250
 
    sys.exit(0)
 
255
            return folder_icon
251
256
 
252
257
def skin_generate(outImage, gtkPath=None, iconPath=None, metacityPath=None, font=None):
253
258
    # This code was ported from GNOME Control Center version 2.32.1,
357
362
        if theme_path is None:
358
363
            self._theme_path = None
359
364
            return
 
365
        if not os.path.isdir(theme_path):
 
366
            raise(Exception("theme_path is not a directory: '%s'" % theme_path))
360
367
        self._theme_path = os.path.normpath(os.path.abspath(theme_path))
361
368
        self.theme_type = theme_type
362
369
        is_gtk = os.path.exists(os.path.join(self._theme_path, "gtk-2.0/gtkrc"))