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-22 16:28:11 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-01-22 16:28:11 (GMT)
commit69bebc6b6f7fd0bb73bc0eda538b44eacda3fe59 (patch)
tree72f06bc0a8fdbeb5db7a225224d62127caf57652
parentc743c06c1ebd28198ab94bab736fb83ff31d3086 (diff)
Revert "Add links to the model"
This reverts commit c743c06c1ebd28198ab94bab736fb83ff31d3086.
-rw-r--r--model.py151
-rw-r--r--treeview.py10
-rw-r--r--view.py10
3 files changed, 45 insertions, 126 deletions
diff --git a/model.py b/model.py
index cefa1c7..2084773 100644
--- a/model.py
+++ b/model.py
@@ -15,7 +15,6 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging
-from gettext import gettext as _
import gobject
import gtk
@@ -26,46 +25,33 @@ from sugar import dispatch
class MindMapModel(gtk.GenericTreeModel):
_COLUMN_TYPES = (str, str, long, long, str)
-
- THOUGHTS = 0
- LINKS = 1
def __init__(self):
gobject.GObject.__init__(self)
- self._next_element_id = 2
+ self._next_thought_id = 0
self._thoughts_by_id = {}
self._thoughts = []
- self._links_by_id = {}
- self._links = []
def create_new_thought(self):
- thought = Thought(self._next_element_id)
- self._next_element_id += 1
+ thought = Thought(self._next_thought_id)
self._add_thought(thought)
def _add_thought(self, thought):
thought.changed.connect(self.__thought_changed_cb)
self._thoughts.append(thought)
self._thoughts_by_id[thought.id] = thought
+ self._next_thought_id += 1
- path = (self.THOUGHTS, len(self._thoughts) - 1)
+ path = (thought.id,)
self.row_inserted(path, self.get_iter(path))
- def get_thought(self, path):
- if isinstance(path, basestring):
- path = path.split(':')
- for i in range(len(path)):
- path[i] = int(path[i])
-
- if path[0] != self.THOUGHTS or path[1] >= len(path):
- raise ValueError('Invalid path %r' % (path,))
-
- return self._thoughts[path[1]]
+ def get_thought(self, thought_id):
+ return self._thoughts_by_id[int(thought_id)]
def __thought_changed_cb(self, **kwargs):
thought = kwargs['sender']
- path = (self.THOUGHTS, self._thoughts.index(thought))
+ path = (thought.id,)
self.row_changed(path, self.get_iter(path))
def get_thoughts(self):
@@ -88,8 +74,6 @@ class MindMapModel(gtk.GenericTreeModel):
thoughts = cjson.decode(data)['thoughts']
for thought_dict in thoughts:
thought = Thought(thought_dict['id'])
- self._next_element_id = max(self._next_element_id + 1,
- int(thought_dict['id']) + 1)
thought.name = thought_dict.get('name', None)
thought.x = thought_dict.get('x', None)
thought.y = thought_dict.get('y', None)
@@ -97,10 +81,7 @@ class MindMapModel(gtk.GenericTreeModel):
self._add_thought(thought)
# gtk.GenericTreeModel methods
- # paths are 0 for the THOUGHTS category, 1 for the LINKS category and the
- # position in their list for elements
- # rowrefs are 0 for the THOUGHTS category, 1 for the LINKS category and the
- # id for elements
+ # paths and rowrefs are the thought ids
def on_get_flags(self):
return gtk.TREE_MODEL_ITERS_PERSIST
@@ -111,124 +92,64 @@ class MindMapModel(gtk.GenericTreeModel):
return self._COLUMN_TYPES[n]
def on_get_iter(self, path):
- #logging.debug('on_get_iter %r %r' % (type(path), path))
-
- if len(path) == 1 and path[0] == self.THOUGHTS:
- return self.THOUGHTS
- elif len(path) == 1 and path[0] == self.LINKS:
- return self.LINKS
- elif path[0] == self.THOUGHTS:
- element_list = self._thoughts
- elif path[0] == self.LINKS:
- element_list = self._links
+ logging.debug('on_get_iter %r %r' % (type(path), path))
+ if path[0] in self._thoughts_by_id:
+ return path[0]
else:
return None
- if path[1] < len(element_list):
- return element_list[path[1]].id
- else:
- return None
-
def on_get_path(self, rowref):
logging.debug('on_get_path %r' % rowref)
- if rowref == self.THOUGHTS:
- return (self.THOUGHTS,)
- elif rowref == self.LINKS:
- return (self.LINKS,)
- elif rowref in self._thoughts_by_id:
- index = self._thoughts.index(self._thoughts_by_id[rowref])
- return (self.THOUGHTS, index,)
- elif rowref in self._links_by_id:
- index = self._links.index(self._links_by_id[rowref])
- return (self.LINKS, index,)
- else:
- return None
+ return (rowref,)
def on_get_value(self, rowref, column):
#logging.debug('on_get_value %r %r' % (rowref, column))
- if rowref == self.THOUGHTS and column == 1:
- return _('Thoughts')
- elif rowref == self.LINKS and column == 1:
- return _('Links')
- elif rowref in self._thoughts_by_id:
- element = self._thoughts_by_id[rowref]
- elif rowref in self._links_by_id:
- element = self._links_by_id[rowref]
- else:
+ if rowref >= len(self._thoughts):
return None
-
- value_tuple = element.get_tuple()
+ thought = self._thoughts[rowref]
+ value_tuple = thought.get_tuple()
return value_tuple[column]
def on_iter_next(self, rowref):
#logging.debug('on_iter_next %r' % rowref)
- if rowref == self.THOUGHTS:
- return self.LINKS
- if rowref in self._thoughts_by_id:
- element = self._thoughts_by_id[rowref]
- element_list = self._thoughts
- elif rowref in self._links_by_id:
- element = self._links_by_id[rowref]
- element_list = self._links
- else:
+ if rowref not in self._thoughts_by_id:
return None
+ thought = self._thoughts_by_id[rowref]
- index = element_list.index(element)
- if index + 1 >= len(element_list):
+ index = self._thoughts.index(thought)
+ if index + 1 >= len(self._thoughts):
return None
- next_element = element_list[index + 1]
- return next_element.id
+ next_thought = self._thoughts[index + 1]
+ #logging.debug('on_iter_next returning %r' % next_thought.id)
+ return next_thought.id
def on_iter_children(self, rowref):
- #logging.debug('on_iter_children %r' % rowref)
- if rowref is None:
- return self.THOUGHTS
- elif rowref == self.THOUGHTS and self._thoughts:
+ logging.debug('on_iter_children %r' % rowref)
+ if rowref:
+ return None
+ if self._thoughts:
return self._thoughts[0].id
- elif rowref == self.LINKS and self._links:
- return self._links[0].id
else:
return None
def on_iter_has_child(self, rowref):
- #logging.debug('on_iter_has_child %r' % rowref)
- if rowref == self.THOUGHTS and self._thoughts:
- return True
- elif rowref == self.LINKS and self._links:
- return True
- else:
- return False
+ return False
def on_iter_n_children(self, rowref):
- #logging.debug('on_iter_n_children %r' % rowref)
- if rowref == self.THOUGHTS:
- return len(self._thoughts)
- elif rowref == self.LINKS:
- return len(self._links)
- else:
+ logging.debug('on_iter_n_children %r' % rowref)
+ if rowref:
return 0
+ return len(self._thoughts)
def on_iter_nth_child(self, rowref, n):
- #logging.debug('on_iter_nth_child %r %r' % (rowref, n))
- if rowref is None and n == self.THOUGHTS:
- return self.THOUGHTS
- elif rowref is None and n == self.LINKS:
- return self.LINKS
- elif rowref == self.THOUGHTS and n < len(self._thoughts):
- return self._thoughts[n].id
- elif rowref == self.LINKS and n < len(self._links):
- return self._links[n].id
- else:
+ logging.debug('on_iter_nth_child %r %r' % (rowref, n))
+ if rowref is not None:
return None
+ if n < len(self._thoughts):
+ return self._thoughts[n].id
- def on_iter_parent(self, rowref):
- #logging.debug('on_iter_parent %r' % rowref)
- if rowref in self._thoughts_by_id:
- return self.THOUGHTS
- elif rowref in self._links_by_id:
- return self.LINKS
- else:
- return None
+ def on_iter_parent(child):
+ return None
class Thought(object):
diff --git a/treeview.py b/treeview.py
index 5016977..cec8562 100644
--- a/treeview.py
+++ b/treeview.py
@@ -29,8 +29,6 @@ class TreeView(gtk.ScrolledWindow):
self.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
self._tree_view = gtk.TreeView(model=model)
- self._tree_view.props.headers_visible = False
- self._tree_view.expand_all()
self.add(self._tree_view)
self._tree_view.show()
@@ -71,18 +69,18 @@ class TreeView(gtk.ScrolledWindow):
self.set_size_request(200, -1)
def __name_edited_cb(self, cell_renderer, path, new_text):
- thought = self._tree_view.props.model.get_thought(path)
+ thought = self._tree_view.props.model.get_thought(path[0])
thought.name = new_text
def __x_edited_cb(self, cell_renderer, path, new_text):
- thought = self._tree_view.props.model.get_thought(path)
+ thought = self._tree_view.props.model.get_thought(path[0])
thought.x = int(new_text)
def __y_edited_cb(self, cell_renderer, path, new_text):
- thought = self._tree_view.props.model.get_thought(path)
+ 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)
+ thought = self._tree_view.props.model.get_thought(path[0])
thought.color = new_text
diff --git a/view.py b/view.py
index 1ec7420..326ced8 100644
--- a/view.py
+++ b/view.py
@@ -108,14 +108,14 @@ class MindMapView(Canvas):
model = property(get_model, set_model)
def __row_inserted_cb(self, model, path, iter):
- logging.debug('__row_inserted_cb %r' % (path,))
+ logging.debug('__row_inserted_cb %r' % path)
- thought_model = model.get_thought(path)
+ thought_model = model.get_thought(path[0])
though_view = ThoughtView(thought_model)
self.add_element(though_view)
def __row_deleted_cb(self, model, path):
- logging.debug('__row_deleted_cb %r' % (path,))
+ logging.debug('__row_deleted_cb %r' % path)
though_view = self._get_though_by_id(path[0])
self.remove_element(though_view)
@@ -247,6 +247,6 @@ class ThoughtView(CanvasElement):
self._last_width = width + self._PADDING * 2
self._last_height = height + self._PADDING * 2
- return gtk.gdk.Rectangle(int(self.model.x), int(self.model.y),
- int(self._last_width), int(self._last_height))
+ return gtk.gdk.Rectangle(self.model.x, self.model.y,
+ self._last_width, self._last_height)