[hamster-applet/gnome-2-32] avoid label echoing redraws by fighting set width versus measured (massive CPU hog that was exposed
- From: Toms Baugis <tbaugis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet/gnome-2-32] avoid label echoing redraws by fighting set width versus measured (massive CPU hog that was exposed
- Date: Fri, 10 Sep 2010 23:07:15 +0000 (UTC)
commit c080213c575b35e3f54c6c098b7a9fa42fcc7afe
Author: Toms Bauģis <toms baugis gmail com>
Date: Sat Sep 11 00:07:07 2010 +0100
avoid label echoing redraws by fighting set width versus measured (massive CPU hog that was exposed in the totals window when)
src/hamster/graphics.py | 38 +++++++++++++++++++++-----------------
1 files changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/src/hamster/graphics.py b/src/hamster/graphics.py
index 4a6c5df..08a4ffd 100644
--- a/src/hamster/graphics.py
+++ b/src/hamster/graphics.py
@@ -618,31 +618,29 @@ class Label(Sprite):
def __setattr__(self, name, val):
- Sprite.__setattr__(self, name, val)
+ if self.__dict__.get(name, "hamster_graphics_no_value_really") != val:
+ if name == "width" and val and self.__dict__.get('_bounds_width') and val * pango.SCALE == self.__dict__['_bounds_width']:
+ return
- if name == "width":
- # setting width means consumer wants to contrain the label
- if val is None or val == -1:
- self.__dict__['_bounds_width'] = -1
- else:
- self.__dict__['_bounds_width'] = val * pango.SCALE
+ Sprite.__setattr__(self, name, val)
- if name in ("width", "text", "size", "font_desc", "wrap", "ellipsize"):
- # avoid chicken and egg
- if "text" in self.__dict__ and "size" in self.__dict__ and "width" in self.__dict__:
- self._set_dimensions()
+ if name == "width":
+ # setting width means consumer wants to contrain the label
+ if val is None or val == -1:
+ self.__dict__['_bounds_width'] = -1
+ else:
+ self.__dict__['_bounds_width'] = val * pango.SCALE
+
+ if name in ("width", "text", "size", "font_desc", "wrap", "ellipsize"):
+ # avoid chicken and egg
+ if "text" in self.__dict__ and "size" in self.__dict__:
+ self._set_dimensions()
def on_render(self, sprite):
- self.graphics.clear()
if not self.text:
return
- if self.interactive: #if label is interactive, draw invisible bounding box for simple hit calculations
- self.graphics.set_color("#000", 0)
- self.graphics.rectangle(0,0, self.width, self.height)
- self.graphics.stroke()
-
self.graphics.set_color(self.color)
self.graphics.show_layout(self.text, self.font_desc,
self.alignment,
@@ -650,6 +648,12 @@ class Label(Sprite):
self.wrap,
self.ellipsize)
+ if self._bounds_width != -1:
+ rect_width = self._bounds_width / pango.SCALE
+ else:
+ rect_width = self.width
+ self.graphics.rectangle(0, 0, rect_width, self.height)
+
def _set_dimensions(self):
context = gtk.gdk.CairoContext(cairo.Context(cairo.ImageSurface(cairo.FORMAT_A1, 0, 0)))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]