6
Utility functions for working with icons.
14
logger = logging.getLogger("Icon")
16
def clear_icon_cache():
17
"""Clear the icon cache, garbage collecting all the icons."""
19
for key, icon in icon_cache:
24
def load_icon(name, size = 48):
25
"""Loads an icon from the default icon theme."""
27
if (name, size) in icon_cache:
28
return icon_cache[(name, size)]
31
theme = gtk.icon_theme_get_default()
32
icon = theme.load_icon(name, size, gtk.ICON_LOOKUP_FORCE_SVG)
33
icon_cache[(name, size)] = icon
36
logger.exception("failed to load_icon")
39
def load_icon_from_file(path, size = 48):
40
"""Loads an icon from the given path."""
42
if (path, size) in icon_cache:
43
return icon_cache[(path, size)]
46
icon = gtk.gdk.pixbuf_new_from_file_at_size(path, size, size)
47
icon_cache[(path, size)] = icon
50
logger.exception("failed to load_icon_from_file")