From f7a1900d3d5313fd7adb96b3061734c80980c04b Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 10 Sep 2007 02:54:47 +0200 Subject: [PATCH] Do not redraw/resize if the properties doesn't actually change. In the Icon widget queue resize and redraw as appropriate. --- sugar/graphics/icon.py | 69 ++++++++++++++++++++++++++------------- sugar/graphics/xocolor.py | 6 ++++ 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/sugar/graphics/icon.py b/sugar/graphics/icon.py index 6c4d56a6..018a4282 100644 --- a/sugar/graphics/icon.py +++ b/sugar/graphics/icon.py @@ -78,6 +78,8 @@ class _IconBuffer(object): _loader = _SVGLoader() def __init__(self): + self._xo_color = None + self.icon_name = None self.file_name = None self.fill_color = None @@ -179,7 +181,10 @@ class _IconBuffer(object): return info - def set_xo_color(self, xo_color): + def _get_xo_color(self): + return self._xo_color + + def _set_xo_color(self, xo_color): if xo_color: self.stroke_color = xo_color.get_stroke_color() self.fill_color = xo_color.get_fill_color() @@ -187,6 +192,8 @@ class _IconBuffer(object): self.stroke_color = None self.fill_color = None + self._xo_color = xo_color + def get_surface(self): cache_key = self._get_cache_key() if cache_key in self._surface_cache: @@ -236,6 +243,8 @@ class _IconBuffer(object): return surface + xo_color = property(_get_xo_color, _set_xo_color) + class Icon(gtk.Image): __gtype_name__ = 'SugarIcon' @@ -317,13 +326,21 @@ class Icon(gtk.Image): def do_set_property(self, pspec, value): if pspec.name == 'xo-color': - self._buffer.set_xo_color(value) + if self._buffer.xo_color != value: + self._buffer.xo_color = value + self.queue_draw() elif pspec.name == 'fill-color': - self._buffer.fill_color = value + if self._buffer.fill_color != value: + self._buffer.fill_color = value + self.queue_draw() elif pspec.name == 'stroke-color': - self._buffer.stroke_color = value + if self._buffer.stroke_color != value: + self._buffer.stroke_color = value + self.queue_draw() elif pspec.name == 'badge-name': - self._buffer.badge_name = value + if self._buffer.badge_name != value: + self._buffer.badge_name = value + self.queue_resize() else: gtk.Image.do_set_property(self, pspec, value) @@ -370,32 +387,40 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): def do_set_property(self, pspec, value): if pspec.name == 'file-name': - self._buffer.file_name = value - self.emit_paint_needed(0, 0, -1, -1) + if self._buffer.file_name != value: + self._buffer.file_name = value + self.emit_paint_needed(0, 0, -1, -1) elif pspec.name == 'icon-name': - self._buffer.icon_name = value - self.emit_paint_needed(0, 0, -1, -1) + if self._buffer.icon_name != value: + self._buffer.icon_name = value + self.emit_paint_needed(0, 0, -1, -1) elif pspec.name == 'xo-color': - self._buffer.set_xo_color(value) - self.emit_paint_needed(0, 0, -1, -1) + if self._buffer.xo_color != value: + self._buffer.xo_color = value + self.emit_paint_needed(0, 0, -1, -1) elif pspec.name == 'fill-color': - self._buffer.fill_color = value - self.emit_paint_needed(0, 0, -1, -1) + if self._buffer.fill_color != value: + self._buffer.fill_color = value + self.emit_paint_needed(0, 0, -1, -1) elif pspec.name == 'stroke-color': - self._buffer.stroke_color = value - self.emit_paint_needed(0, 0, -1, -1) + if self._buffer.stroke_color != value: + self._buffer.stroke_color = value + self.emit_paint_needed(0, 0, -1, -1) elif pspec.name == 'size': - self._buffer.width = value - self._buffer.height = value - self.emit_request_changed() + if self._buffer.width != value: + self._buffer.width = value + self._buffer.height = value + self.emit_request_changed() elif pspec.name == 'scale': - self._buffer.scale = value - self.emit_request_changed() + if self._buffer.scale != value: + self._buffer.scale = value + self.emit_request_changed() elif pspec.name == 'cache': self._buffer.cache = value elif pspec.name == 'badge-name': - self._buffer.badge_name = value - self.emit_paint_needed(0, 0, -1, -1) + if self._buffer.badge_name != value: + self._buffer.badge_name = value + self.emit_paint_needed(0, 0, -1, -1) def do_get_property(self, pspec): if pspec.name == 'size': diff --git a/sugar/graphics/xocolor.py b/sugar/graphics/xocolor.py index ff5a2b5b..3f9fe313 100644 --- a/sugar/graphics/xocolor.py +++ b/sugar/graphics/xocolor.py @@ -223,6 +223,12 @@ class XoColor: else: [self._stroke, self._fill] = _parse_string(color_string) + def __cmp__(self, other): + if isinstance(other, XoColor): + return self._stroke == other._stroke and self._fill == other._fill + else: + return -1 + def get_stroke_color(self): return self._stroke