Added "0desktop --manage".
[zeroinstall/zeroinstall-mseaborn.git] / zeroinstall / gtkui / icon.py
blob7363b98f4041287eca03028dcfceb64cdbba3cf5
1 """Loading icons."""
2 # Copyright (C) 2008, Thomas Leonard
3 # See the README file for details, or visit http://0install.net.
5 import gtk
6 from logging import warn
8 def load_icon(icon_path):
9 """Load icon from path. Icon MUST be in PNG format.
10 @param icon_path: pathname of icon, or None to load nothing
11 @return: a GdkPixbuf, or None on failure"""
12 if not icon_path:
13 return None
14 try:
15 # Icon format must be PNG (to avoid attacks)
16 loader = gtk.gdk.PixbufLoader('png')
17 try:
18 loader.write(file(icon_path).read())
19 finally:
20 loader.close()
21 return loader.get_pixbuf()
22 except Exception, ex:
23 warn("Failed to load cached PNG icon: %s" % ex)
24 return None