Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/treeview.py
blob: e255fa87e8140e083526505415b12a2c3e842758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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)

        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)

    def __name_edited_cb(self, cell_renderer, path, new_text):
        model = self._tree_view.props.model
        model.set(model.get_iter(path), 1, new_text)

    def __x_edited_cb(self, cell_renderer, path, new_text):
        model = self._tree_view.props.model
        model.set(model.get_iter(path), 2, float(new_text))

    def __y_edited_cb(self, cell_renderer, path, new_text):
        model = self._tree_view.props.model
        model.set(model.get_iter(path), 3, float(new_text))

    def __color_edited_cb(self, cell_renderer, path, new_text):
        model = self._tree_view.props.model
        model.set(model.get_iter(path), 4, new_text)