-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidgetTreeViewTk.py
More file actions
43 lines (29 loc) · 1.56 KB
/
WidgetTreeViewTk.py
File metadata and controls
43 lines (29 loc) · 1.56 KB
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
from Tkinter import *
import ttk
import pdb
class WidgetTreeViewTk:
def __init__(self, parent):
self.treeView = ttk.Treeview(parent.graphFrame )
self.icons = { "processing_unit": PhotoImage(file="icons/cogs.gif").subsample(2,2),
"container": PhotoImage(file="icons/box.gif").subsample(2,2),
"platform": PhotoImage(file="icons/platform.gif").subsample(2,2),
"component": PhotoImage(file="icons/component.gif").subsample(2,2)}
self.treeView.pack(side = LEFT, expand = 1,fill=BOTH )
self.callbackParent = parent
def clickHandler(self, event):
self.callbackParent.reportNewObject(self.treeView.focus())
def childEntry(self, parent, currentLevel):
for elem in currentLevel:
currentNode = self.treeView.insert(parent, 0, parent+"/"+elem['name'], text=elem['name'], image=self.icons[elem['type']], open = 1 )
if elem['type'] == 'container' or elem['type'] == "platform":
self.childEntry(currentNode, elem['child'])
# listOfDevices contains a hierarchy of dictionaries
# which represent the platform organization
def openDirectory(self, listOfDevices = {}):
# Dirty hack to get the platform element display to conform
listOfDevices[0]['type'] = "platform"
# end of hack
self.childEntry("", listOfDevices)
self.treeView.bind("<<TreeviewSelect>>", self.clickHandler)
def clear(self):
self.treeView.delete(*self.treeView.get_children())