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-20 18:09:38 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-01-20 18:09:38 (GMT)
commita4848bf6ea047b90cbd16712b2b3cb6c9747365c (patch)
tree713f94793a4416c9bf4e26b00f9a5a20a8d09a82
parentda678e141dd79422a799f89ef6bae4fa43a28b4b (diff)
Added background colors to the model and display them
-rw-r--r--model.py26
-rw-r--r--treeview.py11
-rw-r--r--view.py15
3 files changed, 46 insertions, 6 deletions
diff --git a/model.py b/model.py
index 75ad6a8..2084773 100644
--- a/model.py
+++ b/model.py
@@ -24,7 +24,7 @@ from sugar import dispatch
class MindMapModel(gtk.GenericTreeModel):
- _COLUMN_TYPES = (str, str, long, long)
+ _COLUMN_TYPES = (str, str, long, long, str)
def __init__(self):
gobject.GObject.__init__(self)
@@ -65,6 +65,7 @@ class MindMapModel(gtk.GenericTreeModel):
thought_dict['name'] = thought.name
thought_dict['x'] = thought.x
thought_dict['y'] = thought.y
+ thought_dict['color'] = thought.color
thoughts.append(thought_dict)
return cjson.encode({'thoughts': thoughts})
@@ -73,9 +74,10 @@ class MindMapModel(gtk.GenericTreeModel):
thoughts = cjson.decode(data)['thoughts']
for thought_dict in thoughts:
thought = Thought(thought_dict['id'])
- thought.name = thought_dict['name']
- thought.x = thought_dict['x']
- thought.y = thought_dict['y']
+ thought.name = thought_dict.get('name', None)
+ thought.x = thought_dict.get('x', None)
+ thought.y = thought_dict.get('y', None)
+ thought.color = thought_dict.get('color', None)
self._add_thought(thought)
# gtk.GenericTreeModel methods
@@ -151,18 +153,19 @@ class MindMapModel(gtk.GenericTreeModel):
class Thought(object):
- def __init__(self, thought_id, name=None, x=0, y=0):
+ def __init__(self, thought_id, name=None, x=0, y=0, color=None):
if thought_id is None:
raise ValueError('thought_id cannot be None')
self._id = thought_id
self._name = name
self._x = x
self._y = y
+ self._color = color
self.changed = dispatch.Signal()
def get_tuple(self):
- return (self.id, self.name, self.x, self.y)
+ return (self.id, self.name, self.x, self.y, self.color)
def set_id(self, new_id):
if self._id == new_id:
@@ -208,3 +211,14 @@ class Thought(object):
y = property(get_y, set_y)
+ def set_color(self, new_color):
+ if self._color == new_color:
+ return
+ self._color = new_color
+ self.changed.send(self)
+
+ def get_color(self):
+ return self._color
+
+ color = property(get_color, set_color)
+
diff --git a/treeview.py b/treeview.py
index 42fdbf4..cec8562 100644
--- a/treeview.py
+++ b/treeview.py
@@ -58,6 +58,13 @@ class TreeView(gtk.ScrolledWindow):
column = gtk.TreeViewColumn(_('y'), cell, text=3)
self._tree_view.append_column(column)
+ cell = gtk.CellRendererText()
+ cell.connect('edited', self.__color_edited_cb)
+ cell.props.editable = True
+
+ column = gtk.TreeViewColumn(_('Color'), cell, text=4)
+ self._tree_view.append_column(column)
+
# TODO: should be calculated based on the text size
self.set_size_request(200, -1)
@@ -73,3 +80,7 @@ class TreeView(gtk.ScrolledWindow):
thought = self._tree_view.props.model.get_thought(path[0])
thought.y = int(new_text)
+ def __color_edited_cb(self, cell_renderer, path, new_text):
+ thought = self._tree_view.props.model.get_thought(path[0])
+ thought.color = new_text
+
diff --git a/view.py b/view.py
index 8ba64ea..c4a1a3f 100644
--- a/view.py
+++ b/view.py
@@ -148,11 +148,25 @@ class ThoughtView(CanvasElement):
return layout
def draw(self, context):
+
+ # draw background
+ if self.model.color is None or not self.model.color:
+ color = style.Color('#FFFFFF')
+ else:
+ color = style.Color(self.model.color)
+
+ r, g, b, a = color.get_rgba()
+ context.save()
+ context.set_source_rgb(r, g, b)
+ context.paint()
+ context.restore()
+
if self._dragging:
context.set_source_rgb(0.8, 0.8, 0.8)
else:
context.set_source_rgb(0, 0, 0)
+ # draw text
context.save()
layout = self._get_name_layout(context)
@@ -166,6 +180,7 @@ class ThoughtView(CanvasElement):
context.show_layout(layout)
context.restore()
+ # draw bounding box
context.save()
context.set_line_width(4)