Do not redraw/resize if the properties doesn't actually change.

In the Icon widget queue resize and redraw as appropriate.
This commit is contained in:
Marco Pesenti Gritti 2007-09-10 02:54:47 +02:00
parent 97451c5466
commit f7a1900d3d
2 changed files with 53 additions and 22 deletions

View File

@ -78,6 +78,8 @@ class _IconBuffer(object):
_loader = _SVGLoader() _loader = _SVGLoader()
def __init__(self): def __init__(self):
self._xo_color = None
self.icon_name = None self.icon_name = None
self.file_name = None self.file_name = None
self.fill_color = None self.fill_color = None
@ -179,7 +181,10 @@ class _IconBuffer(object):
return info 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: if xo_color:
self.stroke_color = xo_color.get_stroke_color() self.stroke_color = xo_color.get_stroke_color()
self.fill_color = xo_color.get_fill_color() self.fill_color = xo_color.get_fill_color()
@ -187,6 +192,8 @@ class _IconBuffer(object):
self.stroke_color = None self.stroke_color = None
self.fill_color = None self.fill_color = None
self._xo_color = xo_color
def get_surface(self): def get_surface(self):
cache_key = self._get_cache_key() cache_key = self._get_cache_key()
if cache_key in self._surface_cache: if cache_key in self._surface_cache:
@ -236,6 +243,8 @@ class _IconBuffer(object):
return surface return surface
xo_color = property(_get_xo_color, _set_xo_color)
class Icon(gtk.Image): class Icon(gtk.Image):
__gtype_name__ = 'SugarIcon' __gtype_name__ = 'SugarIcon'
@ -317,13 +326,21 @@ class Icon(gtk.Image):
def do_set_property(self, pspec, value): def do_set_property(self, pspec, value):
if pspec.name == 'xo-color': 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': 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': 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': 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: else:
gtk.Image.do_set_property(self, pspec, value) 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): def do_set_property(self, pspec, value):
if pspec.name == 'file-name': if pspec.name == 'file-name':
self._buffer.file_name = value if self._buffer.file_name != value:
self.emit_paint_needed(0, 0, -1, -1) self._buffer.file_name = value
self.emit_paint_needed(0, 0, -1, -1)
elif pspec.name == 'icon-name': elif pspec.name == 'icon-name':
self._buffer.icon_name = value if self._buffer.icon_name != value:
self.emit_paint_needed(0, 0, -1, -1) self._buffer.icon_name = value
self.emit_paint_needed(0, 0, -1, -1)
elif pspec.name == 'xo-color': elif pspec.name == 'xo-color':
self._buffer.set_xo_color(value) if self._buffer.xo_color != value:
self.emit_paint_needed(0, 0, -1, -1) self._buffer.xo_color = value
self.emit_paint_needed(0, 0, -1, -1)
elif pspec.name == 'fill-color': elif pspec.name == 'fill-color':
self._buffer.fill_color = value if self._buffer.fill_color != value:
self.emit_paint_needed(0, 0, -1, -1) self._buffer.fill_color = value
self.emit_paint_needed(0, 0, -1, -1)
elif pspec.name == 'stroke-color': elif pspec.name == 'stroke-color':
self._buffer.stroke_color = value if self._buffer.stroke_color != value:
self.emit_paint_needed(0, 0, -1, -1) self._buffer.stroke_color = value
self.emit_paint_needed(0, 0, -1, -1)
elif pspec.name == 'size': elif pspec.name == 'size':
self._buffer.width = value if self._buffer.width != value:
self._buffer.height = value self._buffer.width = value
self.emit_request_changed() self._buffer.height = value
self.emit_request_changed()
elif pspec.name == 'scale': elif pspec.name == 'scale':
self._buffer.scale = value if self._buffer.scale != value:
self.emit_request_changed() self._buffer.scale = value
self.emit_request_changed()
elif pspec.name == 'cache': elif pspec.name == 'cache':
self._buffer.cache = value self._buffer.cache = value
elif pspec.name == 'badge-name': elif pspec.name == 'badge-name':
self._buffer.badge_name = value if self._buffer.badge_name != value:
self.emit_paint_needed(0, 0, -1, -1) self._buffer.badge_name = value
self.emit_paint_needed(0, 0, -1, -1)
def do_get_property(self, pspec): def do_get_property(self, pspec):
if pspec.name == 'size': if pspec.name == 'size':

View File

@ -223,6 +223,12 @@ class XoColor:
else: else:
[self._stroke, self._fill] = _parse_string(color_string) [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): def get_stroke_color(self):
return self._stroke return self._stroke