1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
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.
21 shlist
= DemoSHList(root
)
26 def __init__(self
, w
):
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
47 ('jeff', 'Jeff Waxman'),
49 ('peter', 'Peter Kenson')
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')
64 # Let configure the appearance of the HList subwidget
66 hlist
.config( separator
='.', width
=25, drawbranch
=0, indent
=10)
69 for boss
,name
in bosses
:
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
)
81 for person
,boss
,name
in employees
:
82 # '.' is the separator character we chose above
84 key
= boss
+ '.' + person
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)
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 )
120 self
.root
.tk
.dooneevent(TCL_ALL_EVENTS
)
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__' :