Use gproperties in IconItem, make the color optional

This commit is contained in:
Marco Pesenti Gritti 2006-08-28 12:44:46 +02:00
parent 22e290332e
commit 766f9d6e68
5 changed files with 40 additions and 13 deletions

View File

@ -7,13 +7,12 @@ import Theme
class FriendIcon(IconItem): class FriendIcon(IconItem):
def __init__(self, friend): 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._friend = friend
self.set_property('x', random.random() * 1100)
self.set_property('y', random.random() * 800)
def get_friend(self): def get_friend(self):
return self._friend return self._friend

View File

@ -84,7 +84,8 @@ class Model(goocanvas.CanvasModelSimple):
root.add_child(tasks) root.add_child(tasks)
profile = sugar.conf.get_profile() 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), me.translate(600 - (me.get_property('width') / 2),
450 - (me.get_property('height') / 2)) 450 - (me.get_property('height') / 2))
root.add_child(me) root.add_child(me)

View File

@ -14,7 +14,8 @@ class ActivityItem(IconItem):
info = registry.get_activity(activity.get_type()) info = registry.get_activity(activity.get_type())
icon_name = info.get_icon() 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 self._activity = activity

View File

@ -13,8 +13,8 @@ class ActivityItem(IconItem):
if not icon_name: if not icon_name:
act_type = activity.get_default_type() act_type = activity.get_default_type()
raise RuntimeError("Actvity %s did not have an icon!" % act_type) raise RuntimeError("Actvity %s did not have an icon!" % act_type)
IconItem.__init__(self, icon_name, IconItem.__init__(self, icon_name=icon_name,
IconColor('white'), size) color=IconColor('white'), size=size)
self._activity = activity self._activity = activity
def get_activity_id(self): def get_activity_id(self):

View File

@ -51,9 +51,35 @@ class IconCache(gobject.GObject):
return icon return icon
class IconItem(goocanvas.Image): 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) goocanvas.Image.__init__(self, **kwargs)
icon_cache = IconCache() if self._color:
pixbuf = icon_cache.get_icon(icon_name, color, size) cache = IconCache()
self.set_property('pixbuf', pixbuf) 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