diff options
Diffstat (limited to 'treeview.py')
-rw-r--r-- | treeview.py | 75 |
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) + |