File: listtree.py

package info (click to toggle)
python2.3 2.3.5-3sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 43,908 kB
  • ctags: 81,384
  • sloc: ansic: 266,250; python: 246,028; makefile: 4,194; perl: 3,702; lisp: 3,630; sh: 2,576; xml: 1,601; objc: 740; cpp: 106; sed: 2
file content (37 lines) | stat: -rwxr-xr-x 902 bytes parent folder | download | duplicates (9)
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
# List a remote app's widget tree (names and classes only)

import sys
import string

from Tkinter import *

def listtree(master, app):
	list = Listbox(master, name='list')
	list.pack(expand=1, fill=BOTH)
	listnodes(list, app, '.', 0)
	return list

def listnodes(list, app, widget, level):
	klass = list.send(app, 'winfo', 'class', widget)
##	i = string.rindex(widget, '.')
##	list.insert(END, '%s%s (%s)' % ((level-1)*'.   ', widget[i:], klass))
	list.insert(END, '%s (%s)' % (widget, klass))
	children = list.tk.splitlist(
		list.send(app, 'winfo', 'children', widget))
	for c in children:
		listnodes(list, app, c, level+1)

def main():
	if not sys.argv[1:]:
		sys.stderr.write('Usage: listtree appname\n')
		sys.exit(2)
	app = sys.argv[1]
	tk = Tk()
	tk.minsize(1, 1)
	f = Frame(tk, name='f')
	f.pack(expand=1, fill=BOTH)
	list = listtree(f, app)
	tk.mainloop()

if __name__ == '__main__':
	main()