summaryrefslogtreecommitdiff
path: root/rapid/common.py
diff options
context:
space:
mode:
authorJulien Valroff <julien@kirya.net>2010-07-11 09:01:25 +0200
committerJulien Valroff <julien@kirya.net>2010-07-11 09:01:25 +0200
commit9f2e1358d2c028c941b8be825522dd3351333710 (patch)
treed7907a5f1f41d206d8c3a7e49e55bfa0ce1f254f /rapid/common.py
parent1de9270ded0db955e309a21b8abc8981237fbc52 (diff)
Imported Upstream version 0.3.0upstream/0.3.0
Diffstat (limited to 'rapid/common.py')
-rw-r--r--rapid/common.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/rapid/common.py b/rapid/common.py
index d687049..a55d835 100644
--- a/rapid/common.py
+++ b/rapid/common.py
@@ -22,6 +22,11 @@ import sys
import gc
import distutils.version
import gtk.gdk as gdk
+import gtk
+try:
+ import gio
+except:
+ pass
import config
@@ -173,6 +178,45 @@ def scale2pixbuf(width_max, height_max, pixbuf, return_size=False):
return pixbuf, width_orig, height_orig
return pixbuf
+def get_icon_pixbuf(using_gio, icon, size, fallback='gtk-harddisk'):
+ """ returns icon for the volume, or None if not available"""
+
+ icontheme = gtk.icon_theme_get_default()
+
+ if using_gio:
+ f = None
+ if isinstance(icon, gio.ThemedIcon):
+ try:
+ # on some user's systems, themes do not have icons associated with them
+ iconinfo = icontheme.choose_icon(icon.get_names(), size, gtk.ICON_LOOKUP_USE_BUILTIN)
+ f = iconinfo.get_filename()
+ v = gtk.gdk.pixbuf_new_from_file_at_size(f, size, size)
+ except:
+ f = None
+ if not f:
+ v = icontheme.load_icon(fallback, size, gtk.ICON_LOOKUP_USE_BUILTIN)
+ else:
+ v = icontheme.load_icon(icon, size, gtk.ICON_LOOKUP_USE_BUILTIN)
+ return v
+
+def register_iconsets(icon_info):
+ """
+ Register icons in the icon set if they're not already used
+
+ From http://faq.pygtk.org/index.py?req=show&file=faq08.012.htp
+ """
+
+ iconfactory = gtk.IconFactory()
+ stock_ids = gtk.stock_list_ids()
+ for stock_id, file in icon_info:
+ # only load image files when our stock_id is not present
+ if stock_id not in stock_ids:
+ pixbuf = gtk.gdk.pixbuf_new_from_file(file)
+ iconset = gtk.IconSet(pixbuf)
+ iconfactory.add(stock_id, iconset)
+ iconfactory.add_default()
+
+
if __name__ == '__main__':