diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-28 10:44:46 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-28 10:44:46 (GMT) |
commit | 766f9d6e6883822a4b3f76c73e7d7d5e124fb51e (patch) | |
tree | 40dd230ad2c73780c59b5b036b9f1e06b2dffcdc /sugar | |
parent | 22e290332edc221f3020cb1d3f69dddc0c830af5 (diff) |
Use gproperties in IconItem, make the color optional
Diffstat (limited to 'sugar')
-rw-r--r-- | sugar/canvas/IconItem.py | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index d402b5f..f94be4c 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -51,9 +51,35 @@ class IconCache(gobject.GObject): return icon class IconItem(goocanvas.Image): - def __init__(self, icon_name, color, size, **kwargs): + __gproperties__ = { + 'icon-name': (str, None, None, None, + gobject.PARAM_CONSTRUCT_ONLY | + gobject.PARAM_READWRITE), + 'color' : (object, None, None, + gobject.PARAM_CONSTRUCT_ONLY | + gobject.PARAM_READWRITE), + 'size' : (int, None, None, + 0, 1024, 24, + gobject.PARAM_CONSTRUCT_ONLY | + gobject.PARAM_READWRITE) + } + + def do_set_property(self, pspec, value): + if pspec.name == 'icon-name': + self._icon_name = value + elif pspec.name == 'color': + self._color = value + elif pspec.name == 'size': + self._size = value + + def __init__(self, **kwargs): goocanvas.Image.__init__(self, **kwargs) - icon_cache = IconCache() - pixbuf = icon_cache.get_icon(icon_name, color, size) - self.set_property('pixbuf', pixbuf) + if self._color: + cache = IconCache() + pixbuf = cache.get_icon(self._icon_name, self._color, self._size) + self.props.pixbuf = pixbuf + else: + theme = gtk.icon_theme_get_default() + pixbuf = theme.load_icon(self._icon_name, self._size, 0) + self.props.pixbuf = pixbuf |