| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
import Tix |
| 20 |
|
| 21 |
TCL_ALL_EVENTS = 0 |
| 22 |
|
| 23 |
def RunSample (root): |
| 24 |
shlist = DemoSHList(root) |
| 25 |
shlist.mainloop() |
| 26 |
shlist.destroy() |
| 27 |
|
| 28 |
class DemoSHList: |
| 29 |
def __init__(self, w): |
| 30 |
self.root = w |
| 31 |
self.exit = -1 |
| 32 |
|
| 33 |
z = w.winfo_toplevel() |
| 34 |
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
top = Tix.Frame( w, relief=Tix.RAISED, bd=1) |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 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) |
| 46 |
|
| 47 |
hlist=top.a.hlist |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
boldfont=hlist.tk.call('tix','option','get','bold_font') |
| 55 |
|
| 56 |
|
| 57 |
style={} |
| 58 |
style['header'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist, |
| 59 |
anchor=Tix.CENTER, padx=8, pady=2, font = boldfont ) |
| 60 |
|
| 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']) |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
hlist.column_width(2,0) |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
boss = ('doe', 'John Doe', 'Director') |
| 76 |
|
| 77 |
managers = [ |
| 78 |
('jeff', 'Jeff Waxman', 'Manager'), |
| 79 |
('john', 'John Lee', 'Manager'), |
| 80 |
('peter', 'Peter Kenson', 'Manager') |
| 81 |
] |
| 82 |
|
| 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') |
| 91 |
] |
| 92 |
|
| 93 |
style['mgr_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist) |
| 94 |
|
| 95 |
style['mgr_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=hlist) |
| 96 |
|
| 97 |
style['empl_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist) |
| 98 |
|
| 99 |
style['empl_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=hlist) |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
hlist.config(separator='.', width=25, drawbranch=0, indent=10) |
| 104 |
hlist.column_width(0, chars=20) |
| 105 |
|
| 106 |
|
| 107 |
|
| 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']) |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 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']) |
| 122 |
|
| 123 |
|
| 124 |
for key,mgr,name,posn in employees : |
| 125 |
|
| 126 |
|
| 127 |
entrypath = '.' + mgr + '.' + key |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 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'] ) |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
box= Tix.ButtonBox(top, orientation=Tix.HORIZONTAL ) |
| 140 |
box.add( 'ok', text='Ok', underline=0, width=6, |
| 141 |
command = self.okcmd ) |
| 142 |
|
| 143 |
box.add( 'cancel', text='Cancel', underline=0, width=6, |
| 144 |
command = self.quitcmd ) |
| 145 |
|
| 146 |
box.pack( side=Tix.BOTTOM, fill=Tix.X) |
| 147 |
top.pack( side=Tix.TOP, fill=Tix.BOTH, expand=1 ) |
| 148 |
|
| 149 |
def okcmd (self): |
| 150 |
self.quitcmd() |
| 151 |
|
| 152 |
def quitcmd (self): |
| 153 |
self.exit = 0 |
| 154 |
|
| 155 |
def mainloop(self): |
| 156 |
while self.exit < 0: |
| 157 |
self.root.tk.dooneevent(TCL_ALL_EVENTS) |
| 158 |
|
| 159 |
def destroy (self): |
| 160 |
self.root.destroy() |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
if __name__== '__main__' : |
| 167 |
root=Tix.Tk() |
| 168 |
RunSample(root) |