PageRenderTime 232ms CodeModel.GetById 90ms app.highlight 5ms RepoModel.GetById 136ms app.codeStats 0ms

/Demo/tkinter/guido/listtree.py

http://unladen-swallow.googlecode.com/
Python | 37 lines | 28 code | 6 blank | 3 comment | 5 complexity | 36660f6fe400f78573b6676911c38e6c MD5 | raw file
 1# List a remote app's widget tree (names and classes only)
 2
 3import sys
 4import string
 5
 6from Tkinter import *
 7
 8def listtree(master, app):
 9    list = Listbox(master, name='list')
10    list.pack(expand=1, fill=BOTH)
11    listnodes(list, app, '.', 0)
12    return list
13
14def listnodes(list, app, widget, level):
15    klass = list.send(app, 'winfo', 'class', widget)
16##      i = string.rindex(widget, '.')
17##      list.insert(END, '%s%s (%s)' % ((level-1)*'.   ', widget[i:], klass))
18    list.insert(END, '%s (%s)' % (widget, klass))
19    children = list.tk.splitlist(
20            list.send(app, 'winfo', 'children', widget))
21    for c in children:
22        listnodes(list, app, c, level+1)
23
24def main():
25    if not sys.argv[1:]:
26        sys.stderr.write('Usage: listtree appname\n')
27        sys.exit(2)
28    app = sys.argv[1]
29    tk = Tk()
30    tk.minsize(1, 1)
31    f = Frame(tk, name='f')
32    f.pack(expand=1, fill=BOTH)
33    list = listtree(f, app)
34    tk.mainloop()
35
36if __name__ == '__main__':
37    main()