From 1b869a04f8571fd2bb501d80667b5269db300b56 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 28 Feb 2007 19:53:06 +0100 Subject: [PATCH] Icon and Button fixes. --- sugar/graphics/canvasicon.py | 48 +++++++++++++++++++++++------------- sugar/graphics/color.py | 4 --- sugar/graphics/iconbutton.py | 25 ++----------------- 3 files changed, 33 insertions(+), 44 deletions(-) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 4b1134c6..3438c829 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -14,7 +14,7 @@ # License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. - +import logging import re import gobject @@ -137,7 +137,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): 'icon-name' : (str, None, None, None, gobject.PARAM_READWRITE), 'xo-color' : (object, None, None, - gobject.PARAM_READWRITE), + gobject.PARAM_WRITABLE), 'fill-color' : (object, None, None, gobject.PARAM_READWRITE), 'stroke-color' : (object, None, None, @@ -148,6 +148,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): 'cache' : (bool, None, None, False, gobject.PARAM_READWRITE), 'tooltip' : (str, None, None, None, + gobject.PARAM_READWRITE), + 'active' : (bool, None, None, True, gobject.PARAM_READWRITE) } @@ -165,6 +167,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self._popup = None self._hover_popup = False self._tooltip = False + self._active = True self._timeline = Timeline(self) self._timeline.add_tag('popup', 6, 6) @@ -216,38 +219,47 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self._cache = value elif pspec.name == 'tooltip': self._tooltip = value + elif pspec.name == 'active': + if self._active != value: + if not self._cache: + self._clear_buffers() + self._active = value + self._handle = None + self.emit_paint_needed(0, 0, -1, -1) + + def _choose_colors(self): + fill_color = None + stroke_color = None + if self._active: + if self._fill_color: + fill_color = self._fill_color.get_html() + if self._stroke_color: + stroke_color = self._stroke_color.get_html() + else: + stroke_color = color.ICON_STROKE_INACTIVE.get_html() + if self._fill_color: + fill_color = self._fill_color.get_html() + return [fill_color, stroke_color] def _get_handle(self): if not self._handle: cache = CanvasIcon._cache - fill_color = None - if self._fill_color: - fill_color = self._fill_color.get_html() + [fill_color, stroke_color] = self._choose_colors() - 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._fill_color, self._stroke_color, self._scale) + [fill_color, stroke_color] = self._choose_colors() + return (self._icon_name, fill_color, 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 == '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': @@ -256,6 +268,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): return self._cache elif pspec.name == 'tooltip': return self._tooltip + elif pspec.name == 'active': + return self._active def _get_icon_size(self): handle = self._get_handle() diff --git a/sugar/graphics/color.py b/sugar/graphics/color.py index 5ff4c928..068aa160 100644 --- a/sugar/graphics/color.py +++ b/sugar/graphics/color.py @@ -20,8 +20,6 @@ _system_colors = { 'button-background-normal' : '#424242', 'button-hover' : '#808080', 'button-background-hover' : '#000000', - 'button-inactive' : '#808080', - 'button-background-inactive' : '#424242', 'icon-stroke-inactive' : '#757575', 'icon-fill-inactive' : '#9D9FA1' } @@ -100,7 +98,5 @@ BUTTON_NORMAL = SystemColor('button-normal') BUTTON_BACKGROUND_NORMAL = SystemColor('button-background-normal') BUTTON_HOVER = SystemColor('button-hover') BUTTON_BACKGROUND_HOVER = SystemColor('button-background-hover') -BUTTON_INACTIVE = SystemColor('button-inactive') -BUTTON_BACKGROUND_INACTIVE = SystemColor('button-background-inactive') ICON_FILL_INACTIVE = SystemColor('icon-fill-inactive') ICON_STROKE_INACTIVE = SystemColor('icon-stroke-inactive') diff --git a/sugar/graphics/iconbutton.py b/sugar/graphics/iconbutton.py index fea02fbd..822ddf1f 100644 --- a/sugar/graphics/iconbutton.py +++ b/sugar/graphics/iconbutton.py @@ -33,26 +33,15 @@ class IconButton(CanvasIcon): __gproperties__ = { 'size' : (int, None, None, 0, sys.maxint, STANDARD_SIZE, - gobject.PARAM_READWRITE), - 'active' : (bool, None, None, True, gobject.PARAM_READWRITE) } def __init__(self, **kwargs): - self._active = True - CanvasIcon.__init__(self, cache=True, **kwargs) - if self._active: + if not self.props.fill_color and not self.props.stroke_color: self.props.fill_color = color.BUTTON_BACKGROUND_NORMAL self.props.stroke_color = color.BUTTON_NORMAL - self.props.background_color = \ - color.BUTTON_BACKGROUND_NORMAL.get_int() - else: - self.props.fill_color = color.BUTTON_BACKGROUND_INACTIVE - self.props.stroke_color = color.BUTTON_INACTIVE - self.props.background_color = \ - color.BUTTON_BACKGROUND_INACTIVE.get_int() self._set_size(STANDARD_SIZE) @@ -74,22 +63,12 @@ class IconButton(CanvasIcon): def do_set_property(self, pspec, value): if pspec.name == 'size': self._set_size(value) - elif pspec.name == 'active': - self._active = value - if self._active: - self.props.fill_color = color.BUTTON_BACKGROUND_NORMAL - self.props.stroke_color = color.BUTTON_NORMAL - else: - self.props.fill_color = color.BUTTON_BACKGROUND_INACTIVE - self.props.stroke_color = color.BUTTON_INACTIVE else: CanvasIcon.do_set_property(self, pspec, value) def do_get_property(self, pspec): if pspec.name == 'size': return self._size - elif pspec.name == 'active': - return self._active else: return CanvasIcon.do_get_property(self, pspec) @@ -100,7 +79,7 @@ class IconButton(CanvasIcon): def prelight(self, enter): if enter: - if self._active: + if self.props.active: self.props.background_color = color.BLACK.get_int() else: self.props.background_color = \