Updated for 2.1b2 distribution.
[python/dscho.git] / Demo / tix / samples / SHList2.py
blobe1a7a7c21bdf81d8a965a5d738ce660bcf2c7027
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 PyTix demo program "tixwidget": 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 how to use multiple columns and multiple styles
14 # in the tixHList widget
16 # In a tixHList widget, you can have one ore more columns.
19 import Tix
21 def RunSample (w) :
23 # We create the frame and the ScrolledHList widget
24 # at the top of the dialog box
26 top = Tix.Frame( w, relief=Tix.RAISED, bd=1)
28 # Put a simple hierachy into the HList (two levels). Use colors and
29 # separator widgets (frames) to make the list look fancy
31 top.a = Tix.ScrolledHList(top, options='hlist.columns 3 hlist.header 1' )
33 top.a.pack( expand=1, fill=Tix.BOTH, padx=10, pady=10, side=Tix.TOP)
35 hlist=top.a.hlist
37 # Create the title for the HList widget
38 # >> Notice that we have set the hlist.header subwidget option to true
39 # so that the header is displayed
42 boldfont=hlist.tk.call('tix','option','get','bold_font')
44 # First some styles for the headers
45 style={}
46 style['header'] = Tix.DisplayStyle(Tix.TEXT, fg='black', refwindow=top,
47 anchor=Tix.CENTER, padx=8, pady=2, font = boldfont )
49 hlist.header_create(0, itemtype=Tix.TEXT, text='Name',
50 style=style['header'])
51 hlist.header_create(1, itemtype=Tix.TEXT, text='Position',
52 style=style['header'])
54 # Notice that we use 3 columns in the hlist widget. This way when the user
55 # expands the windows wide, the right side of the header doesn't look
56 # chopped off. The following line ensures that the 3 column header is
57 # not shown unless the hlist window is wider than its contents.
59 hlist.column_width(2,0)
61 # This is our little relational database
63 boss = ('doe', 'John Doe', 'Director')
65 managers = [
66 ('jeff', 'Jeff Waxman', 'Manager'),
67 ('john', 'John Lee', 'Manager'),
68 ('peter', 'Peter Kenson', 'Manager')
71 employees = [
72 ('alex', 'john', 'Alex Kellman', 'Clerk'),
73 ('alan', 'john', 'Alan Adams', 'Clerk'),
74 ('andy', 'peter', 'Andreas Crawford', 'Salesman'),
75 ('doug', 'jeff', 'Douglas Bloom', 'Clerk'),
76 ('jon', 'peter', 'Jon Baraki', 'Salesman'),
77 ('chris', 'jeff', 'Chris Geoffrey', 'Clerk'),
78 ('chuck', 'jeff', 'Chuck McLean', 'Cleaner')
81 style['mgr_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=top,
82 fg='#202060', selectforeground = '#202060', font = boldfont )
84 style['mgr_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=top,
85 fg='#202060', selectforeground='#202060' )
87 style['empl_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=top,
88 fg='#602020', selectforeground = '#602020', font = boldfont )
90 style['empl_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=top,
91 fg='#602020', selectforeground = '#602020' )
93 # Let configure the appearance of the HList subwidget
95 hlist.config(separator='.', width=25, drawbranch=0, indent=10)
96 hlist.column_width(0, chars=20)
98 # Create the boss
100 hlist.add ('.', itemtype=Tix.TEXT, text=boss[1],
101 style=style['mgr_name'])
102 hlist.item_create('.', 1, itemtype=Tix.TEXT, text=boss[2],
103 style=style['mgr_posn'])
105 # Create the managers
108 for key,name,posn in managers :
109 e= '.'+ key
110 hlist.add(e, itemtype=Tix.TEXT, text=name,
111 style=style['mgr_name'])
112 hlist.item_create(e, 1, itemtype=Tix.TEXT, text=posn,
113 style=style['mgr_posn'])
116 for key,mgr,name,posn in employees :
117 # "." is the separator character we chose above
119 entrypath = '.' + mgr + '.' + key
121 # ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
122 # parent entryPath / child's name
124 hlist.add(entrypath, text=name, style=style['empl_name'])
125 hlist.item_create(entrypath, 1, itemtype=Tix.TEXT,
126 text = posn, style = style['empl_posn'] )
129 # Use a ButtonBox to hold the buttons.
131 box= Tix.ButtonBox(top, orientation=Tix.HORIZONTAL )
132 box.add( 'ok', text='Ok', underline=0, width=6,
133 command = lambda w=w: w.destroy() )
135 box.add( 'cancel', text='Cancel', underline=0, width=6,
136 command = lambda w=w: w.destroy() )
138 box.pack( side=Tix.BOTTOM, fill=Tix.X)
139 top.pack( side=Tix.TOP, fill=Tix.BOTH, expand=1 )
142 # This "if" statement makes it possible to run this script file inside or
143 # outside of the main demo program "widget".
145 if __name__== '__main__' :
146 root=Tix.Tk()
147 RunSample(root)
148 root.mainloop()