ATLAS Offline Software
Loading...
Searching...
No Matches
PyPoolBrowser.py
Go to the documentation of this file.
1from idlelib import TreeWidget
2from PyKernel import PyKernel
3from Tkinter import *
4
5import re
6import time
7
8# import PyDataHeader and PyCLIDSvc
9import cppyy
10cppyy.load_library("libPyAnalysisCoreDict")
11
12
13
14# EDM item
15class EDMItem (TreeWidget.TreeItem):
16 # name : name of the object
17 # ref : reference to the object
18 # expandable : whether the object may be a leaf object
19 # classKey : key of the class to which this obj belongs
20 def __init__ (self, name, ref, expandable, classKey=None):
21 self.name = name
22 self.ref = ref
23 self.expandable = expandable
24 self.classKey = classKey
25
26 def GetText (self):
27 return self.name
28
29 def IsExpandable (self):
30 return self.expandable
31
32 def GetIconName(self):
33 if not self.IsExpandable():
34 return "python" # XXX wish there was a "file" icon
35
36 # execute plot command when double-click
37 def OnDoubleClick(self):
38 # not a leaf
39 if self.IsExpandable():
40 return
41 # doesn't belong to a class
42 if self.classKey == None:
43 return
44 # draw histogram
45 x = eval ('PyKernel.plot ("%s#%s", "$x.%s()")' % (objList[self.classKey], self.classKey, self.name))
46 # sleep is needed to draw up canvas
47 time.sleep(1)
48 # return is also needed. see PyKernel.plot
49 return x
50
51 # return list of items which belong to the object
52 def GetSubList (self):
53 sublist = []
54 # if a vector-like class
55 if hasattr(self.ref,'size') and hasattr(self.ref,'__getitem__'):
56 # use the fist one
57 if self.ref.size() != 0:
58 item = EDMItem ('%s constituents' % self.ref.size(),self.ref[0],True,self.classKey)
59 sublist.append(item)
60 return sublist
61 #others
62 else:
63 attrs=dir(self.ref)
64 attrs.sort()
65 for attr in attrs:
66 # private
67 if re.search(r"\A_",attr):
68 continue
69 # member
70 if re.search(r"\Am_",attr):
71 continue
72 # method
73 attrRef = getattr(self.ref,attr)
74 item = EDMItem (attr,attrRef,False,self.classKey)
75 sublist.append(item)
76 return sublist
77
78# Root Item
80 # override GetSubList
81 def GetSubList (self):
82 sublist = []
83 # get EDM objects
84 attrs=dir(self.ref)
85 attrs.sort()
86 for attr in attrs:
87 # private
88 if re.search(r"\A_",attr):
89 continue
90 # else
91 attrRef = getattr(self.ref,attr)
92 item = EDMItem (attr,attrRef,True,attr)
93 sublist.append(item)
94 return sublist
95
96
97
98# run 1 event to get DataHeader
99theApp.run(1)
100
101# get EDM/Key list from DataHeader
102dh = g.PyDataHeader()
103objList = {}
104for i in range(dh.size()):
105 objList[dh.getKey(i)] = dh.getName(i)
106
107# build Root object
109 pass
110
111rootObj = MyRootObj()
112
113# attach EDM objects to Root object if they are not in the ignore list
114for key in objList.keys():
115 name = objList[key]
116 try:
117 exec('con = PyKernel.retrieve(g.%s,"%s")' % (name, key))
118 setattr(rootObj,key, con)
119 except:
120 pass
121
122# start Tk session
123root=Tk()
124root.title(os.path.basename(sys.argv[0]))
125root.configure(bd=0)
126
127sc = TreeWidget.ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
128sc.frame.pack(expand=1, fill="both")
129item = RootItem('/',rootObj,True)
130item.GetText()
131node = TreeWidget.TreeNode(sc.canvas, None, item)
132node.update()
133
134root.mainloop()
__init__(self, name, ref, expandable, classKey=None)