[hamster-applet] using one tag to paint them all and conserving valuable labels
- From: Toms Baugis <tbaugis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet] using one tag to paint them all and conserving valuable labels
- Date: Sat, 4 Dec 2010 00:18:38 +0000 (UTC)
commit cc84fc3bb282b78b69156e16f14acc20f7d9b3ed
Author: Toms Bauģis <toms baugis gmail com>
Date: Sat Dec 4 00:18:29 2010 +0000
using one tag to paint them all and conserving valuable labels
src/hamster/widgets/facttree.py | 20 ++++++------
src/hamster/widgets/tags.py | 61 +++++++++++++++++++++------------------
2 files changed, 43 insertions(+), 38 deletions(-)
---
diff --git a/src/hamster/widgets/facttree.py b/src/hamster/widgets/facttree.py
index a6296cd..a35b0a3 100644
--- a/src/hamster/widgets/facttree.py
+++ b/src/hamster/widgets/facttree.py
@@ -429,6 +429,8 @@ class FactCellRenderer(gtk.GenericCellRenderer):
default_font = gtk.Style().font_desc.to_string()
+ self.tag = Tag("")
+
self.selected_color = None
self.normal_color = None
@@ -591,27 +593,25 @@ class FactCellRenderer(gtk.GenericCellRenderer):
# otherwise move to the next line
tags_end = cell_start + cell_width
- tag = Tag(fact.tags[0])
-
- if x + tag.width > tags_end:
+ if x + self.tag.width > tags_end:
x = cell_start
y = self.activity_label.height + 4
for i, tag in enumerate(fact.tags):
- tag = Tag(tag)
+ self.tag.text = tag
- if x + tag.width >= tags_end:
+ if x + self.tag.width >= tags_end:
x = cell_start
- y += tag.height + 4
+ y += self.tag.height + 4
- tag.x, tag.y = x, y
+ self.tag.x, self.tag.y = x, y
if really:
- tag._draw(context)
+ self.tag._draw(context)
- x += tag.width + 4
+ x += self.tag.width + 4
- current_height = y + tag.height + 4
+ current_height = y + self.tag.height + 4
current_height = max(self.activity_label.height + 2, current_height)
diff --git a/src/hamster/widgets/tags.py b/src/hamster/widgets/tags.py
index 421863b..73aad5e 100644
--- a/src/hamster/widgets/tags.py
+++ b/src/hamster/widgets/tags.py
@@ -316,35 +316,40 @@ class Tag(graphics.Sprite):
font = gtk.Style().font_desc
font_size = int(font.get_size() * 0.8 / pango.SCALE) # 80% of default
- label = graphics.Label(self.text, size = font_size, color = (30, 30, 30), y = 1)
+ self.width, self.height = 0,0
- corner = int((label.height + 3) / 3) + 0.5
- label.x = corner + 6
+ self.label = graphics.Label(self.text, size = font_size, color = (30, 30, 30), y = 1)
+ self.corner = int((self.label.height + 3) / 3) + 0.5
+ self.label.x = self.corner + 6
+ self.color = color
+ self.add_child(self.label)
+
+
+ self.connect("on-render", self.on_render)
+
+ def __setattr__(self, name, value):
+ graphics.Sprite.__setattr__(self, name, value)
+ if name == 'text' and hasattr(self, 'label'):
+ self.label.text = value
+
+ def on_render(self, sprite):
+
+ w, h = int(self.label.x + self.label.width + self.label.height * 0.3), self.label.height + 3
+
+ self.graphics.set_line_style(width=1)
+
+ self.graphics.move_to(0.5, self.corner)
+ self.graphics.line_to([(self.corner, 0.5),
+ (w + 0.5, 0.5),
+ (w + 0.5, h - 0.5),
+ (self.corner, h - 0.5),
+ (0.5, h - self.corner)])
+ self.graphics.close_path()
+ self.graphics.fill_stroke(self.color, "#b4b4b4")
+
+ self.graphics.circle(6, h / 2, 2)
+ self.graphics.fill_stroke("#fff", "#b4b4b4")
- w, h = int(label.x + label.width + label.height * 0.3), label.height + 3
- self.color = color
- self.tag = graphics.Polygon([(0.5, corner),
- (corner, 0.5),
- (w + 0.5, 0.5),
- (w + 0.5, h - 0.5),
- (corner, h - 0.5),
- (0.5, h - corner)],
- fill = self.color,
- stroke = "#b4b4b4",
- line_width = 1, cache_as_bitmap = True)
-
- self.add_child(self.tag)
- self.add_child(graphics.Circle(3, 3, x = 2, y = h / 2 - 2,
- fill = "#fff",
- stroke = "#b4b4b4",
- line_width = 1,
- cache_as_bitmap = True))
-
- self.add_child(label)
- self.width, self.height = w, h
-
- self.graphics.set_color((0,0,0), 0)
- self.graphics.rectangle(0, 0, w, h)
- self.graphics.stroke()
+ self.__dict__['width'], self.__dict__['height'] = w, h
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]