Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/thoughtview.py
diff options
context:
space:
mode:
Diffstat (limited to 'thoughtview.py')
-rw-r--r--thoughtview.py168
1 files changed, 42 insertions, 126 deletions
diff --git a/thoughtview.py b/thoughtview.py
index cd79682..1651e09 100644
--- a/thoughtview.py
+++ b/thoughtview.py
@@ -23,153 +23,69 @@ import gtk
# We'd rather not depend on sugar in this class
from sugar.graphics import style
-from canvas import CanvasElement
+from gaphas.examples import Box, Text
-class ThoughtView(CanvasElement):
+class ThoughtView(Box):
_PADDING = style.zoom(15)
_LINE_WIDTH = style.zoom(2)
def __init__(self, thought_id, name, x, y, color):
- CanvasElement.__init__(self)
+ Box.__init__(self)
logging.debug('ThoughtView %r %r' % (thought_id, name))
self.id = thought_id
- self.name = name
- self.x = x
- self.y = y
- self.color = color
-
- self._last_width = -1
- self._last_height = -1
- self._dragging = False
- self._selected = False
- self._add_control_rect = gtk.gdk.Rectangle(0, 0, 0, 0)
-
- def set_dragging(self, dragging):
- if self._dragging != dragging:
- self._dragging = dragging
- self.invalidate()
-
- def get_dragging(self):
- return self._dragging
-
- dragging = property(get_dragging, set_dragging)
+ self._name = name
+ self._color = color
- def set_selected(self, selected):
- if self._selected != selected:
- self._selected = selected
- self.invalidate()
+ self.set_position(x, y)
- selected = property(None, set_selected)
+ def set_name(self, name):
+ if self._name != name:
+ self._name = name
+ self.request_update(update=True, matrix=True)
- def _get_name_layout(self, context=None):
- if context is None:
- visual = gtk.gdk.screen_get_default().get_system_visual()
- pixmap = gtk.gdk.Pixmap(None, 1, 1, visual.depth)
- context = pixmap.cairo_create()
+ def get_name(self):
+ return self._name
- if self.name is None or not self.name:
- name = _('Unnamed')
- else:
- name = self.name
+ name = property(get_name, set_name)
- layout = context.create_layout()
- layout.set_text(name)
+ def set_color(self, color):
+ if self._color != color:
+ self._color = color
+ self.request_update(update=True, matrix=True)
- return layout
+ def get_color(self):
+ return self._color
- def draw(self, context):
- self._draw_background(context)
- width, height = self._draw_text(context)
- self._draw_bounding_box(context, width, height)
+ color = property(get_color, set_color)
- if self.hovering:
- self._draw_controls(context, width, height)
+ def set_position(self, x, y):
+ if (x, y) != self.get_position():
+ self.matrix = (1.0, 0.0, 0.0, 1, x, y)
- self._last_width = width
- self._last_height = height
-
- CanvasElement.draw(self, context)
-
- def _draw_background(self, context):
- if self.color is None or not self.color:
- color = style.Color('#FFFFFF')
- else:
- color = style.Color(self.color)
+ def get_position(self):
+ return self.matrix[4], self.matrix[5]
- r, g, b, a = color.get_rgba()
- context.save()
- context.set_source_rgb(r, g, b)
- context.paint()
- context.restore()
+ position = property(get_position, set_position)
- def _draw_text(self, context):
- context.save()
-
- context.set_source_rgb(0.0, 0.0, 0.0)
-
- layout = self._get_name_layout(context)
+ def draw(self, context):
+ super(ThoughtView, self).draw(context)
+ self._draw_label(context)
- width, height = layout.get_pixel_size()
- width += self._PADDING * 2
- height += self._PADDING * 2
-
- x = self.x + self._PADDING
- y = self.y + self._PADDING
- context.translate(x, y)
- context.show_layout(layout)
- context.restore()
-
- return width, height
-
- def _draw_bounding_box(self, context, width, height):
- context.save()
-
- if self._selected or self._dragging:
- context.set_source_rgb(0.6, 0.6, 0.6)
- context.set_line_width(self._LINE_WIDTH * 2)
- else:
- context.set_source_rgb(0, 0, 0)
- context.set_line_width(self._LINE_WIDTH)
+ def _draw_label(self, context):
+ context.cairo.save()
+ layout = context.cairo.create_layout()
+ layout.set_text(self._name)
- x = self.x + self._LINE_WIDTH / 2
- y = self.y + self._LINE_WIDTH / 2
- rect_width = width - self._LINE_WIDTH
- rect_height = height - self._LINE_WIDTH
-
- context.rectangle(x, y, rect_width, rect_height)
- context.stroke()
- context.restore()
-
- def _draw_controls(self, context, width, height):
- context.save()
-
- context.set_source_rgb(0.0, 0.0, 0.0)
-
- layout = context.create_layout()
- layout.set_text('+')
-
- label_width, label_height = layout.get_pixel_size()
-
- x = self.x + width - label_width
- y = self.y
- context.translate(x, y)
- context.show_layout(layout)
-
- context.restore()
-
- self._add_control_rect = gtk.gdk.Rectangle(x, y, label_width,
- label_height)
-
- def get_rect(self):
- if -1 in (self._last_width, self._last_height):
- layout = self._get_name_layout()
- width, height = layout.get_pixel_size()
- self._last_width = width + self._PADDING * 2
- self._last_height = height + self._PADDING * 2
-
- return gtk.gdk.Rectangle(self.x, self.y,
- self._last_width, self._last_height)
+ width, height = layout.get_pixel_size()
+ self.width = width + self._PADDING * 2
+ self.height = height + self._PADDING * 2
+
+ x = self._PADDING
+ y = self._PADDING
+ context.cairo.translate(x, y)
+ context.cairo.show_layout(layout)
+ context.cairo.restore()