Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/treeview.py
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-01-19 18:32:45 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-01-19 18:32:45 (GMT)
commit8535ed6494b8ead86756c414ae9f305f35e25884 (patch)
tree4205b85dfc16e6b9aa57248a32dcc99941f1801e /treeview.py
Initial commit
Diffstat (limited to 'treeview.py')
-rw-r--r--treeview.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/treeview.py b/treeview.py
new file mode 100644
index 0000000..42fdbf4
--- /dev/null
+++ b/treeview.py
@@ -0,0 +1,75 @@
+# Copyright (C) 2009, Tomeu Vizoso
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import logging
+from gettext import gettext as _
+
+import gtk
+
+class TreeView(gtk.ScrolledWindow):
+ __gtype_name__ = 'MindMapTreeView'
+
+ def __init__(self, model):
+ gtk.ScrolledWindow.__init__(self)
+
+ self.props.hscrollbar_policy = gtk.POLICY_AUTOMATIC
+ self.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
+
+ self._tree_view = gtk.TreeView(model=model)
+ self.add(self._tree_view)
+ self._tree_view.show()
+
+ cell = gtk.CellRendererText()
+ column = gtk.TreeViewColumn(_('Id'), cell, text=0)
+ self._tree_view.append_column(column)
+
+ cell = gtk.CellRendererText()
+ cell.connect('edited', self.__name_edited_cb)
+ cell.props.editable = True
+
+ column = gtk.TreeViewColumn(_('Name'), cell, text=1)
+ self._tree_view.append_column(column)
+ self._tree_view.set_search_column(1)
+
+ cell = gtk.CellRendererText()
+ cell.connect('edited', self.__x_edited_cb)
+ cell.props.editable = True
+
+ column = gtk.TreeViewColumn(_('x'), cell, text=2)
+ self._tree_view.append_column(column)
+
+ cell = gtk.CellRendererText()
+ cell.connect('edited', self.__y_edited_cb)
+ cell.props.editable = True
+
+ column = gtk.TreeViewColumn(_('y'), cell, text=3)
+ self._tree_view.append_column(column)
+
+ # TODO: should be calculated based on the text size
+ 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[0])
+ thought.name = new_text
+
+ def __x_edited_cb(self, cell_renderer, path, new_text):
+ 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[0])
+ thought.y = int(new_text)
+