Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-01-24 16:51:28 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-01-24 16:51:28 (GMT)
commit7fc1f05973a16f9852d6c25d4f2484384747e00a (patch)
tree330f2a03200174828abf6a5a2f2283f87555d86a
parent9ee11dda200e1ae317d7ec9b919692f41fd39c52 (diff)
Add a '+' button to the thought view for adding a child thought
-rw-r--r--canvas.py29
-rw-r--r--thoughtview.py24
2 files changed, 46 insertions, 7 deletions
diff --git a/canvas.py b/canvas.py
index ca1beb8..ef9e31b 100644
--- a/canvas.py
+++ b/canvas.py
@@ -56,8 +56,6 @@ class Canvas(gtk.DrawingArea):
rect.x = 0
rect.y = 0
- logging.debug('__expose_event_cb1 %r %r %r %r' % (event.area.x, event.area.y,
- event.area.width, event.area.height))
context.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
context.clip()
@@ -67,7 +65,6 @@ class Canvas(gtk.DrawingArea):
for element in self._elements:
rect = element.get_rect()
- logging.debug('__expose_event_cb %r %r %r %r' % (rect.x, rect.y, rect.width, rect.height))
if rect.intersect(event.area):
context.save()
@@ -154,12 +151,19 @@ class Canvas(gtk.DrawingArea):
def __motion_notify_event_cb(self, widget, event):
if self._last_clicked_element is None:
- return True
+ for element in self._elements:
+ rect = element.get_rect()
+ if (event.x >= rect.x and event.x <= rect.x + rect.width) and \
+ (event.y >= rect.y and event.y <= rect.y + rect.height):
+ element.hovering = True
+ else:
+ element.hovering = False
+ return False
# if the mouse button is not pressed, no drag should occurr
if not event.state & gtk.gdk.BUTTON1_MASK:
self._cleanup_drag()
- return True
+ return False
if event.is_hint:
x, y, state_ = event.window.get_pointer()
@@ -169,7 +173,7 @@ class Canvas(gtk.DrawingArea):
if self._dragging:
self.dragging_motion.send(self, position=(x, y))
- return True
+ return False
logging.debug('motion_notify_event_cb')
@@ -181,12 +185,13 @@ class Canvas(gtk.DrawingArea):
self.dragging_started.send(self, position=(x, y),
element=self._last_clicked_element)
- return True
+ return False
class CanvasElement(object):
def __init__(self):
self.invalidated = dispatch.Signal()
self.previous_rect = gtk.gdk.Rectangle(0, 0, 0, 0)
+ self._hovering = False
def draw(self, context):
self.previous_rect = self.get_rect()
@@ -197,3 +202,13 @@ class CanvasElement(object):
def get_rect(self):
pass
+ def set_hovering(self, hovering):
+ if self._hovering != hovering:
+ self._hovering = hovering
+ self.invalidate()
+
+ def get_hovering(self):
+ return self._hovering
+
+ hovering = property(get_hovering, set_hovering)
+
diff --git a/thoughtview.py b/thoughtview.py
index 5d02365..cd79682 100644
--- a/thoughtview.py
+++ b/thoughtview.py
@@ -45,6 +45,7 @@ class ThoughtView(CanvasElement):
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:
@@ -84,6 +85,9 @@ class ThoughtView(CanvasElement):
width, height = self._draw_text(context)
self._draw_bounding_box(context, width, height)
+ if self.hovering:
+ self._draw_controls(context, width, height)
+
self._last_width = width
self._last_height = height
@@ -139,6 +143,26 @@ class ThoughtView(CanvasElement):
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()