home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / tkinter / guido / listtree.py < prev    next >
Text File  |  1996-07-30  |  902b  |  38 lines

  1. # List a remote app's widget tree (names and classes only)
  2.  
  3. import sys
  4. import string
  5.  
  6. from Tkinter import *
  7.  
  8. def 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.  
  14. def 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.  
  24. def 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.  
  36. if __name__ == '__main__':
  37.     main()
  38.