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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
import gtk
import gobject
from gettext import gettext as _
class Data(gtk.TreeView):
__gsignals__ = {
'label-changed': (gobject.SIGNAL_RUN_FIRST, None, [str, str], ),
'value-changed': (gobject.SIGNAL_RUN_FIRST, None, [str, str], ), }
def __init__(self, activity):
gtk.TreeView.__init__(self)
self.model = gtk.ListStore(str, str)
self.set_model(self.model)
# Label column
column = gtk.TreeViewColumn(_("Label"))
label = gtk.CellRendererText()
label.set_property('editable', True)
label.connect("edited", self._label_changed, self.model)
column.pack_start(label)
column.set_attributes(label, text=0)
self.append_column(column)
# Value column
column = gtk.TreeViewColumn(_("Value"))
value = gtk.CellRendererText()
value.set_property('editable', True)
value.connect("edited", self._value_changed, self.model, activity)
column.pack_start(value)
column.set_attributes(value, text=1)
self.append_column(column)
self.set_enable_search(False)
self.show_all()
def add_value(self, label, value):
selected = self.get_selection().get_selected()[1]
if not selected:
path = 0
elif selected:
path = self.model.get_path(selected)[0] + 1
iter = self.model.insert(path, [label, value])
self.set_cursor(self.model.get_path(iter),
self.get_column(1),
True)
return path
def remove_selected_value(self):
path, column = self.get_cursor()
path = path[0]
model, iter = self.get_selection().get_selected()
self.model.remove(iter)
return path
def update_selected_value(self, data):
path, column = self.get_cursor()
path = path[0]
self.model[path][0] = data
#self.emit("label-changed", str(path), data)
print 'remover', path, column
return path
def _label_changed(self, cell, path, new_text, model):
model[path][0] = new_text
self.emit("label-changed", str(path), new_text)
def _value_changed(self, cell, path, new_text, model, activity):
model[path][1] = new_text
self.emit("value-changed", str(path), new_text)
def get_info(self):
l = []
for row in self.model:
name = row[1]
pos = row[0]
pos = pos.replace('(', '')
pos = pos.replace(')', '')
pos = pos.split(',')
pos = [float(pos[0]), float(pos[1])]
pos = (int(pos[0]), int(pos[1]))
l.append((name, pos))
return l
|