From 766f9d6e6883822a4b3f76c73e7d7d5e124fb51e Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 28 Aug 2006 12:44:46 +0200 Subject: [PATCH] Use gproperties in IconItem, make the color optional --- shell/home/FriendsView.py | 9 ++++----- shell/home/HomeView.py | 3 ++- shell/home/MeshView.py | 3 ++- shell/panel/VerbsPanel.py | 4 ++-- sugar/canvas/IconItem.py | 34 ++++++++++++++++++++++++++++++---- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/shell/home/FriendsView.py b/shell/home/FriendsView.py index 4f0f365d..5f730a7f 100644 --- a/shell/home/FriendsView.py +++ b/shell/home/FriendsView.py @@ -7,13 +7,12 @@ import Theme class FriendIcon(IconItem): def __init__(self, friend): - IconItem.__init__(self, 'stock-buddy', friend.get_color(), 48) - + IconItem.__init__(self, icon_name='stock-buddy', + color=friend.get_color(), size=48, + x=random.random() * 1100, + y=random.random() * 800) self._friend = friend - self.set_property('x', random.random() * 1100) - self.set_property('y', random.random() * 800) - def get_friend(self): return self._friend diff --git a/shell/home/HomeView.py b/shell/home/HomeView.py index e1c6904e..d44bbeba 100644 --- a/shell/home/HomeView.py +++ b/shell/home/HomeView.py @@ -84,7 +84,8 @@ class Model(goocanvas.CanvasModelSimple): root.add_child(tasks) profile = sugar.conf.get_profile() - me = IconItem('stock-buddy', profile.get_color(), 150) + me = IconItem(icon_name = 'stock-buddy', + color = profile.get_color(), size = 150) me.translate(600 - (me.get_property('width') / 2), 450 - (me.get_property('height') / 2)) root.add_child(me) diff --git a/shell/home/MeshView.py b/shell/home/MeshView.py index d5c43277..fab4f289 100644 --- a/shell/home/MeshView.py +++ b/shell/home/MeshView.py @@ -14,7 +14,8 @@ class ActivityItem(IconItem): info = registry.get_activity(activity.get_type()) icon_name = info.get_icon() - IconItem.__init__(self, icon_name, activity.get_color(), 48) + IconItem.__init__(self, icon_name=icon_name, + color=activity.get_color(), size=48) self._activity = activity diff --git a/shell/panel/VerbsPanel.py b/shell/panel/VerbsPanel.py index 4c487691..ed4beb12 100644 --- a/shell/panel/VerbsPanel.py +++ b/shell/panel/VerbsPanel.py @@ -13,8 +13,8 @@ class ActivityItem(IconItem): if not icon_name: act_type = activity.get_default_type() raise RuntimeError("Actvity %s did not have an icon!" % act_type) - IconItem.__init__(self, icon_name, - IconColor('white'), size) + IconItem.__init__(self, icon_name=icon_name, + color=IconColor('white'), size=size) self._activity = activity def get_activity_id(self): diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index d402b5f6..f94be4c3 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