5
updated: March 26, 2011
7
Utility functions for working with icons.
11
from gi.repository import GdkPixbuf, Gtk
15
logger = logging.getLogger("Icon")
18
"""Clear the icon cache, garbage collecting all the icons."""
20
for key, icon in icon_cache:
25
def load(name, size = 48):
26
"""Loads an icon from the default icon theme."""
28
if (name, size) in icon_cache:
29
return icon_cache[(name, size)]
32
theme = Gtk.IconTheme.get_default()
33
icon = theme.load_icon(name, size, Gtk.IconLookupFlags.FORCE_SVG)
34
icon_cache[(name, size)] = icon
37
logger.exception("failed to load_icon")
40
def load_from_file(path, size = 48):
41
"""Loads an icon from the given path."""
43
if (path, size) in icon_cache:
44
return icon_cache[(path, size)]
47
icon = GdkPixbuf.Pixbuf.new_from_file_at_size(path, size, size)
48
icon_cache[(path, size)] = icon
51
logger.exception("failed to load_icon_from_file")