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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
"""
This file is part of the Ventoo program.
This 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 3 of the License, or
(at your option) any later version.
It 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 software. If not, see <http://www.gnu.org/licenses/>.
Copyright 2010 Christopher Harvey
"""
import sys
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import os.path as osp
import augeas_utils
class AugEditTree(gtk.TreeView):
def __init__(self):
#make storage enable/disable label user entry paint color
self.tv_store = gtk.TreeStore('gboolean', str, str, 'gboolean', str)
#make widget
gtk.TreeView.__init__(self, self.tv_store)
#make renderers
self.buttonRenderer = gtk.CellRendererToggle()
self.labelRenderer = gtk.CellRendererText()
self.entryRenderer = gtk.CellRendererText()
self.entryRenderer.set_property('background-set', True)
self.buttonRenderer.set_property("activatable", True)
self.entryRenderer.set_property("editable", True)
self.entryRenderer.connect("edited", self.entry_edited)
self.buttonRenderer.connect("toggled", self.entry_toggled)
#make columns
self.columnButton = gtk.TreeViewColumn('Enabled')
self.columnButton.pack_start(self.buttonRenderer, False)
self.columnLabel = gtk.TreeViewColumn('Label')
self.columnLabel.pack_start(self.labelRenderer, False)
self.columnEntry = gtk.TreeViewColumn('Data')
self.columnEntry.pack_start(self.entryRenderer, True)
self.columnButton.add_attribute(self.buttonRenderer, 'active', 0)
self.columnLabel.add_attribute(self.labelRenderer, 'text', 1)
self.columnEntry.add_attribute(self.entryRenderer, 'text', 2)
self.columnEntry.add_attribute(self.entryRenderer, 'background_set', 3)
self.columnEntry.add_attribute(self.entryRenderer, 'background', 4)
#add columns
self.append_column(self.columnButton)
self.append_column(self.columnLabel)
self.append_column(self.columnEntry)
gobject.signal_new("entry-edited",
AugEditTree,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING,
gobject.TYPE_STRING))
gobject.signal_new("entry-toggled",
AugEditTree,
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING,))
def entry_edited(self, cell, path, text):
#column = int(path)
self.tv_store[path][2] = text
self.emit("entry-edited", path, text)
def entry_toggled(self, cell, path):
#column = int(path)
self.tv_store[path][0] = not self.tv_store[path][0]
self.emit("entry-toggled", path)
"""
Returns a path in the form of a/b/c to the currently selected node.
"""
def getSelectedEntryPath(self):
currentSelection = self.get_selection()
if currentSelection.count_selected_rows()!=1:
raise RuntimeException("User selected more that one row from the file list...should never be possible.")
selectedSystemPathTuple = currentSelection.get_selected()
selectedIter = selectedSystemPathTuple[1]
return self.get_label_path(selectedIter)
"""
Gets a path of the form a/b/c where c is the
element pointed to by the iterator iter.
"""
def get_label_path(self, inputIter):
ret = ''
i = inputIter
while True:
ret = augeas_utils.stripBothSlashes(osp.join(self.tv_store.get_value(i, 1), ret))
i = self.tv_store.iter_parent(i)
if i == None:
break
return ret
"""
Same as get_label_path, except converts a string path to an
iterator for you.
"""
def get_label_path_str(self, path):
return self.get_label_path(self.tv_store.get_iter(path))
def addElement(self, parentIter, enabled, label, text):
return self.tv_store.append(parentIter, [enabled, label, text, False, '#C9C9C9'])
|