Merged release21-maint changes.
[python/dscho.git] / Demo / tix / samples / SHList1.py
blob5122bbcdda6116a2010cb9ffa13bc6848ffde799
1 #!/usr/local/bin/python
2 #
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": 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 def RunSample (w) :
20 # We create the frame and the ScrolledHList widget
21 # at the top of the dialog box
23 top = Tix.Frame( w, relief=Tix.RAISED, bd=1)
25 # Put a simple hierachy into the HList (two levels). Use colors and
26 # separator widgets (frames) to make the list look fancy
28 top.a = Tix.ScrolledHList(top)
29 top.a.pack( expand=1, fill=Tix.BOTH, padx=10, pady=10, side=Tix.TOP)
32 # This is our little relational database
34 bosses = [
35 ('jeff', 'Jeff Waxman'),
36 ('john', 'John Lee'),
37 ('peter', 'Peter Kenson')
40 employees = [
41 ('alex', 'john', 'Alex Kellman'),
42 ('alan', 'john', 'Alan Adams'),
43 ('andy', 'peter', 'Andreas Crawford'),
44 ('doug', 'jeff', 'Douglas Bloom'),
45 ('jon', 'peter', 'Jon Baraki'),
46 ('chris', 'jeff', 'Chris Geoffrey'),
47 ('chuck', 'jeff', 'Chuck McLean')
50 hlist=top.a.hlist
52 # Let configure the appearance of the HList subwidget
54 hlist.config( separator='.', width=25, drawbranch=0, indent=10)
56 count=0
57 for boss,name in bosses :
58 if count :
59 f=Tix.Frame(hlist, name='sep%d' % count, height=2, width=150,
60 bd=2, relief=Tix.SUNKEN, bg=hlist['bg'] )
62 hlist.add_child( itemtype=Tix.WINDOW,
63 window=f, state=Tix.DISABLED )
65 hlist.add(boss, itemtype=Tix.TEXT, text=name)
66 count = count+1
69 for person,boss,name in employees :
70 # '.' is the separator character we chose above
72 key= boss + '.' + person
73 # ^^^^ ^^^^^^
74 # parent entryPath / child's name
76 hlist.add( key, text=name )
78 # [Hint] Make sure the keys (e.g. 'boss.person') you choose
79 # are unique names. If you cannot be sure of this (because of
80 # the structure of your database, e.g.) you can use the
81 # "add_child" command instead:
83 # hlist.addchild( boss, text=name)
84 # ^^^^
85 # parent entryPath
88 # Use a ButtonBox to hold the buttons.
90 box= Tix.ButtonBox(top, orientation=Tix.HORIZONTAL )
91 box.add( 'ok', text='Ok', underline=0, width=6,
92 command = lambda w=w: w.destroy() )
94 box.add( 'cancel', text='Cancel', underline=0, width=6,
95 command = lambda w=w: w.destroy() )
97 box.pack( side=Tix.BOTTOM, fill=Tix.X)
98 top.pack( side=Tix.TOP, fill=Tix.BOTH, expand=1 )
101 # This "if" statement makes it possible to run this script file inside or
102 # outside of the main demo program "widget".
104 if __name__== '__main__' :
105 root=Tix.Tk()
106 RunSample(root)
107 root.mainloop()