-
Notifications
You must be signed in to change notification settings - Fork 215
/
Trees.py
102 lines (74 loc) · 2.68 KB
/
Trees.py
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
from pyjamas.ui.Tree import Tree
from pyjamas.ui.TreeItem import TreeItem
from pyjamas.ui.Composite import Composite
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.HTML import HTML
from pyjamas import Window
from pyjamas.JSONService import JSONProxy
class Trees(Composite):
def __init__(self):
Composite.__init__(self)
self.fProto = []
self.fTree = Tree()
self.fTree.addTreeListener(self)
self.initWidget(self.fTree)
self.remote = InfoServicePython()
self.remote.index("", 1, self)
def protoise_tree(self, data):
res = []
for i in range(len(data)):
d = data[i]
name = d[0]
children = d[1]
res.append(Proto(name, self.protoise_tree(children)))
return res
def create_tree(self, data):
self.fProto = self.protoise_tree(data)
for i in range(len(self.fProto)):
p = self.fProto[i]
p.pathify()
self.createItem(p)
self.fTree.addItem(p.item)
def onRemoteResponse(self, response, request_info):
if request_info.method == "index":
self.create_tree(response)
def onRemoteError(self, code, message, request_info):
RootPanel().add(HTML("Server Error or Invalid Response: ERROR " + code + " - " + message))
def onTreeItemSelected(self, item):
pass
def onTreeItemStateChanged(self, item):
child = item.getChild(0)
if hasattr(child, "isPendingItem"):
item.removeItem(child)
proto = item.getUserObject()
for i in range(len(proto.children)):
self.createItem(proto.children[i])
item.addItem(proto.children[i].item)
def createItem(self, proto):
proto.item = TreeItem(proto.text)
proto.item.setUserObject(proto)
if len(proto.children) > 0:
proto.item.addItem(PendingItem())
class Proto:
def __init__(self, text, children=None):
self.children = []
self.item = None
self.text = text
self.root = '/'
if children is not None:
self.children = children
def pathify(self):
""" cascade setup of full path
"""
for c in self.children:
c.root = self.root + self.text + "/"
c.pathify()
class PendingItem(TreeItem):
def __init__(self):
TreeItem.__init__(self, "Please wait...")
def isPendingItem(self):
return True
class InfoServicePython(JSONProxy):
def __init__(self):
JSONProxy.__init__(self, "/infoservice/EchoService.py",
["index"])