Issue #6615: logging: Used weak references in internal handler list. Thanks to flox...
[python.git] / Demo / tix / samples / SHList1.py
blob7ca7b3e7fbbf0306b960f8846f9445f0e03aad6b
1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3 # $Id$
5 # Tix Demostration Program
7 # This sample program is structured in such a way so that it can be
8 # executed from the Tix demo program "tixwidgets.py": it must have a
9 # procedure called "RunSample". It should also have the "if" statment
10 # at the end of this file so that it can be run as a standalone
11 # program using tixwish.
13 # This file demonstrates the use of the tixScrolledHList widget.
16 import Tix
18 TCL_ALL_EVENTS = 0
20 def RunSample (root):
21 shlist = DemoSHList(root)
22 shlist.mainloop()
23 shlist.destroy()
25 class DemoSHList:
26 def __init__(self, w):
27 self.root = w
28 self.exit = -1
30 z = w.winfo_toplevel()
31 z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
33 # We create the frame and the ScrolledHList widget
34 # at the top of the dialog box
36 top = Tix.Frame( w, relief=Tix.RAISED, bd=1)
38 # Put a simple hierachy into the HList (two levels). Use colors and
39 # separator widgets (frames) to make the list look fancy
41 top.a = Tix.ScrolledHList(top)
42 top.a.pack( expand=1, fill=Tix.BOTH, padx=10, pady=10, side=Tix.TOP)
44 # This is our little relational database
46 bosses = [
47 ('jeff', 'Jeff Waxman'),
48 ('john', 'John Lee'),
49 ('peter', 'Peter Kenson')
52 employees = [
53 ('alex', 'john', 'Alex Kellman'),
54 ('alan', 'john', 'Alan Adams'),
55 ('andy', 'peter', 'Andreas Crawford'),
56 ('doug', 'jeff', 'Douglas Bloom'),
57 ('jon', 'peter', 'Jon Baraki'),
58 ('chris', 'jeff', 'Chris Geoffrey'),
59 ('chuck', 'jeff', 'Chuck McLean')
62 hlist=top.a.hlist
64 # Let configure the appearance of the HList subwidget
66 hlist.config( separator='.', width=25, drawbranch=0, indent=10)
68 count=0
69 for boss,name in bosses :
70 if count :
71 f=Tix.Frame(hlist, name='sep%d' % count, height=2, width=150,
72 bd=2, relief=Tix.SUNKEN )
74 hlist.add_child( itemtype=Tix.WINDOW,
75 window=f, state=Tix.DISABLED )
77 hlist.add(boss, itemtype=Tix.TEXT, text=name)
78 count = count+1
81 for person,boss,name in employees :
82 # '.' is the separator character we chose above
84 key= boss + '.' + person
85 # ^^^^ ^^^^^^
86 # parent entryPath / child's name
88 hlist.add( key, text=name )
90 # [Hint] Make sure the keys (e.g. 'boss.person') you choose
91 # are unique names. If you cannot be sure of this (because of
92 # the structure of your database, e.g.) you can use the
93 # "add_child" command instead:
95 # hlist.addchild( boss, text=name)
96 # ^^^^
97 # parent entryPath
100 # Use a ButtonBox to hold the buttons.
102 box= Tix.ButtonBox(top, orientation=Tix.HORIZONTAL )
103 box.add( 'ok', text='Ok', underline=0, width=6,
104 command = self.okcmd)
106 box.add( 'cancel', text='Cancel', underline=0, width=6,
107 command = self.quitcmd)
109 box.pack( side=Tix.BOTTOM, fill=Tix.X)
110 top.pack( side=Tix.TOP, fill=Tix.BOTH, expand=1 )
112 def okcmd (self):
113 self.quitcmd()
115 def quitcmd (self):
116 self.exit = 0
118 def mainloop(self):
119 while self.exit < 0:
120 self.root.tk.dooneevent(TCL_ALL_EVENTS)
122 def destroy (self):
123 self.root.destroy()
126 # This "if" statement makes it possible to run this script file inside or
127 # outside of the main demo program "tixwidgets.py".
129 if __name__== '__main__' :
130 root=Tix.Tk()
131 RunSample(root)