From a2e5b9308e08637afc3eeb3bd9a6b0634e1b7fe1 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Fri, 23 Feb 2007 17:08:37 +0100 Subject: [PATCH] Rename color property in CanvasIcon to xo-color and added properties fill-color and stroke-color. --- shell/view/BuddyIcon.py | 4 +- shell/view/frame/ActivitiesBox.py | 8 +-- shell/view/frame/ZoomBox.py | 2 +- shell/view/home/FriendView.py | 4 +- shell/view/home/HomeBox.py | 7 +- shell/view/home/MeshBox.py | 2 +- shell/view/home/MyIcon.py | 2 +- shell/view/home/activitiesdonut.py | 6 +- sugar/activity/activity.py | 2 +- sugar/graphics/canvasicon.py | 104 +++++++++++++++++++---------- sugar/graphics/color.py | 13 +++- sugar/graphics/iconbutton.py | 15 ++--- sugar/graphics/menu.py | 2 +- tests/test-snowflake-box.py | 4 +- tests/test-spread-box.py | 2 +- 15 files changed, 108 insertions(+), 69 deletions(-) diff --git a/shell/view/BuddyIcon.py b/shell/view/BuddyIcon.py index 5ca9e8be..0d32eba4 100644 --- a/shell/view/BuddyIcon.py +++ b/shell/view/BuddyIcon.py @@ -20,7 +20,7 @@ from view.BuddyMenu import BuddyMenu class BuddyIcon(CanvasIcon): def __init__(self, shell, menu_shell, buddy): CanvasIcon.__init__(self, icon_name='theme:stock-buddy', - color=buddy.get_color()) + xo_color=buddy.get_color()) self._shell = shell self._buddy = buddy @@ -30,7 +30,7 @@ class BuddyIcon(CanvasIcon): def _buddy_presence_change_cb(self, buddy, color=None): # Update the icon's color when the buddy comes and goes - self.set_property('color', buddy.get_color()) + self.props.xo_color = buddy.get_color() def set_popup_distance(self, distance): self._popup_distance = distance diff --git a/shell/view/frame/ActivitiesBox.py b/shell/view/frame/ActivitiesBox.py index 8041a621..8fcddf86 100644 --- a/shell/view/frame/ActivitiesBox.py +++ b/shell/view/frame/ActivitiesBox.py @@ -31,12 +31,6 @@ class ActivityButton(IconButton): self._activity = activity self._popup_context = popup_context - def _mouse_motion_event_cb(self, item, event): - if event.detail == hippo.MOTION_DETAIL_ENTER: - self.set_property('color', self._prelight_color) - elif event.detail == hippo.MOTION_DETAIL_LEAVE: - self.set_property('color', self._normal_color) - def get_bundle_id(self): return self._activity.get_service_name() @@ -47,7 +41,7 @@ class InviteButton(IconButton): def __init__(self, activity, invite): IconButton.__init__(self, icon_name=activity.get_icon()) - self.props.color = activity.get_color() + self.props.xo_color = activity.get_color() self._invite = invite def get_activity_id(self): diff --git a/shell/view/frame/ZoomBox.py b/shell/view/frame/ZoomBox.py index 0cb0c34a..2ba46b8e 100644 --- a/shell/view/frame/ZoomBox.py +++ b/shell/view/frame/ZoomBox.py @@ -48,7 +48,7 @@ class ActivityButton(IconButton): icon_name = self._activity_model.get_icon_name() icon_color = self._activity_model.get_icon_color() - IconButton.__init__(self, icon_name=icon_name, color=icon_color) + IconButton.__init__(self, icon_name=icon_name, xo_color=icon_color) def get_popup(self): menu = ActivityMenu(self._activity_model) diff --git a/shell/view/home/FriendView.py b/shell/view/home/FriendView.py index c84cee54..d0273a7d 100644 --- a/shell/view/home/FriendView.py +++ b/shell/view/home/FriendView.py @@ -70,7 +70,7 @@ class FriendView(hippo.CanvasBox): name = self._get_new_icon_name(activity) if name: self._activity_icon.props.icon_name = name - self._activity_icon.props.color = buddy.get_color() + self._activity_icon.props.xo_color = buddy.get_color() if not self._activity_icon_visible: self.append(self._activity_icon, hippo.PACK_EXPAND) self._activity_icon_visible = True @@ -85,4 +85,4 @@ class FriendView(hippo.CanvasBox): self._buddy_activity_changed_cb(buddy, None) def _buddy_color_changed_cb(self, buddy, color): - self._activity_icon.props.color = buddy.get_color() + self._activity_icon.props.xo_color = buddy.get_color() diff --git a/shell/view/home/HomeBox.py b/shell/view/home/HomeBox.py index 0d5f999d..a7936cf6 100644 --- a/shell/view/home/HomeBox.py +++ b/shell/view/home/HomeBox.py @@ -19,6 +19,7 @@ import math import hippo from sugar.graphics import units +from sugar.graphics import color from sugar.graphics.xocolor import XoColor from view.home.activitiesdonut import ActivitiesDonut @@ -59,7 +60,11 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem): if self._donut: self.remove(self._donut) self._donut = None - self._my_icon.props.color = XoColor('insensitive') + self._my_icon.props.stroke_color = color.BUTTON_INACTIVE + self._my_icon.props.fill_color = \ + color.BUTTON_INACTIVE_BACKGROUND + self._my_icon.props.background_color = \ + color.BUTTON_INACTIVE_BACKGROUND def do_allocate(self, width, height, origin_changed): hippo.CanvasBox.do_allocate(self, width, height, origin_changed) diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index 2c6947cc..b8ff3eae 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -33,7 +33,7 @@ class ActivityView(SnowflakeBox): self._icons = {} icon = CanvasIcon(icon_name=model.get_icon_name(), - color=model.get_color(), box_width=80) + xo_color=model.get_color(), box_width=80) icon.connect('activated', self._clicked_cb) self.append(icon, hippo.PACK_FIXED) self.set_root(icon) diff --git a/shell/view/home/MyIcon.py b/shell/view/home/MyIcon.py index 6fa36b60..91b1d4c9 100644 --- a/shell/view/home/MyIcon.py +++ b/shell/view/home/MyIcon.py @@ -21,4 +21,4 @@ class MyIcon(CanvasIcon): def __init__(self, scale): CanvasIcon.__init__(self, scale=scale, icon_name='theme:stock-buddy', - color=profile.get_color()) + xo_color=profile.get_color()) diff --git a/shell/view/home/activitiesdonut.py b/shell/view/home/activitiesdonut.py index 6c411ae2..455fbaa6 100644 --- a/shell/view/home/activitiesdonut.py +++ b/shell/view/home/activitiesdonut.py @@ -55,7 +55,7 @@ class ActivityIcon(CanvasIcon): self._level = self._level_max color = self._icon_colors[self._level] - CanvasIcon.__init__(self, icon_name=icon_name, color=color, + CanvasIcon.__init__(self, icon_name=icon_name, xo_color=color, scale=units.MEDIUM_ICON_SCALE, cache=True) self._activity = activity @@ -103,7 +103,7 @@ class ActivityIcon(CanvasIcon): self._direction = 1 self._level = 0 - self.props.color = self._icon_colors[self._level] + self.props.xo_color = self._icon_colors[self._level] self.emit_paint_needed(0, 0, -1, -1) return True @@ -113,7 +113,7 @@ class ActivityIcon(CanvasIcon): self._launched = True self.cleanup() self._level = 100.0 - self.props.color = self._orig_color + self.props.xo_color = self._orig_color self.emit_paint_needed(0, 0, -1, -1) def get_launched(self): diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index 3e039882..54589ff1 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -105,4 +105,4 @@ class Activity(gtk.Window): self._pservice.unregister_service(self._service) def get_bundle_path(): - return os.environ['SUGAR_BUNDLE_BUNDLE_PATH'] + return os.environ['SUGAR_BUNDLE_PATH'] diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 7cf1ed24..2f7e8925 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -27,29 +27,28 @@ import time from sugar.graphics.timeline import Timeline from sugar.graphics.popup import Popup from sugar.graphics import color +from sugar.graphics.xocolor import XoColor from sugar.graphics import font from sugar.graphics import units class _IconCacheIcon: - def __init__(self, name, color, now): + def __init__(self, name, fill_color, stroke_color, now): self.data_size = None - self.handle = self._read_icon_data(name, color) + self.handle = self._read_icon_data(name, fill_color, stroke_color) self.last_used = now self.usage_count = 1 - def _read_icon_data(self, filename, color): + def _read_icon_data(self, filename, fill_color, stroke_color): icon_file = open(filename, 'r') data = icon_file.read() icon_file.close() - if color: - fill = color.get_fill_color() - stroke = color.get_stroke_color() - - entity = '' % fill + if fill_color: + entity = '' % fill_color data = re.sub('', entity, data) - entity = '' % stroke + if stroke_color: + entity = '' % stroke_color data = re.sub('', entity, data) self.data_size = len(data) @@ -104,15 +103,15 @@ class _IconCache: self._cache_size -= self._icons[evict_key].data_size del self._icons[evict_key] - def get_handle(self, name, color): + def get_handle(self, name, fill_color, stroke_color): if name == None: return None if name[0:6] == "theme:": name = self._get_real_name_from_theme(name[6:]) - if color: - key = (name, color.to_string()) + if fill_color or stroke_color: + key = (name, fill_color, stroke_color) else: key = name @@ -125,7 +124,7 @@ class _IconCache: icon.usage_count += 1 icon.last_used = now else: - icon = _IconCacheIcon(name, color, now) + icon = _IconCacheIcon(name, fill_color, stroke_color, now) self._icons[key] = icon self._cache_size += icon.data_size return icon.handle @@ -135,17 +134,21 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): __gtype_name__ = 'CanvasIcon' __gproperties__ = { - 'icon-name': (str, None, None, None, - gobject.PARAM_READWRITE), - 'color' : (object, None, None, - gobject.PARAM_READWRITE), - 'scale' : (float, None, None, - 0.0, 1024.0, 1.0, - gobject.PARAM_READWRITE), - 'cache' : (bool, None, None, False, - gobject.PARAM_READWRITE), - 'tooltip' : (str, None, None, None, - gobject.PARAM_READWRITE) + 'icon-name' : (str, None, None, None, + gobject.PARAM_READWRITE), + 'xo-color' : (object, None, None, + gobject.PARAM_READWRITE), + 'fill-color' : (object, None, None, + gobject.PARAM_READWRITE), + 'stroke-color' : (object, None, None, + gobject.PARAM_READWRITE), + 'scale' : (float, None, None, + 0.0, 1024.0, 1.0, + gobject.PARAM_READWRITE), + 'cache' : (bool, None, None, False, + gobject.PARAM_READWRITE), + 'tooltip' : (str, None, None, None, + gobject.PARAM_READWRITE) } _cache = _IconCache() @@ -154,7 +157,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self._buffers = {} self._cur_buffer = None self._scale = 1.0 - self._color = None + self._fill_color = None + self._stroke_color = None self._icon_name = None self._cache = False self._handle = None @@ -186,12 +190,23 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self._icon_name = value self._handle = None self.emit_paint_needed(0, 0, -1, -1) - elif pspec.name == 'color': - if self._color != value and not self._cache: - self._clear_buffers() - self._color = value - self._handle = None - self.emit_paint_needed(0, 0, -1, -1) + elif pspec.name == 'xo-color': + self.props.fill_color = color.HTMLColor(value.get_fill_color()) + self.props.stroke_color = color.HTMLColor(value.get_stroke_color()) + elif pspec.name == 'fill-color': + if self._fill_color != value: + if not self._cache: + self._clear_buffers() + self._fill_color = value + self._handle = None + self.emit_paint_needed(0, 0, -1, -1) + elif pspec.name == 'stroke-color': + if self._stroke_color != value: + if not self._cache: + self._clear_buffers() + self._stroke_color = value + self._handle = None + self.emit_paint_needed(0, 0, -1, -1) elif pspec.name == 'scale': if self._scale != value and not self._cache: self._clear_buffers() @@ -205,19 +220,38 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): def _get_handle(self): if not self._handle: cache = CanvasIcon._cache - self._handle = cache.get_handle(self._icon_name, self._color) + + fill_color = None + if self._fill_color: + fill_color = self._fill_color.get_html() + + stroke_color = None + if self._stroke_color: + stroke_color = self._stroke_color.get_html() + + self._handle = cache.get_handle(self._icon_name, fill_color, + stroke_color) return self._handle def _get_current_buffer_key(self): - return (self._icon_name, self._color, self._scale) + return (self._icon_name, self._fill_color, self._stroke_color, self._scale) def do_get_property(self, pspec): if pspec.name == 'scale': return self._scale elif pspec.name == 'icon-name': return self._icon_name - elif pspec.name == 'color': - return self._color + elif pspec.name == 'xo-color': + if self._stroke_color and self._fill_color: + xo_color = XoColor('%s,%s' % (self._stroke_color.get_html(), + self._fill_color.get_html())) + return xo_color + else: + return None + elif pspec.name == 'fill-color': + return self._fill_color + elif pspec.name == 'stroke-color': + return self._stroke_color elif pspec.name == 'cache': return self._cache elif pspec.name == 'tooltip': diff --git a/sugar/graphics/color.py b/sugar/graphics/color.py index b18b2ce2..a52b1ff0 100644 --- a/sugar/graphics/color.py +++ b/sugar/graphics/color.py @@ -60,11 +60,18 @@ class RGBColor(object): return gtk.gdk.Color(int(self._r * 65535), int(self._g * 65535), int(self._b * 65535)) -class SystemColor(RGBColor): - def __init__(self, color_id): - rgb = _html_to_rgb(_system_colors[color_id]) + def get_html(self): + return '#%x%x%x' % (self._r * 255, self._g * 255, self._b * 255) + +class HTMLColor(RGBColor): + def __init__(self, html_color): + rgb = _html_to_rgb(html_color) RGBColor.__init__(self, *rgb) +class SystemColor(HTMLColor): + def __init__(self, color_id): + HTMLColor.__init__(self, _system_colors[color_id]) + RED = RGBColor(1.0, 0.0, 0.0) GREEN = RGBColor(0.0, 1.0, 0.0) BLUE = RGBColor(0.0, 0.0, 1.0) diff --git a/sugar/graphics/iconbutton.py b/sugar/graphics/iconbutton.py index 78196d08..568d6ef1 100644 --- a/sugar/graphics/iconbutton.py +++ b/sugar/graphics/iconbutton.py @@ -44,14 +44,13 @@ class IconButton(CanvasIcon): CanvasIcon.__init__(self, cache=True, **kwargs) - if self.props.color: - self._normal_color = self.props.color - else: - self._normal_color = XoColor('white') - self.props.color = self._normal_color - self._prelight_color = profile.get_color() self._inactive_color = XoColor('#808080,#424242') + self._normal_color = XoColor('white') + + if not self.props.xo_color: + self.props.xo_color = self._normal_color + self._set_size(STANDARD_SIZE) self.connect('button-press-event', self._button_press_event_cb) @@ -74,9 +73,9 @@ class IconButton(CanvasIcon): elif pspec.name == 'active': self._active = value if self._active: - self.props.color = self._normal_color + self.props.xo_color = self._normal_color else: - self.props.color = self._inactive_color + self.props.xo_color = self._inactive_color else: CanvasIcon.do_set_property(self, pspec, value) diff --git a/sugar/graphics/menu.py b/sugar/graphics/menu.py index 0f154701..e60bd61a 100644 --- a/sugar/graphics/menu.py +++ b/sugar/graphics/menu.py @@ -49,7 +49,7 @@ class MenuItem(hippo.CanvasBox): icon = CanvasIcon(icon_name=icon_name, scale=units.SMALL_ICON_SCALE) if icon_color: - icon.props.color = icon_color + icon.props.xo_color = icon_color self.append(icon) self._canvas_text = hippo.CanvasText(text=label) diff --git a/tests/test-snowflake-box.py b/tests/test-snowflake-box.py index abbc79d4..50f849a0 100755 --- a/tests/test-snowflake-box.py +++ b/tests/test-snowflake-box.py @@ -33,14 +33,14 @@ from sugar.graphics.canvasicon import CanvasIcon def _create_snowflake(parent, children): color = XoColor() - icon = CanvasIcon(size=40, color=color, + icon = CanvasIcon(size=40, xo_color=color, icon_name='activity-groupchat') parent.append(icon, hippo.PACK_FIXED) parent.set_root(icon) for i in range(0, children): color = XoColor() - icon = CanvasIcon(size=60, color=color, + icon = CanvasIcon(size=60, xo_color=color, icon_name='stock-buddy') parent.append(icon, hippo.PACK_FIXED) diff --git a/tests/test-spread-box.py b/tests/test-spread-box.py index ba774c40..f7270944 100755 --- a/tests/test-spread-box.py +++ b/tests/test-spread-box.py @@ -33,7 +33,7 @@ from sugar.graphics.canvasicon import CanvasIcon def _create_icon(): color = XoColor() - icon = CanvasIcon(size=100, color=color, + icon = CanvasIcon(size=100, xo_color=color, icon_name='stock-buddy') box.add_item(icon)