Update for release.
[python/dscho.git] / Demo / tix / samples / SHList2.py
blobe82d1e586a3c6cde1f8ee75c31462ec90d0bc316
1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
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 "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 TCL_ALL_EVENTS = 0
23 def RunSample (root):
24 shlist = DemoSHList(root)
25 shlist.mainloop()
26 shlist.destroy()
28 class DemoSHList:
29 def __init__(self, w):
30 self.root = w
31 self.exit = -1
33 z = w.winfo_toplevel()
34 z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
36 # We create the frame and the ScrolledHList widget
37 # at the top of the dialog box
39 top = Tix.Frame( w, relief=Tix.RAISED, bd=1)
41 # Put a simple hierachy into the HList (two levels). Use colors and
42 # separator widgets (frames) to make the list look fancy
44 top.a = Tix.ScrolledHList(top, options='hlist.columns 3 hlist.header 1' )
45 top.a.pack( expand=1, fill=Tix.BOTH, padx=10, pady=10, side=Tix.TOP)
47 hlist=top.a.hlist
49 # Create the title for the HList widget
50 # >> Notice that we have set the hlist.header subwidget option to true
51 # so that the header is displayed
54 boldfont=hlist.tk.call('tix','option','get','bold_font')
56 # First some styles for the headers
57 style={}
58 style['header'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist,
59 anchor=Tix.CENTER, padx=8, pady=2, font = boldfont )
61 hlist.header_create(0, itemtype=Tix.TEXT, text='Name',
62 style=style['header'])
63 hlist.header_create(1, itemtype=Tix.TEXT, text='Position',
64 style=style['header'])
66 # Notice that we use 3 columns in the hlist widget. This way when the user
67 # expands the windows wide, the right side of the header doesn't look
68 # chopped off. The following line ensures that the 3 column header is
69 # not shown unless the hlist window is wider than its contents.
71 hlist.column_width(2,0)
73 # This is our little relational database
75 boss = ('doe', 'John Doe', 'Director')
77 managers = [
78 ('jeff', 'Jeff Waxman', 'Manager'),
79 ('john', 'John Lee', 'Manager'),
80 ('peter', 'Peter Kenson', 'Manager')
83 employees = [
84 ('alex', 'john', 'Alex Kellman', 'Clerk'),
85 ('alan', 'john', 'Alan Adams', 'Clerk'),
86 ('andy', 'peter', 'Andreas Crawford', 'Salesman'),
87 ('doug', 'jeff', 'Douglas Bloom', 'Clerk'),
88 ('jon', 'peter', 'Jon Baraki', 'Salesman'),
89 ('chris', 'jeff', 'Chris Geoffrey', 'Clerk'),
90 ('chuck', 'jeff', 'Chuck McLean', 'Cleaner')
93 style['mgr_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist)
95 style['mgr_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=hlist)
97 style['empl_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist)
99 style['empl_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=hlist)
101 # Let configure the appearance of the HList subwidget
103 hlist.config(separator='.', width=25, drawbranch=0, indent=10)
104 hlist.column_width(0, chars=20)
106 # Create the boss
108 hlist.add ('.', itemtype=Tix.TEXT, text=boss[1],
109 style=style['mgr_name'])
110 hlist.item_create('.', 1, itemtype=Tix.TEXT, text=boss[2],
111 style=style['mgr_posn'])
113 # Create the managers
116 for key,name,posn in managers :
117 e= '.'+ key
118 hlist.add(e, itemtype=Tix.TEXT, text=name,
119 style=style['mgr_name'])
120 hlist.item_create(e, 1, itemtype=Tix.TEXT, text=posn,
121 style=style['mgr_posn'])
124 for key,mgr,name,posn in employees :
125 # "." is the separator character we chose above
127 entrypath = '.' + mgr + '.' + key
129 # ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
130 # parent entryPath / child's name
132 hlist.add(entrypath, text=name, style=style['empl_name'])
133 hlist.item_create(entrypath, 1, itemtype=Tix.TEXT,
134 text = posn, style = style['empl_posn'] )
137 # Use a ButtonBox to hold the buttons.
139 box= Tix.ButtonBox(top, orientation=Tix.HORIZONTAL )
140 box.add( 'ok', text='Ok', underline=0, width=6,
141 command = self.okcmd )
143 box.add( 'cancel', text='Cancel', underline=0, width=6,
144 command = self.quitcmd )
146 box.pack( side=Tix.BOTTOM, fill=Tix.X)
147 top.pack( side=Tix.TOP, fill=Tix.BOTH, expand=1 )
149 def okcmd (self):
150 self.quitcmd()
152 def quitcmd (self):
153 self.exit = 0
155 def mainloop(self):
156 while self.exit < 0:
157 self.root.tk.dooneevent(TCL_ALL_EVENTS)
159 def destroy (self):
160 self.root.destroy()
163 # This "if" statement makes it possible to run this script file inside or
164 # outside of the main demo program "tixwidgets.py".
166 if __name__== '__main__' :
167 root=Tix.Tk()
168 RunSample(root)