| 66 | | if PLATFORM == 'linux2': |
| 67 | | # FIXME: This naming scheme should be more consistent |
| 68 | | # All icon or all logo, and not mixed up |
| 69 | | for icon_name in icon_names[0:12]: |
| 70 | | file_path = os.path.join(pixmap_path, '%s.svg' % icon_name) |
| 71 | | (key, val) = ('%s_icon' % icon_name, file_path) |
| 72 | | if os.path.exists(file_path): |
| 73 | | log.debug('Register %s icon name for file %s' % (key, val)) |
| 74 | | icons.append(('%s_icon' % icon_name, file_path)) |
| | 56 | # This is a generator that returns file names for pixmaps in the order they |
| | 57 | # should be tried. |
| | 58 | def get_pixmap_file_names(icon_name, size): |
| | 59 | yield '%s.svg' % icon_name |
| | 60 | yield '%s_%s.png' % (icon_name, size) |
| | 61 | |
| | 62 | iconfactory = gtk.IconFactory() |
| | 63 | for icon_name in icon_names: |
| | 64 | for type, size in (('icon', '32'), ('logo', '75')): |
| | 65 | key = '%s_%s' % (icon_name, type) |
| | 66 | # Look for a usable image file. |
| | 67 | for file_name in get_pixmap_file_names(icon_name, size): |
| | 68 | file_path = os.path.join(pixmap_path, file_name) |
| | 69 | try: |
| | 70 | pixbuf = gtk.gdk.pixbuf_new_from_file(file_path) |
| | 71 | break |
| | 72 | except gobject.GError: |
| | 73 | # Try again. |
| | 74 | pass |
| 76 | | log.warn('Could not find %s file for icon name %s' % (val, key)) |
| 77 | | |
| 78 | | for icon_name in icon_names[12:]: |
| 79 | | file_path = os.path.join(pixmap_path, '%s.svg' % icon_name) |
| 80 | | (key, val) = ('%s_logo' % icon_name, file_path) |
| 81 | | if os.path.exists(file_path): |
| 82 | | log.debug('Register %s icon name for file %s' % (key, val)) |
| 83 | | icons.append(('%s_logo' % icon_name, file_path)) |
| 84 | | else: |
| 85 | | log.warning('Could not find %s file for icon name %s' % (val, key)) |
| 86 | | else: |
| 87 | | for icon_name in icon_names: |
| 88 | | for variant in (('icon', '32'), ('logo', '75')): |
| 89 | | #log.debug('Pixmap Path: %s' % pixmap_path) |
| 90 | | file_path = os.path.join(pixmap_path, '%s_%s.png' % (icon_name, variant[1])) |
| 91 | | (key, val) = ('%s_%s' % (icon_name, variant[0]), file_path) |
| 92 | | if os.path.exists(file_path): |
| 93 | | #log.debug('Register %s icon name for file %s' % (key, val)) |
| 94 | | icons.append((key, val)) |
| 95 | | else: |
| 96 | | log.warn('Could not find %s file for icon name %s' % (val, key)) |
| 97 | | |
| 98 | | |
| 99 | | iconfactory = gtk.IconFactory() |
| 100 | | |
| 101 | | for stock_id, file in icons: |
| 102 | | # only load image files when our stock_id is not present |
| 103 | | pixbuf = gtk.gdk.pixbuf_new_from_file(file) |
| 104 | | iconset = gtk.IconSet(pixbuf) |
| 105 | | iconfactory.add(stock_id, iconset) |
| | 76 | log.warn('Could not find the icon for %s at any of (%s) in %s' % (icon_name, ', '.join(get_pixmap_file_names(icon_name, size)), pixmap_path)) |
| | 77 | continue |
| | 78 | iconset = gtk.IconSet(pixbuf) |
| | 79 | iconfactory.add(key, iconset) |
| | 80 | log.debug('Register %s icon name for file %s' % (key, file_path)) |