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