blob: a4b67def1908d8ae035f646a681a337476c1a689 [file] [log] [blame]
Martin v. Löwis20efa682001-11-11 14:07:37 +00001# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00002#
3# $Id$
4#
5# tixwidgets.py --
Martin v. Löwis20efa682001-11-11 14:07:37 +00006#
7# For Tix, see http://tix.sourceforge.net
8#
Neal Norwitzac30ead2002-11-14 02:44:08 +00009# This is a demo program of some of the Tix widgets available in Python.
10# If you have installed Python & Tix properly, you can execute this as
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000011#
Martin v. Löwis652e1912001-11-25 14:50:56 +000012# % python tixwidgets.py
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000013#
14
Martin v. Löwis652e1912001-11-25 14:50:56 +000015import os, os.path, sys, Tix
Martin v. Löwis20efa682001-11-11 14:07:37 +000016from Tkconstants import *
Neal Norwitzac30ead2002-11-14 02:44:08 +000017import traceback, tkMessageBox
Martin v. Löwis20efa682001-11-11 14:07:37 +000018
19TCL_DONT_WAIT = 1<<1
20TCL_WINDOW_EVENTS = 1<<2
21TCL_FILE_EVENTS = 1<<3
22TCL_TIMER_EVENTS = 1<<4
23TCL_IDLE_EVENTS = 1<<5
24TCL_ALL_EVENTS = 0
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000025
26class Demo:
Martin v. Löwis20efa682001-11-11 14:07:37 +000027 def __init__(self, top):
28 self.root = top
29 self.exit = -1
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000030
Martin v. Löwis20efa682001-11-11 14:07:37 +000031 self.dir = None # script directory
32 self.balloon = None # balloon widget
33 self.useBalloons = Tix.StringVar()
34 self.useBalloons.set('0')
35 self.statusbar = None # status bar widget
36 self.welmsg = None # Msg widget
37 self.welfont = '' # font name
38 self.welsize = '' # font size
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000039
Martin v. Löwis20efa682001-11-11 14:07:37 +000040 progname = sys.argv[0]
41 dirname = os.path.dirname(progname)
42 if dirname and dirname != os.curdir:
43 self.dir = dirname
44 index = -1
45 for i in range(len(sys.path)):
46 p = sys.path[i]
47 if p in ("", os.curdir):
48 index = i
49 if index >= 0:
50 sys.path[index] = dirname
51 else:
52 sys.path.insert(0, dirname)
53 else:
54 self.dir = os.getcwd()
55 sys.path.insert(0, self.dir+'/samples')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000056
Martin v. Löwis20efa682001-11-11 14:07:37 +000057 def MkMainMenu(self):
58 top = self.root
59 w = Tix.Frame(top, bd=2, relief=RAISED)
60 file = Tix.Menubutton(w, text='File', underline=0, takefocus=0)
61 help = Tix.Menubutton(w, text='Help', underline=0, takefocus=0)
62 file.pack(side=LEFT)
63 help.pack(side=RIGHT)
Martin v. Löwis652e1912001-11-25 14:50:56 +000064 fm = Tix.Menu(file, tearoff=0)
Martin v. Löwis20efa682001-11-11 14:07:37 +000065 file['menu'] = fm
Martin v. Löwis652e1912001-11-25 14:50:56 +000066 hm = Tix.Menu(help, tearoff=0)
Martin v. Löwis20efa682001-11-11 14:07:37 +000067 help['menu'] = hm
68
Martin v. Löwis652e1912001-11-25 14:50:56 +000069 fm.add_command(label='Exit', underline=1,
Martin v. Löwis20efa682001-11-11 14:07:37 +000070 command = lambda self=self: self.quitcmd () )
71 hm.add_checkbutton(label='BalloonHelp', underline=0, command=ToggleHelp,
72 variable=self.useBalloons)
73 # The trace variable option doesn't seem to work, instead I use 'command'
74 #apply(w.tk.call, ('trace', 'variable', self.useBalloons, 'w',
75 # ToggleHelp))
Neal Norwitzac30ead2002-11-14 02:44:08 +000076
Martin v. Löwis20efa682001-11-11 14:07:37 +000077 return w
78
79 def MkMainNotebook(self):
80 top = self.root
81 w = Tix.NoteBook(top, ipadx=5, ipady=5, options="""
Neal Norwitzac30ead2002-11-14 02:44:08 +000082 tagPadX 6
83 tagPadY 4
84 borderWidth 2
Martin v. Löwis20efa682001-11-11 14:07:37 +000085 """)
86 # This may be required if there is no *Background option
87 top['bg'] = w['bg']
88
89 w.add('wel', label='Welcome', underline=0,
90 createcmd=lambda w=w, name='wel': MkWelcome(w, name))
91 w.add('cho', label='Choosers', underline=0,
92 createcmd=lambda w=w, name='cho': MkChoosers(w, name))
93 w.add('scr', label='Scrolled Widgets', underline=0,
94 createcmd=lambda w=w, name='scr': MkScroll(w, name))
95 w.add('mgr', label='Manager Widgets', underline=0,
96 createcmd=lambda w=w, name='mgr': MkManager(w, name))
97 w.add('dir', label='Directory List', underline=0,
98 createcmd=lambda w=w, name='dir': MkDirList(w, name))
99 w.add('exp', label='Run Sample Programs', underline=0,
100 createcmd=lambda w=w, name='exp': MkSample(w, name))
101 return w
102
103 def MkMainStatus(self):
104 global demo
105 top = self.root
106
107 w = Tix.Frame(top, relief=Tix.RAISED, bd=1)
108 demo.statusbar = Tix.Label(w, relief=Tix.SUNKEN, bd=1)
109 demo.statusbar.form(padx=3, pady=3, left=0, right='%70')
110 return w
111
112 def build(self):
113 root = self.root
114 z = root.winfo_toplevel()
115 z.wm_title('Tix Widget Demonstration')
Neal Norwitzac30ead2002-11-14 02:44:08 +0000116 if z.winfo_screenwidth() <= 800:
117 z.geometry('790x590+10+10')
118 else:
119 z.geometry('890x640+10+10')
Martin v. Löwis20efa682001-11-11 14:07:37 +0000120 demo.balloon = Tix.Balloon(root)
121 frame1 = self.MkMainMenu()
122 frame2 = self.MkMainNotebook()
123 frame3 = self.MkMainStatus()
124 frame1.pack(side=TOP, fill=X)
125 frame3.pack(side=BOTTOM, fill=X)
126 frame2.pack(side=TOP, expand=1, fill=BOTH, padx=4, pady=4)
127 demo.balloon['statusbar'] = demo.statusbar
128 z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
129
Neal Norwitzac30ead2002-11-14 02:44:08 +0000130 # To show Tcl errors - uncomment this to see the listbox bug.
131 # Tkinter defines a Tcl tkerror procedure that in effect
132 # silences all background Tcl error reporting.
133 # root.tk.eval('if {[info commands tkerror] != ""} {rename tkerror pytkerror}')
Martin v. Löwis20efa682001-11-11 14:07:37 +0000134 def quitcmd (self):
Martin v. Löwis652e1912001-11-25 14:50:56 +0000135 """Quit our mainloop. It is up to you to call root.destroy() after."""
Martin v. Löwis20efa682001-11-11 14:07:37 +0000136 self.exit = 0
137
138 def loop(self):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000139 """This is an explict replacement for _tkinter mainloop()
140 It lets you catch keyboard interrupts easier, and avoids
141 the 20 msec. dead sleep() which burns a constant CPU."""
Martin v. Löwis652e1912001-11-25 14:50:56 +0000142 while self.exit < 0:
Neal Norwitzac30ead2002-11-14 02:44:08 +0000143 # There are 2 whiles here. The outer one lets you continue
144 # after a ^C interrupt.
Martin v. Löwis652e1912001-11-25 14:50:56 +0000145 try:
Neal Norwitzac30ead2002-11-14 02:44:08 +0000146 # This is the replacement for _tkinter mainloop()
147 # It blocks waiting for the next Tcl event using select.
148 while self.exit < 0:
149 self.root.tk.dooneevent(TCL_ALL_EVENTS)
Martin v. Löwis652e1912001-11-25 14:50:56 +0000150 except SystemExit:
Neal Norwitzac30ead2002-11-14 02:44:08 +0000151 # Tkinter uses SystemExit to exit
Martin v. Löwis652e1912001-11-25 14:50:56 +0000152 #print 'Exit'
153 self.exit = 1
Neal Norwitzac30ead2002-11-14 02:44:08 +0000154 return
Martin v. Löwis652e1912001-11-25 14:50:56 +0000155 except KeyboardInterrupt:
156 if tkMessageBox.askquestion ('Interrupt', 'Really Quit?') == 'yes':
157 # self.tk.eval('exit')
Neal Norwitzac30ead2002-11-14 02:44:08 +0000158 self.exit = 1
Martin v. Löwis652e1912001-11-25 14:50:56 +0000159 return
Martin v. Löwis652e1912001-11-25 14:50:56 +0000160 continue
161 except:
Neal Norwitzac30ead2002-11-14 02:44:08 +0000162 # Otherwise it's some other error - be nice and say why
Martin v. Löwis652e1912001-11-25 14:50:56 +0000163 t, v, tb = sys.exc_info()
164 text = ""
165 for line in traceback.format_exception(t,v,tb):
166 text += line + '\n'
167 try: tkMessageBox.showerror ('Error', text)
168 except: pass
Martin v. Löwis8ec03e02002-03-17 18:19:13 +0000169 self.exit = 1
170 raise SystemExit, 1
Martin v. Löwis20efa682001-11-11 14:07:37 +0000171
172 def destroy (self):
173 self.root.destroy()
Neal Norwitzac30ead2002-11-14 02:44:08 +0000174
Martin v. Löwis652e1912001-11-25 14:50:56 +0000175def RunMain(root):
176 global demo
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000177
Martin v. Löwis652e1912001-11-25 14:50:56 +0000178 demo = Demo(root)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000179
Martin v. Löwis20efa682001-11-11 14:07:37 +0000180 demo.build()
181 demo.loop()
182 demo.destroy()
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000183
Martin v. Löwis20efa682001-11-11 14:07:37 +0000184# Tabs
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000185def MkWelcome(nb, name):
186 w = nb.page(name)
187 bar = MkWelcomeBar(w)
188 text = MkWelcomeText(w)
Martin v. Löwis20efa682001-11-11 14:07:37 +0000189 bar.pack(side=TOP, fill=X, padx=2, pady=2)
190 text.pack(side=TOP, fill=BOTH, expand=1)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000191
192def MkWelcomeBar(top):
193 global demo
194
195 w = Tix.Frame(top, bd=2, relief=Tix.GROOVE)
196 b1 = Tix.ComboBox(w, command=lambda w=top: MainTextFont(w))
197 b2 = Tix.ComboBox(w, command=lambda w=top: MainTextFont(w))
198 b1.entry['width'] = 15
199 b1.slistbox.listbox['height'] = 3
200 b2.entry['width'] = 4
201 b2.slistbox.listbox['height'] = 3
202
203 demo.welfont = b1
204 demo.welsize = b2
205
206 b1.insert(Tix.END, 'Courier')
207 b1.insert(Tix.END, 'Helvetica')
208 b1.insert(Tix.END, 'Lucida')
209 b1.insert(Tix.END, 'Times Roman')
210
211 b2.insert(Tix.END, '8')
212 b2.insert(Tix.END, '10')
213 b2.insert(Tix.END, '12')
214 b2.insert(Tix.END, '14')
215 b2.insert(Tix.END, '18')
216
217 b1.pick(1)
218 b2.pick(3)
219
220 b1.pack(side=Tix.LEFT, padx=4, pady=4)
221 b2.pack(side=Tix.LEFT, padx=4, pady=4)
222
223 demo.balloon.bind_widget(b1, msg='Choose\na font',
224 statusmsg='Choose a font for this page')
225 demo.balloon.bind_widget(b2, msg='Point size',
226 statusmsg='Choose the font size for this page')
227 return w
228
229def MkWelcomeText(top):
230 global demo
231
232 w = Tix.ScrolledWindow(top, scrollbar='auto')
233 win = w.window
234 text = 'Welcome to TIX in Python'
Martin v. Löwis20efa682001-11-11 14:07:37 +0000235 title = Tix.Label(win,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000236 bd=0, width=30, anchor=Tix.N, text=text)
Martin v. Löwis20efa682001-11-11 14:07:37 +0000237 msg = Tix.Message(win,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000238 bd=0, width=400, anchor=Tix.N,
239 text='Tix is a set of mega-widgets based on TK. This program \
240demonstrates the widgets in the Tix widget set. You can choose the pages \
241in this window to look at the corresponding widgets. \n\n\
242To quit this program, choose the "File | Exit" command.\n\n\
243For more information, see http://tix.sourceforge.net.')
244 title.pack(expand=1, fill=Tix.BOTH, padx=10, pady=10)
245 msg.pack(expand=1, fill=Tix.BOTH, padx=10, pady=10)
246 demo.welmsg = msg
247 return w
248
249def MainTextFont(w):
250 global demo
251
252 if not demo.welmsg:
253 return
254 font = demo.welfont['value']
255 point = demo.welsize['value']
256 if font == 'Times Roman':
257 font = 'times'
Martin v. Löwis20efa682001-11-11 14:07:37 +0000258 fontstr = '%s %s' % (font, point)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000259 demo.welmsg['font'] = fontstr
260
261def ToggleHelp():
262 if demo.useBalloons.get() == '1':
263 demo.balloon['state'] = 'both'
264 else:
265 demo.balloon['state'] = 'none'
266
267def MkChoosers(nb, name):
268 w = nb.page(name)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000269 options = "label.padX 4"
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000270
Neal Norwitzac30ead2002-11-14 02:44:08 +0000271 til = Tix.LabelFrame(w, label='Chooser Widgets', options=options)
272 cbx = Tix.LabelFrame(w, label='tixComboBox', options=options)
273 ctl = Tix.LabelFrame(w, label='tixControl', options=options)
274 sel = Tix.LabelFrame(w, label='tixSelect', options=options)
275 opt = Tix.LabelFrame(w, label='tixOptionMenu', options=options)
276 fil = Tix.LabelFrame(w, label='tixFileEntry', options=options)
277 fbx = Tix.LabelFrame(w, label='tixFileSelectBox', options=options)
278 tbr = Tix.LabelFrame(w, label='Tool Bar', options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000279
280 MkTitle(til.frame)
281 MkCombo(cbx.frame)
282 MkControl(ctl.frame)
283 MkSelect(sel.frame)
284 MkOptMenu(opt.frame)
285 MkFileEnt(fil.frame)
286 MkFileBox(fbx.frame)
287 MkToolBar(tbr.frame)
288
289 # First column: comBox and selector
290 cbx.form(top=0, left=0, right='%33')
291 sel.form(left=0, right='&'+str(cbx), top=cbx)
292 opt.form(left=0, right='&'+str(cbx), top=sel, bottom=-1)
293
294 # Second column: title .. etc
295 til.form(left=cbx, top=0,right='%66')
296 ctl.form(left=cbx, right='&'+str(til), top=til)
297 fil.form(left=cbx, right='&'+str(til), top=ctl)
298 tbr.form(left=cbx, right='&'+str(til), top=fil, bottom=-1)
299
300 #
301 # Third column: file selection
302 fbx.form(right=-1, top=0, left='%66')
303
304def MkCombo(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000305 options="label.width %d label.anchor %s entry.width %d" % (10, Tix.E, 14)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000306
Neal Norwitzac30ead2002-11-14 02:44:08 +0000307 static = Tix.ComboBox(w, label='Static', editable=0, options=options)
308 editable = Tix.ComboBox(w, label='Editable', editable=1, options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000309 history = Tix.ComboBox(w, label='History', editable=1, history=1,
Neal Norwitzac30ead2002-11-14 02:44:08 +0000310 anchor=Tix.E, options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000311 static.insert(Tix.END, 'January')
312 static.insert(Tix.END, 'February')
313 static.insert(Tix.END, 'March')
314 static.insert(Tix.END, 'April')
315 static.insert(Tix.END, 'May')
316 static.insert(Tix.END, 'June')
317 static.insert(Tix.END, 'July')
318 static.insert(Tix.END, 'August')
319 static.insert(Tix.END, 'September')
320 static.insert(Tix.END, 'October')
321 static.insert(Tix.END, 'November')
322 static.insert(Tix.END, 'December')
323
324 editable.insert(Tix.END, 'Angola')
325 editable.insert(Tix.END, 'Bangladesh')
326 editable.insert(Tix.END, 'China')
327 editable.insert(Tix.END, 'Denmark')
328 editable.insert(Tix.END, 'Ecuador')
329
330 history.insert(Tix.END, '/usr/bin/ksh')
331 history.insert(Tix.END, '/usr/local/lib/python')
332 history.insert(Tix.END, '/var/adm')
333
334 static.pack(side=Tix.TOP, padx=5, pady=3)
335 editable.pack(side=Tix.TOP, padx=5, pady=3)
336 history.pack(side=Tix.TOP, padx=5, pady=3)
337
338states = ['Bengal', 'Delhi', 'Karnataka', 'Tamil Nadu']
339
340def spin_cmd(w, inc):
341 idx = states.index(demo_spintxt.get()) + inc
342 if idx < 0:
343 idx = len(states) - 1
344 elif idx >= len(states):
345 idx = 0
346# following doesn't work.
347# return states[idx]
348 demo_spintxt.set(states[idx]) # this works
349
350def spin_validate(w):
351 global states, demo_spintxt
352
353 try:
354 i = states.index(demo_spintxt.get())
Fred Drake7def2562001-05-11 19:44:55 +0000355 except ValueError:
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000356 return states[0]
357 return states[i]
358 # why this procedure works as opposed to the previous one beats me.
359
360def MkControl(w):
361 global demo_spintxt
362
Neal Norwitzac30ead2002-11-14 02:44:08 +0000363 options="label.width %d label.anchor %s entry.width %d" % (10, Tix.E, 13)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000364
365 demo_spintxt = Tix.StringVar()
366 demo_spintxt.set(states[0])
Neal Norwitzac30ead2002-11-14 02:44:08 +0000367 simple = Tix.Control(w, label='Numbers', options=options)
368 spintxt = Tix.Control(w, label='States', variable=demo_spintxt,
369 options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000370 spintxt['incrcmd'] = lambda w=spintxt: spin_cmd(w, 1)
371 spintxt['decrcmd'] = lambda w=spintxt: spin_cmd(w, -1)
372 spintxt['validatecmd'] = lambda w=spintxt: spin_validate(w)
373
374 simple.pack(side=Tix.TOP, padx=5, pady=3)
375 spintxt.pack(side=Tix.TOP, padx=5, pady=3)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000376
Neal Norwitzac30ead2002-11-14 02:44:08 +0000377def MkSelect(w):
378 options = "label.anchor %s" % Tix.CENTER
379
380 sel1 = Tix.Select(w, label='Mere Mortals', allowzero=1, radio=1,
381 orientation=Tix.VERTICAL,
382 labelside=Tix.TOP,
383 options=options)
384 sel2 = Tix.Select(w, label='Geeks', allowzero=1, radio=0,
385 orientation=Tix.VERTICAL,
386 labelside= Tix.TOP,
387 options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000388
389 sel1.add('eat', text='Eat')
390 sel1.add('work', text='Work')
391 sel1.add('play', text='Play')
392 sel1.add('party', text='Party')
393 sel1.add('sleep', text='Sleep')
394
395 sel2.add('eat', text='Eat')
396 sel2.add('prog1', text='Program')
397 sel2.add('prog2', text='Program')
398 sel2.add('prog3', text='Program')
399 sel2.add('sleep', text='Sleep')
400
401 sel1.pack(side=Tix.LEFT, padx=5, pady=3, fill=Tix.X)
402 sel2.pack(side=Tix.LEFT, padx=5, pady=3, fill=Tix.X)
403
404def MkOptMenu(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000405 options='menubutton.width 15 label.anchor %s' % Tix.E
406
407 m = Tix.OptionMenu(w, label='File Format : ', options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000408 m.add_command('text', label='Plain Text')
409 m.add_command('post', label='PostScript')
410 m.add_command('format', label='Formatted Text')
411 m.add_command('html', label='HTML')
412 m.add_command('sep')
413 m.add_command('tex', label='LaTeX')
414 m.add_command('rtf', label='Rich Text Format')
415
416 m.pack(fill=Tix.X, padx=5, pady=3)
417
418def MkFileEnt(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000419 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000420 relief=Tix.FLAT, width=240, anchor=Tix.N,
421 text='Press the "open file" icon button and a TixFileSelectDialog will popup.')
422 ent = Tix.FileEntry(w, label='Select a file : ')
423 msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3)
424 ent.pack(side=Tix.TOP, fill=Tix.X, padx=3, pady=3)
425
426def MkFileBox(w):
Martin v. Löwis8ec03e02002-03-17 18:19:13 +0000427 """The FileSelectBox is a Motif-style box with various enhancements.
428 For example, you can adjust the size of the two listboxes
429 and your past selections are recorded.
430 """
Neal Norwitzac30ead2002-11-14 02:44:08 +0000431 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000432 relief=Tix.FLAT, width=240, anchor=Tix.N,
Martin v. Löwis8ec03e02002-03-17 18:19:13 +0000433 text='The Tix FileSelectBox is a Motif-style box with various enhancements. For example, you can adjust the size of the two listboxes and your past selections are recorded.')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000434 box = Tix.FileSelectBox(w)
435 msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3)
436 box.pack(side=Tix.TOP, fill=Tix.X, padx=3, pady=3)
437
438def MkToolBar(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000439 """The Select widget is also good for arranging buttons in a tool bar.
440 """
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000441 global demo
442
Neal Norwitzac30ead2002-11-14 02:44:08 +0000443 options='frame.borderWidth 1'
444
445 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000446 relief=Tix.FLAT, width=240, anchor=Tix.N,
447 text='The Select widget is also good for arranging buttons in a tool bar.')
448 bar = Tix.Frame(w, bd=2, relief=Tix.RAISED)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000449 font = Tix.Select(w, allowzero=1, radio=0, label='', options=options)
450 para = Tix.Select(w, allowzero=0, radio=1, label='', options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000451
452 font.add('bold', bitmap='@' + demo.dir + '/bitmaps/bold.xbm')
453 font.add('italic', bitmap='@' + demo.dir + '/bitmaps/italic.xbm')
454 font.add('underline', bitmap='@' + demo.dir + '/bitmaps/underline.xbm')
455 font.add('capital', bitmap='@' + demo.dir + '/bitmaps/capital.xbm')
456
457 para.add('left', bitmap='@' + demo.dir + '/bitmaps/leftj.xbm')
458 para.add('right', bitmap='@' + demo.dir + '/bitmaps/rightj.xbm')
459 para.add('center', bitmap='@' + demo.dir + '/bitmaps/centerj.xbm')
460 para.add('justify', bitmap='@' + demo.dir + '/bitmaps/justify.xbm')
461
462 msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3)
463 bar.pack(side=Tix.TOP, fill=Tix.X, padx=3, pady=3)
464 font.pack({'in':bar}, side=Tix.LEFT, padx=3, pady=3)
465 para.pack({'in':bar}, side=Tix.LEFT, padx=3, pady=3)
466
467def MkTitle(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000468 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000469 relief=Tix.FLAT, width=240, anchor=Tix.N,
470 text='There are many types of "chooser" widgets that allow the user to input different types of information')
471 msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3)
472
473def MkScroll(nb, name):
474 w = nb.page(name)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000475 options='label.padX 4'
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000476
Neal Norwitzac30ead2002-11-14 02:44:08 +0000477 sls = Tix.LabelFrame(w, label='tixScrolledListBox', options=options)
478 swn = Tix.LabelFrame(w, label='tixScrolledWindow', options=options)
479 stx = Tix.LabelFrame(w, label='tixScrolledText', options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000480
481 MkSList(sls.frame)
482 MkSWindow(swn.frame)
483 MkSText(stx.frame)
484
485 sls.form(top=0, left=0, right='%33', bottom=-1)
486 swn.form(top=0, left=sls, right='%66', bottom=-1)
487 stx.form(top=0, left=swn, right=-1, bottom=-1)
488
Neal Norwitzac30ead2002-11-14 02:44:08 +0000489
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000490def MkSList(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000491 """This TixScrolledListBox is configured so that it uses scrollbars
492 only when it is necessary. Use the handles to resize the listbox and
493 watch the scrollbars automatically appear and disappear. """
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000494 top = Tix.Frame(w, width=300, height=330)
495 bot = Tix.Frame(w)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000496 msg = Tix.Message(top,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000497 relief=Tix.FLAT, width=200, anchor=Tix.N,
498 text='This TixScrolledListBox is configured so that it uses scrollbars only when it is necessary. Use the handles to resize the listbox and watch the scrollbars automatically appear and disappear.')
499
500 list = Tix.ScrolledListBox(top, scrollbar='auto')
501 list.place(x=50, y=150, width=120, height=80)
502 list.listbox.insert(Tix.END, 'Alabama')
503 list.listbox.insert(Tix.END, 'California')
504 list.listbox.insert(Tix.END, 'Montana')
505 list.listbox.insert(Tix.END, 'New Jersey')
506 list.listbox.insert(Tix.END, 'New York')
507 list.listbox.insert(Tix.END, 'Pennsylvania')
508 list.listbox.insert(Tix.END, 'Washington')
509
510 rh = Tix.ResizeHandle(top, bg='black',
511 relief=Tix.RAISED,
512 handlesize=8, gridded=1, minwidth=50, minheight=30)
513 btn = Tix.Button(bot, text='Reset', command=lambda w=rh, x=list: SList_reset(w,x))
514 top.propagate(0)
515 msg.pack(fill=Tix.X)
516 btn.pack(anchor=Tix.CENTER)
517 top.pack(expand=1, fill=Tix.BOTH)
518 bot.pack(fill=Tix.BOTH)
519 list.bind('<Map>', func=lambda arg=0, rh=rh, list=list:
520 list.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(list)))
521
522def SList_reset(rh, list):
523 list.place(x=50, y=150, width=120, height=80)
524 list.update()
525 rh.attach_widget(list)
526
527def MkSWindow(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000528 """The ScrolledWindow widget allows you to scroll any kind of Tk
529 widget. It is more versatile than a scrolled canvas widget.
530 """
531 global demo
Martin v. Löwis652e1912001-11-25 14:50:56 +0000532
Neal Norwitzac30ead2002-11-14 02:44:08 +0000533 text = 'The Tix ScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.'
534
Martin v. Löwis652e1912001-11-25 14:50:56 +0000535 file = os.path.join(demo.dir, 'bitmaps', 'tix.gif')
536 if not os.path.isfile(file):
537 text += ' (Image missing)'
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000538
539 top = Tix.Frame(w, width=330, height=330)
540 bot = Tix.Frame(w)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000541 msg = Tix.Message(top,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000542 relief=Tix.FLAT, width=200, anchor=Tix.N,
Martin v. Löwis652e1912001-11-25 14:50:56 +0000543 text=text)
544
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000545 win = Tix.ScrolledWindow(top, scrollbar='auto')
Martin v. Löwis652e1912001-11-25 14:50:56 +0000546
Neal Norwitzac30ead2002-11-14 02:44:08 +0000547 global image1
548 # This image is not showing up in the Label unless it is set to a
549 # global variable - no problem under Tcl/Tix. It is being
550 # garbage collected at the end of this proecedure if not global
Martin v. Löwis652e1912001-11-25 14:50:56 +0000551 image1 = Tix.Image('photo', file=file)
552 lbl = Tix.Label(win.window, image=image1)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000553 lbl.pack(expand=1, fill=Tix.BOTH)
554
555 win.place(x=30, y=150, width=190, height=120)
556
557 rh = Tix.ResizeHandle(top, bg='black',
558 relief=Tix.RAISED,
559 handlesize=8, gridded=1, minwidth=50, minheight=30)
560 btn = Tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SWindow_reset(w,x))
561 top.propagate(0)
562 msg.pack(fill=Tix.X)
563 btn.pack(anchor=Tix.CENTER)
564 top.pack(expand=1, fill=Tix.BOTH)
565 bot.pack(fill=Tix.BOTH)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000566
567def SWindow_reset(rh, win):
568 win.place(x=30, y=150, width=190, height=120)
569 win.update()
570 rh.attach_widget(win)
571
572def MkSText(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000573 """The TixScrolledWindow widget allows you to scroll any kind of Tk
574 widget. It is more versatile than a scrolled canvas widget."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000575 top = Tix.Frame(w, width=330, height=330)
576 bot = Tix.Frame(w)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000577 msg = Tix.Message(top,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000578 relief=Tix.FLAT, width=200, anchor=Tix.N,
Neal Norwitzac30ead2002-11-14 02:44:08 +0000579 text='The Tix ScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000580
581 win = Tix.ScrolledText(top, scrollbar='auto')
582# win.text['wrap'] = 'none'
583 win.text.insert(Tix.END, 'This is a text widget embedded in a scrolled window. Although the original Tix demo does not have any text here, I decided to put in some so that you can see the effect of scrollbars etc.')
584 win.place(x=30, y=150, width=190, height=100)
585
586 rh = Tix.ResizeHandle(top, bg='black',
587 relief=Tix.RAISED,
588 handlesize=8, gridded=1, minwidth=50, minheight=30)
589 btn = Tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SText_reset(w,x))
590 top.propagate(0)
591 msg.pack(fill=Tix.X)
592 btn.pack(anchor=Tix.CENTER)
593 top.pack(expand=1, fill=Tix.BOTH)
594 bot.pack(fill=Tix.BOTH)
595 win.bind('<Map>', func=lambda arg=0, rh=rh, win=win:
596 win.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(win)))
597
598def SText_reset(rh, win):
599 win.place(x=30, y=150, width=190, height=120)
600 win.update()
601 rh.attach_widget(win)
602
603def MkManager(nb, name):
604 w = nb.page(name)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000605 options='label.padX 4'
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000606
Neal Norwitzac30ead2002-11-14 02:44:08 +0000607 pane = Tix.LabelFrame(w, label='tixPanedWindow', options=options)
608 note = Tix.LabelFrame(w, label='tixNoteBook', options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000609
610 MkPanedWindow(pane.frame)
611 MkNoteBook(note.frame)
612
613 pane.form(top=0, left=0, right=note, bottom=-1)
614 note.form(top=0, right=-1, bottom=-1)
615
616def MkPanedWindow(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000617 """The PanedWindow widget allows the user to interactively manipulate
618 the sizes of several panes. The panes can be arranged either vertically
619 or horizontally.
620 """
621 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000622 relief=Tix.FLAT, width=240, anchor=Tix.N,
623 text='The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally.')
Martin v. Löwis652e1912001-11-25 14:50:56 +0000624 group = Tix.LabelEntry(w, label='Newsgroup:', options='entry.width 25')
625 group.entry.insert(0,'comp.lang.python')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000626 pane = Tix.PanedWindow(w, orientation='vertical')
627
628 p1 = pane.add('list', min=70, size=100)
629 p2 = pane.add('text', min=70)
630 list = Tix.ScrolledListBox(p1)
631 text = Tix.ScrolledText(p2)
632
Martin v. Löwis652e1912001-11-25 14:50:56 +0000633 list.listbox.insert(Tix.END, " 12324 Re: Tkinter is good for your health")
634 list.listbox.insert(Tix.END, "+ 12325 Re: Tkinter is good for your health")
635 list.listbox.insert(Tix.END, "+ 12326 Re: Tix is even better for your health (Was: Tkinter is good...)")
636 list.listbox.insert(Tix.END, " 12327 Re: Tix is even better for your health (Was: Tkinter is good...)")
637 list.listbox.insert(Tix.END, "+ 12328 Re: Tix is even better for your health (Was: Tkinter is good...)")
638 list.listbox.insert(Tix.END, " 12329 Re: Tix is even better for your health (Was: Tkinter is good...)")
639 list.listbox.insert(Tix.END, "+ 12330 Re: Tix is even better for your health (Was: Tkinter is good...)")
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000640
641 text.text['bg'] = list.listbox['bg']
642 text.text['wrap'] = 'none'
643 text.text.insert(Tix.END, """
Martin v. Löwis652e1912001-11-25 14:50:56 +0000644Mon, 19 Jun 1995 11:39:52 comp.lang.python Thread 34 of 220
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000645Lines 353 A new way to put text and bitmaps together iNo responses
646ioi@blue.seas.upenn.edu Ioi K. Lam at University of Pennsylvania
647
648Hi,
649
650I have implemented a new image type called "compound". It allows you
651to glue together a bunch of bitmaps, images and text strings together
652to form a bigger image. Then you can use this image with widgets that
653support the -image option. For example, you can display a text string string
654together with a bitmap, at the same time, inside a TK button widget.
655""")
656 list.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6)
657 text.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6)
658
659 msg.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH)
660 group.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH)
661 pane.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH, expand=1)
662
663def MkNoteBook(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000664 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000665 relief=Tix.FLAT, width=240, anchor=Tix.N,
666 text='The NoteBook widget allows you to layout a complex interface into individual pages.')
Neal Norwitzac30ead2002-11-14 02:44:08 +0000667 # prefix = Tix.OptionName(w)
668 # if not prefix: prefix = ''
669 # w.option_add('*' + prefix + '*TixNoteBook*tagPadX', 8)
670 options = "entry.width %d label.width %d label.anchor %s" % (10, 18, Tix.E)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000671
Neal Norwitzac30ead2002-11-14 02:44:08 +0000672 nb = Tix.NoteBook(w, ipadx=6, ipady=6, options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000673 nb.add('hard_disk', label="Hard Disk", underline=0)
674 nb.add('network', label="Network", underline=0)
675
676 # Frame for the buttons that are present on all pages
677 common = Tix.Frame(nb.hard_disk)
678 common.pack(side=Tix.RIGHT, padx=2, pady=2, fill=Tix.Y)
679 CreateCommonButtons(common)
680
681 # Widgets belonging only to this page
682 a = Tix.Control(nb.hard_disk, value=12, label='Access Time: ')
683 w = Tix.Control(nb.hard_disk, value=400, label='Write Throughput: ')
684 r = Tix.Control(nb.hard_disk, value=400, label='Read Throughput: ')
685 c = Tix.Control(nb.hard_disk, value=1021, label='Capacity: ')
686 a.pack(side=Tix.TOP, padx=20, pady=2)
687 w.pack(side=Tix.TOP, padx=20, pady=2)
688 r.pack(side=Tix.TOP, padx=20, pady=2)
689 c.pack(side=Tix.TOP, padx=20, pady=2)
690
691 common = Tix.Frame(nb.network)
692 common.pack(side=Tix.RIGHT, padx=2, pady=2, fill=Tix.Y)
693 CreateCommonButtons(common)
694
695 a = Tix.Control(nb.network, value=12, label='Access Time: ')
696 w = Tix.Control(nb.network, value=400, label='Write Throughput: ')
697 r = Tix.Control(nb.network, value=400, label='Read Throughput: ')
698 c = Tix.Control(nb.network, value=1021, label='Capacity: ')
699 u = Tix.Control(nb.network, value=10, label='Users: ')
700 a.pack(side=Tix.TOP, padx=20, pady=2)
701 w.pack(side=Tix.TOP, padx=20, pady=2)
702 r.pack(side=Tix.TOP, padx=20, pady=2)
703 c.pack(side=Tix.TOP, padx=20, pady=2)
704 u.pack(side=Tix.TOP, padx=20, pady=2)
705
706 msg.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH)
707 nb.pack(side=Tix.TOP, padx=5, pady=5, fill=Tix.BOTH, expand=1)
708
709def CreateCommonButtons(f):
710 ok = Tix.Button(f, text='OK', width = 6)
711 cancel = Tix.Button(f, text='Cancel', width = 6)
712 ok.pack(side=Tix.TOP, padx=2, pady=2)
713 cancel.pack(side=Tix.TOP, padx=2, pady=2)
714
715def MkDirList(nb, name):
716 w = nb.page(name)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000717 options = "label.padX 4"
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000718
Neal Norwitzac30ead2002-11-14 02:44:08 +0000719 dir = Tix.LabelFrame(w, label='tixDirList', options=options)
720 fsbox = Tix.LabelFrame(w, label='tixExFileSelectBox', options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000721 MkDirListWidget(dir.frame)
722 MkExFileWidget(fsbox.frame)
723 dir.form(top=0, left=0, right='%40', bottom=-1)
724 fsbox.form(top=0, left='%40', right=-1, bottom=-1)
725
726def MkDirListWidget(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000727 """The TixDirList widget gives a graphical representation of the file
728 system directory and makes it easy for the user to choose and access
729 directories.
730 """
731 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000732 relief=Tix.FLAT, width=240, anchor=Tix.N,
Neal Norwitzac30ead2002-11-14 02:44:08 +0000733 text='The Tix DirList widget gives a graphical representation of the file system directory and makes it easy for the user to choose and access directories.')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000734 dirlist = Tix.DirList(w, options='hlist.padY 1 hlist.width 25 hlist.height 16')
735 msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3)
736 dirlist.pack(side=Tix.TOP, padx=3, pady=3)
737
738def MkExFileWidget(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000739 """The TixExFileSelectBox widget is more user friendly than the Motif
740 style FileSelectBox. """
741 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000742 relief=Tix.FLAT, width=240, anchor=Tix.N,
Neal Norwitzac30ead2002-11-14 02:44:08 +0000743 text='The Tix ExFileSelectBox widget is more user friendly than the Motif style FileSelectBox.')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000744 # There's a bug in the ComboBoxes - the scrolledlistbox is destroyed
745 box = Tix.ExFileSelectBox(w, bd=2, relief=Tix.RAISED)
746 msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3)
747 box.pack(side=Tix.TOP, padx=3, pady=3)
748
749###
750### List of all the demos we want to show off
751comments = {'widget' : 'Widget Demos', 'image' : 'Image Demos'}
752samples = {'Balloon' : 'Balloon',
753 'Button Box' : 'BtnBox',
754 'Combo Box' : 'ComboBox',
755 'Compound Image' : 'CmpImg',
Martin v. Löwis20efa682001-11-11 14:07:37 +0000756 'Directory List' : 'DirList',
757 'Directory Tree' : 'DirTree',
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000758 'Control' : 'Control',
759 'Notebook' : 'NoteBook',
760 'Option Menu' : 'OptMenu',
Martin v. Löwis652e1912001-11-25 14:50:56 +0000761 'Paned Window' : 'PanedWin',
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000762 'Popup Menu' : 'PopMenu',
763 'ScrolledHList (1)' : 'SHList1',
764 'ScrolledHList (2)' : 'SHList2',
765 'Tree (dynamic)' : 'Tree'
766}
767
Martin v. Löwis20efa682001-11-11 14:07:37 +0000768# There are still a lot of demos to be translated:
769## set root {
770## {d "File Selectors" file }
771## {d "Hierachical ListBox" hlist }
772## {d "Tabular ListBox" tlist {c tixTList}}
773## {d "Grid Widget" grid {c tixGrid}}
774## {d "Manager Widgets" manager }
775## {d "Scrolled Widgets" scroll }
776## {d "Miscellaneous Widgets" misc }
777## {d "Image Types" image }
778## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000779##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000780## set image {
781## {d "Compound Image" cmpimg }
782## {d "XPM Image" xpm {i pixmap}}
783## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000784##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000785## set cmpimg {
Neal Norwitzac30ead2002-11-14 02:44:08 +0000786##done {f "In Buttons" CmpImg.tcl }
Martin v. Löwis20efa682001-11-11 14:07:37 +0000787## {f "In NoteBook" CmpImg2.tcl }
788## {f "Notebook Color Tabs" CmpImg4.tcl }
789## {f "Icons" CmpImg3.tcl }
790## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000791##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000792## set xpm {
793## {f "In Button" Xpm.tcl {i pixmap}}
794## {f "In Menu" Xpm1.tcl {i pixmap}}
795## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000796##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000797## set file {
798##added {f DirList DirList.tcl }
799##added {f DirTree DirTree.tcl }
800## {f DirSelectDialog DirDlg.tcl }
801## {f ExFileSelectDialog EFileDlg.tcl }
802## {f FileSelectDialog FileDlg.tcl }
803## {f FileEntry FileEnt.tcl }
804## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000805##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000806## set hlist {
807## {f HList HList1.tcl }
808## {f CheckList ChkList.tcl {c tixCheckList}}
809##done {f "ScrolledHList (1)" SHList.tcl }
810##done {f "ScrolledHList (2)" SHList2.tcl }
811##done {f Tree Tree.tcl }
812##done {f "Tree (Dynamic)" DynTree.tcl {v win}}
813## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000814##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000815## set tlist {
816## {f "ScrolledTList (1)" STList1.tcl {c tixTList}}
817## {f "ScrolledTList (2)" STList2.tcl {c tixTList}}
818## }
819## global tcl_platform
820## # This demo hangs windows
821## if {$tcl_platform(platform) != "windows"} {
822##na lappend tlist {f "TList File Viewer" STList3.tcl {c tixTList}}
823## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000824##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000825## set grid {
826##na {f "Simple Grid" SGrid0.tcl {c tixGrid}}
827##na {f "ScrolledGrid" SGrid1.tcl {c tixGrid}}
828##na {f "Editable Grid" EditGrid.tcl {c tixGrid}}
829## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000830##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000831## set scroll {
832## {f ScrolledListBox SListBox.tcl }
833## {f ScrolledText SText.tcl }
834## {f ScrolledWindow SWindow.tcl }
835##na {f "Canvas Object View" CObjView.tcl {c tixCObjView}}
836## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000837##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000838## set manager {
Neal Norwitzac30ead2002-11-14 02:44:08 +0000839## {f ListNoteBook ListNBK.tcl }
Martin v. Löwis652e1912001-11-25 14:50:56 +0000840##done {f NoteBook NoteBook.tcl }
841##done {f PanedWindow PanedWin.tcl }
Martin v. Löwis20efa682001-11-11 14:07:37 +0000842## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000843##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000844## set misc {
845##done {f Balloon Balloon.tcl }
846##done {f ButtonBox BtnBox.tcl }
847##done {f ComboBox ComboBox.tcl }
848##done {f Control Control.tcl }
849## {f LabelEntry LabEntry.tcl }
850## {f LabelFrame LabFrame.tcl }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000851## {f Meter Meter.tcl {c tixMeter}}
Martin v. Löwis20efa682001-11-11 14:07:37 +0000852##done {f OptionMenu OptMenu.tcl }
853##done {f PopupMenu PopMenu.tcl }
854## {f Select Select.tcl }
855## {f StdButtonBox StdBBox.tcl }
856## }
857##
858
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000859stypes = {}
860stypes['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control',
Martin v. Löwis20efa682001-11-11 14:07:37 +0000861 'Directory List', 'Directory Tree',
Martin v. Löwis652e1912001-11-25 14:50:56 +0000862 'Notebook', 'Option Menu', 'Popup Menu', 'Paned Window',
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000863 'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)']
864stypes['image'] = ['Compound Image']
865
866def MkSample(nb, name):
867 w = nb.page(name)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000868 options = "label.padX 4"
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000869
Martin v. Löwis652e1912001-11-25 14:50:56 +0000870 pane = Tix.PanedWindow(w, orientation='horizontal')
871 pane.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH)
872 f1 = pane.add('list', expand='1')
873 f2 = pane.add('text', expand='5')
874 f1['relief'] = 'flat'
875 f2['relief'] = 'flat'
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000876
Neal Norwitzac30ead2002-11-14 02:44:08 +0000877 lab = Tix.LabelFrame(f1, label='Select a sample program:')
878 lab.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5, pady=5)
879 lab1 = Tix.LabelFrame(f2, label='Source:')
880 lab1.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5, pady=5)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000881
Neal Norwitzac30ead2002-11-14 02:44:08 +0000882 slb = Tix.Tree(lab.frame, options='hlist.width 20')
Martin v. Löwis652e1912001-11-25 14:50:56 +0000883 slb.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5)
884
Neal Norwitzac30ead2002-11-14 02:44:08 +0000885 stext = Tix.ScrolledText(lab1.frame, name='stext')
Martin v. Löwis20efa682001-11-11 14:07:37 +0000886 font = root.tk.eval('tix option get fixed_font')
887 stext.text.config(font=font)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000888
Neal Norwitzac30ead2002-11-14 02:44:08 +0000889 frame = Tix.Frame(lab1.frame, name='frame')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000890
Martin v. Löwis652e1912001-11-25 14:50:56 +0000891 run = Tix.Button(frame, text='Run ...', name='run')
892 view = Tix.Button(frame, text='View Source ...', name='view')
893 run.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE)
894 view.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000895
896 stext.text['bg'] = slb.hlist['bg']
897 stext.text['state'] = 'disabled'
898 stext.text['wrap'] = 'none'
Martin v. Löwis652e1912001-11-25 14:50:56 +0000899 stext.text['width'] = 80
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000900
Neal Norwitzac30ead2002-11-14 02:44:08 +0000901 frame.pack(side=Tix.BOTTOM, expand=0, fill=Tix.X, padx=7)
902 stext.pack(side=Tix.TOP, expand=0, fill=Tix.BOTH, padx=7)
903
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000904 slb.hlist['separator'] = '.'
905 slb.hlist['width'] = 25
906 slb.hlist['drawbranch'] = 0
907 slb.hlist['indent'] = 10
908 slb.hlist['wideselect'] = 1
Martin v. Löwis652e1912001-11-25 14:50:56 +0000909 slb.hlist['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
910 slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'browse')
911
912 run['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
913 view['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'view')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000914
915 for type in ['widget', 'image']:
916 if type != 'widget':
917 x = Tix.Frame(slb.hlist, bd=2, height=2, width=150,
918 relief=Tix.SUNKEN, bg=slb.hlist['bg'])
919 slb.hlist.add_child(itemtype=Tix.WINDOW, window=x, state='disabled')
920 x = slb.hlist.add_child(itemtype=Tix.TEXT, state='disabled',
921 text=comments[type])
922 for key in stypes[type]:
923 slb.hlist.add_child(x, itemtype=Tix.TEXT, data=key,
924 text=key)
925 slb.hlist.selection_clear()
926
927 run['state'] = 'disabled'
928 view['state'] = 'disabled'
929
Martin v. Löwis652e1912001-11-25 14:50:56 +0000930def Sample_Action(w, slb, stext, run, view, action):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000931 global demo
932
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000933 hlist = slb.hlist
934 anchor = hlist.info_anchor()
935 if not anchor:
936 run['state'] = 'disabled'
937 view['state'] = 'disabled'
938 elif not hlist.info_parent(anchor):
939 # a comment
940 return
941
942 run['state'] = 'normal'
943 view['state'] = 'normal'
944 key = hlist.info_data(anchor)
945 title = key
946 prog = samples[key]
947
948 if action == 'run':
949 exec('import ' + prog)
950 w = Tix.Toplevel()
951 w.title(title)
952 rtn = eval(prog + '.RunSample')
953 rtn(w)
954 elif action == 'view':
955 w = Tix.Toplevel()
956 w.title('Source view: ' + title)
957 LoadFile(w, demo.dir + '/samples/' + prog + '.py')
958 elif action == 'browse':
959 ReadFile(stext.text, demo.dir + '/samples/' + prog + '.py')
960
961def LoadFile(w, fname):
Martin v. Löwis20efa682001-11-11 14:07:37 +0000962 global root
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000963 b = Tix.Button(w, text='Close', command=w.destroy)
964 t = Tix.ScrolledText(w)
965 # b.form(left=0, bottom=0, padx=4, pady=4)
966 # t.form(left=0, bottom=b, right='-0', top=0)
967 t.pack()
968 b.pack()
969
Martin v. Löwis20efa682001-11-11 14:07:37 +0000970 font = root.tk.eval('tix option get fixed_font')
971 t.text.config(font=font)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000972 t.text['bd'] = 2
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000973 t.text['wrap'] = 'none'
974
975 ReadFile(t.text, fname)
976
977def ReadFile(w, fname):
978 old_state = w['state']
979 w['state'] = 'normal'
980 w.delete('0.0', Tix.END)
981
982 try:
983 f = open(fname)
984 lines = f.readlines()
985 for s in lines:
986 w.insert(Tix.END, s)
987 f.close()
988 finally:
989# w.see('1.0')
990 w['state'] = old_state
991
992if __name__ == '__main__':
Martin v. Löwis20efa682001-11-11 14:07:37 +0000993 root = Tix.Tk()
994 RunMain(root)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000995