blob: f6bb70e438c1b138788040cc8b3c67490f82768f [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
Martin v. Löwis46874282002-12-06 10:33:45 +0000477 sls = Tix.LabelFrame(w, label='Tix.ScrolledListBox', options=options)
478 swn = Tix.LabelFrame(w, label='Tix.ScrolledWindow', options=options)
479 stx = Tix.LabelFrame(w, label='Tix.ScrolledText', 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 Norwitz731a9862002-12-10 02:18:49 +0000547 image1 = win.window.image_create('photo', file=file)
Martin v. Löwis652e1912001-11-25 14:50:56 +0000548 lbl = Tix.Label(win.window, image=image1)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000549 lbl.pack(expand=1, fill=Tix.BOTH)
550
551 win.place(x=30, y=150, width=190, height=120)
552
553 rh = Tix.ResizeHandle(top, bg='black',
554 relief=Tix.RAISED,
555 handlesize=8, gridded=1, minwidth=50, minheight=30)
556 btn = Tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SWindow_reset(w,x))
557 top.propagate(0)
558 msg.pack(fill=Tix.X)
559 btn.pack(anchor=Tix.CENTER)
560 top.pack(expand=1, fill=Tix.BOTH)
561 bot.pack(fill=Tix.BOTH)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000562
563def SWindow_reset(rh, win):
564 win.place(x=30, y=150, width=190, height=120)
565 win.update()
566 rh.attach_widget(win)
567
568def MkSText(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000569 """The TixScrolledWindow widget allows you to scroll any kind of Tk
570 widget. It is more versatile than a scrolled canvas widget."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000571 top = Tix.Frame(w, width=330, height=330)
572 bot = Tix.Frame(w)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000573 msg = Tix.Message(top,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000574 relief=Tix.FLAT, width=200, anchor=Tix.N,
Neal Norwitzac30ead2002-11-14 02:44:08 +0000575 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 +0000576
577 win = Tix.ScrolledText(top, scrollbar='auto')
578# win.text['wrap'] = 'none'
579 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.')
580 win.place(x=30, y=150, width=190, height=100)
581
582 rh = Tix.ResizeHandle(top, bg='black',
583 relief=Tix.RAISED,
584 handlesize=8, gridded=1, minwidth=50, minheight=30)
585 btn = Tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SText_reset(w,x))
586 top.propagate(0)
587 msg.pack(fill=Tix.X)
588 btn.pack(anchor=Tix.CENTER)
589 top.pack(expand=1, fill=Tix.BOTH)
590 bot.pack(fill=Tix.BOTH)
591 win.bind('<Map>', func=lambda arg=0, rh=rh, win=win:
592 win.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(win)))
593
594def SText_reset(rh, win):
595 win.place(x=30, y=150, width=190, height=120)
596 win.update()
597 rh.attach_widget(win)
598
599def MkManager(nb, name):
600 w = nb.page(name)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000601 options='label.padX 4'
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000602
Martin v. Löwis46874282002-12-06 10:33:45 +0000603 pane = Tix.LabelFrame(w, label='Tix.PanedWindow', options=options)
604 note = Tix.LabelFrame(w, label='Tix.NoteBook', options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000605
606 MkPanedWindow(pane.frame)
607 MkNoteBook(note.frame)
608
609 pane.form(top=0, left=0, right=note, bottom=-1)
610 note.form(top=0, right=-1, bottom=-1)
611
612def MkPanedWindow(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000613 """The PanedWindow widget allows the user to interactively manipulate
614 the sizes of several panes. The panes can be arranged either vertically
615 or horizontally.
616 """
617 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000618 relief=Tix.FLAT, width=240, anchor=Tix.N,
619 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 +0000620 group = Tix.LabelEntry(w, label='Newsgroup:', options='entry.width 25')
621 group.entry.insert(0,'comp.lang.python')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000622 pane = Tix.PanedWindow(w, orientation='vertical')
623
624 p1 = pane.add('list', min=70, size=100)
625 p2 = pane.add('text', min=70)
626 list = Tix.ScrolledListBox(p1)
627 text = Tix.ScrolledText(p2)
628
Martin v. Löwis652e1912001-11-25 14:50:56 +0000629 list.listbox.insert(Tix.END, " 12324 Re: Tkinter is good for your health")
630 list.listbox.insert(Tix.END, "+ 12325 Re: Tkinter is good for your health")
631 list.listbox.insert(Tix.END, "+ 12326 Re: Tix is even better for your health (Was: Tkinter is good...)")
632 list.listbox.insert(Tix.END, " 12327 Re: Tix is even better for your health (Was: Tkinter is good...)")
633 list.listbox.insert(Tix.END, "+ 12328 Re: Tix is even better for your health (Was: Tkinter is good...)")
634 list.listbox.insert(Tix.END, " 12329 Re: Tix is even better for your health (Was: Tkinter is good...)")
635 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 +0000636
637 text.text['bg'] = list.listbox['bg']
638 text.text['wrap'] = 'none'
639 text.text.insert(Tix.END, """
Martin v. Löwis652e1912001-11-25 14:50:56 +0000640Mon, 19 Jun 1995 11:39:52 comp.lang.python Thread 34 of 220
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000641Lines 353 A new way to put text and bitmaps together iNo responses
642ioi@blue.seas.upenn.edu Ioi K. Lam at University of Pennsylvania
643
644Hi,
645
646I have implemented a new image type called "compound". It allows you
647to glue together a bunch of bitmaps, images and text strings together
648to form a bigger image. Then you can use this image with widgets that
649support the -image option. For example, you can display a text string string
650together with a bitmap, at the same time, inside a TK button widget.
651""")
652 list.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6)
653 text.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6)
654
655 msg.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH)
656 group.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH)
657 pane.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH, expand=1)
658
659def MkNoteBook(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000660 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000661 relief=Tix.FLAT, width=240, anchor=Tix.N,
662 text='The NoteBook widget allows you to layout a complex interface into individual pages.')
Neal Norwitzac30ead2002-11-14 02:44:08 +0000663 # prefix = Tix.OptionName(w)
664 # if not prefix: prefix = ''
665 # w.option_add('*' + prefix + '*TixNoteBook*tagPadX', 8)
666 options = "entry.width %d label.width %d label.anchor %s" % (10, 18, Tix.E)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000667
Neal Norwitzac30ead2002-11-14 02:44:08 +0000668 nb = Tix.NoteBook(w, ipadx=6, ipady=6, options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000669 nb.add('hard_disk', label="Hard Disk", underline=0)
670 nb.add('network', label="Network", underline=0)
671
672 # Frame for the buttons that are present on all pages
673 common = Tix.Frame(nb.hard_disk)
674 common.pack(side=Tix.RIGHT, padx=2, pady=2, fill=Tix.Y)
675 CreateCommonButtons(common)
676
677 # Widgets belonging only to this page
678 a = Tix.Control(nb.hard_disk, value=12, label='Access Time: ')
679 w = Tix.Control(nb.hard_disk, value=400, label='Write Throughput: ')
680 r = Tix.Control(nb.hard_disk, value=400, label='Read Throughput: ')
681 c = Tix.Control(nb.hard_disk, value=1021, label='Capacity: ')
682 a.pack(side=Tix.TOP, padx=20, pady=2)
683 w.pack(side=Tix.TOP, padx=20, pady=2)
684 r.pack(side=Tix.TOP, padx=20, pady=2)
685 c.pack(side=Tix.TOP, padx=20, pady=2)
686
687 common = Tix.Frame(nb.network)
688 common.pack(side=Tix.RIGHT, padx=2, pady=2, fill=Tix.Y)
689 CreateCommonButtons(common)
690
691 a = Tix.Control(nb.network, value=12, label='Access Time: ')
692 w = Tix.Control(nb.network, value=400, label='Write Throughput: ')
693 r = Tix.Control(nb.network, value=400, label='Read Throughput: ')
694 c = Tix.Control(nb.network, value=1021, label='Capacity: ')
695 u = Tix.Control(nb.network, value=10, label='Users: ')
696 a.pack(side=Tix.TOP, padx=20, pady=2)
697 w.pack(side=Tix.TOP, padx=20, pady=2)
698 r.pack(side=Tix.TOP, padx=20, pady=2)
699 c.pack(side=Tix.TOP, padx=20, pady=2)
700 u.pack(side=Tix.TOP, padx=20, pady=2)
701
702 msg.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH)
703 nb.pack(side=Tix.TOP, padx=5, pady=5, fill=Tix.BOTH, expand=1)
704
705def CreateCommonButtons(f):
706 ok = Tix.Button(f, text='OK', width = 6)
707 cancel = Tix.Button(f, text='Cancel', width = 6)
708 ok.pack(side=Tix.TOP, padx=2, pady=2)
709 cancel.pack(side=Tix.TOP, padx=2, pady=2)
710
711def MkDirList(nb, name):
712 w = nb.page(name)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000713 options = "label.padX 4"
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000714
Martin v. Löwis46874282002-12-06 10:33:45 +0000715 dir = Tix.LabelFrame(w, label='Tix.DirList', options=options)
716 fsbox = Tix.LabelFrame(w, label='Tix.ExFileSelectBox', options=options)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000717 MkDirListWidget(dir.frame)
718 MkExFileWidget(fsbox.frame)
719 dir.form(top=0, left=0, right='%40', bottom=-1)
720 fsbox.form(top=0, left='%40', right=-1, bottom=-1)
721
722def MkDirListWidget(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000723 """The TixDirList widget gives a graphical representation of the file
724 system directory and makes it easy for the user to choose and access
725 directories.
726 """
727 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000728 relief=Tix.FLAT, width=240, anchor=Tix.N,
Neal Norwitzac30ead2002-11-14 02:44:08 +0000729 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 +0000730 dirlist = Tix.DirList(w, options='hlist.padY 1 hlist.width 25 hlist.height 16')
731 msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3)
732 dirlist.pack(side=Tix.TOP, padx=3, pady=3)
733
734def MkExFileWidget(w):
Neal Norwitzac30ead2002-11-14 02:44:08 +0000735 """The TixExFileSelectBox widget is more user friendly than the Motif
736 style FileSelectBox. """
737 msg = Tix.Message(w,
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000738 relief=Tix.FLAT, width=240, anchor=Tix.N,
Neal Norwitzac30ead2002-11-14 02:44:08 +0000739 text='The Tix ExFileSelectBox widget is more user friendly than the Motif style FileSelectBox.')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000740 # There's a bug in the ComboBoxes - the scrolledlistbox is destroyed
741 box = Tix.ExFileSelectBox(w, bd=2, relief=Tix.RAISED)
742 msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3)
743 box.pack(side=Tix.TOP, padx=3, pady=3)
744
745###
746### List of all the demos we want to show off
747comments = {'widget' : 'Widget Demos', 'image' : 'Image Demos'}
748samples = {'Balloon' : 'Balloon',
749 'Button Box' : 'BtnBox',
750 'Combo Box' : 'ComboBox',
751 'Compound Image' : 'CmpImg',
Martin v. Löwis20efa682001-11-11 14:07:37 +0000752 'Directory List' : 'DirList',
753 'Directory Tree' : 'DirTree',
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000754 'Control' : 'Control',
755 'Notebook' : 'NoteBook',
756 'Option Menu' : 'OptMenu',
Martin v. Löwis652e1912001-11-25 14:50:56 +0000757 'Paned Window' : 'PanedWin',
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000758 'Popup Menu' : 'PopMenu',
759 'ScrolledHList (1)' : 'SHList1',
760 'ScrolledHList (2)' : 'SHList2',
761 'Tree (dynamic)' : 'Tree'
762}
763
Martin v. Löwis20efa682001-11-11 14:07:37 +0000764# There are still a lot of demos to be translated:
765## set root {
766## {d "File Selectors" file }
767## {d "Hierachical ListBox" hlist }
768## {d "Tabular ListBox" tlist {c tixTList}}
769## {d "Grid Widget" grid {c tixGrid}}
770## {d "Manager Widgets" manager }
771## {d "Scrolled Widgets" scroll }
772## {d "Miscellaneous Widgets" misc }
773## {d "Image Types" image }
774## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000775##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000776## set image {
777## {d "Compound Image" cmpimg }
778## {d "XPM Image" xpm {i pixmap}}
779## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000780##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000781## set cmpimg {
Neal Norwitzac30ead2002-11-14 02:44:08 +0000782##done {f "In Buttons" CmpImg.tcl }
Martin v. Löwis20efa682001-11-11 14:07:37 +0000783## {f "In NoteBook" CmpImg2.tcl }
784## {f "Notebook Color Tabs" CmpImg4.tcl }
785## {f "Icons" CmpImg3.tcl }
786## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000787##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000788## set xpm {
789## {f "In Button" Xpm.tcl {i pixmap}}
790## {f "In Menu" Xpm1.tcl {i pixmap}}
791## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000792##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000793## set file {
794##added {f DirList DirList.tcl }
795##added {f DirTree DirTree.tcl }
796## {f DirSelectDialog DirDlg.tcl }
797## {f ExFileSelectDialog EFileDlg.tcl }
798## {f FileSelectDialog FileDlg.tcl }
799## {f FileEntry FileEnt.tcl }
800## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000801##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000802## set hlist {
803## {f HList HList1.tcl }
804## {f CheckList ChkList.tcl {c tixCheckList}}
805##done {f "ScrolledHList (1)" SHList.tcl }
806##done {f "ScrolledHList (2)" SHList2.tcl }
807##done {f Tree Tree.tcl }
808##done {f "Tree (Dynamic)" DynTree.tcl {v win}}
809## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000810##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000811## set tlist {
812## {f "ScrolledTList (1)" STList1.tcl {c tixTList}}
813## {f "ScrolledTList (2)" STList2.tcl {c tixTList}}
814## }
815## global tcl_platform
816## # This demo hangs windows
817## if {$tcl_platform(platform) != "windows"} {
818##na lappend tlist {f "TList File Viewer" STList3.tcl {c tixTList}}
819## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000820##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000821## set grid {
822##na {f "Simple Grid" SGrid0.tcl {c tixGrid}}
823##na {f "ScrolledGrid" SGrid1.tcl {c tixGrid}}
824##na {f "Editable Grid" EditGrid.tcl {c tixGrid}}
825## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000826##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000827## set scroll {
828## {f ScrolledListBox SListBox.tcl }
829## {f ScrolledText SText.tcl }
830## {f ScrolledWindow SWindow.tcl }
831##na {f "Canvas Object View" CObjView.tcl {c tixCObjView}}
832## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000833##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000834## set manager {
Neal Norwitzac30ead2002-11-14 02:44:08 +0000835## {f ListNoteBook ListNBK.tcl }
Martin v. Löwis652e1912001-11-25 14:50:56 +0000836##done {f NoteBook NoteBook.tcl }
837##done {f PanedWindow PanedWin.tcl }
Martin v. Löwis20efa682001-11-11 14:07:37 +0000838## }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000839##
Martin v. Löwis20efa682001-11-11 14:07:37 +0000840## set misc {
841##done {f Balloon Balloon.tcl }
842##done {f ButtonBox BtnBox.tcl }
843##done {f ComboBox ComboBox.tcl }
844##done {f Control Control.tcl }
845## {f LabelEntry LabEntry.tcl }
846## {f LabelFrame LabFrame.tcl }
Neal Norwitzac30ead2002-11-14 02:44:08 +0000847## {f Meter Meter.tcl {c tixMeter}}
Martin v. Löwis20efa682001-11-11 14:07:37 +0000848##done {f OptionMenu OptMenu.tcl }
849##done {f PopupMenu PopMenu.tcl }
850## {f Select Select.tcl }
851## {f StdButtonBox StdBBox.tcl }
852## }
853##
854
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000855stypes = {}
856stypes['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control',
Martin v. Löwis20efa682001-11-11 14:07:37 +0000857 'Directory List', 'Directory Tree',
Martin v. Löwis652e1912001-11-25 14:50:56 +0000858 'Notebook', 'Option Menu', 'Popup Menu', 'Paned Window',
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000859 'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)']
860stypes['image'] = ['Compound Image']
861
862def MkSample(nb, name):
863 w = nb.page(name)
Neal Norwitzac30ead2002-11-14 02:44:08 +0000864 options = "label.padX 4"
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000865
Martin v. Löwis652e1912001-11-25 14:50:56 +0000866 pane = Tix.PanedWindow(w, orientation='horizontal')
867 pane.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH)
868 f1 = pane.add('list', expand='1')
869 f2 = pane.add('text', expand='5')
870 f1['relief'] = 'flat'
871 f2['relief'] = 'flat'
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000872
Neal Norwitzac30ead2002-11-14 02:44:08 +0000873 lab = Tix.LabelFrame(f1, label='Select a sample program:')
874 lab.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5, pady=5)
875 lab1 = Tix.LabelFrame(f2, label='Source:')
876 lab1.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5, pady=5)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000877
Neal Norwitzac30ead2002-11-14 02:44:08 +0000878 slb = Tix.Tree(lab.frame, options='hlist.width 20')
Martin v. Löwis652e1912001-11-25 14:50:56 +0000879 slb.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5)
880
Neal Norwitzac30ead2002-11-14 02:44:08 +0000881 stext = Tix.ScrolledText(lab1.frame, name='stext')
Martin v. Löwis20efa682001-11-11 14:07:37 +0000882 font = root.tk.eval('tix option get fixed_font')
883 stext.text.config(font=font)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000884
Neal Norwitzac30ead2002-11-14 02:44:08 +0000885 frame = Tix.Frame(lab1.frame, name='frame')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000886
Martin v. Löwis652e1912001-11-25 14:50:56 +0000887 run = Tix.Button(frame, text='Run ...', name='run')
888 view = Tix.Button(frame, text='View Source ...', name='view')
889 run.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE)
890 view.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000891
892 stext.text['bg'] = slb.hlist['bg']
893 stext.text['state'] = 'disabled'
894 stext.text['wrap'] = 'none'
Martin v. Löwis652e1912001-11-25 14:50:56 +0000895 stext.text['width'] = 80
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000896
Neal Norwitzac30ead2002-11-14 02:44:08 +0000897 frame.pack(side=Tix.BOTTOM, expand=0, fill=Tix.X, padx=7)
898 stext.pack(side=Tix.TOP, expand=0, fill=Tix.BOTH, padx=7)
899
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000900 slb.hlist['separator'] = '.'
901 slb.hlist['width'] = 25
902 slb.hlist['drawbranch'] = 0
903 slb.hlist['indent'] = 10
904 slb.hlist['wideselect'] = 1
Martin v. Löwis652e1912001-11-25 14:50:56 +0000905 slb.hlist['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
906 slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'browse')
907
908 run['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
909 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 +0000910
911 for type in ['widget', 'image']:
912 if type != 'widget':
913 x = Tix.Frame(slb.hlist, bd=2, height=2, width=150,
914 relief=Tix.SUNKEN, bg=slb.hlist['bg'])
915 slb.hlist.add_child(itemtype=Tix.WINDOW, window=x, state='disabled')
916 x = slb.hlist.add_child(itemtype=Tix.TEXT, state='disabled',
917 text=comments[type])
918 for key in stypes[type]:
919 slb.hlist.add_child(x, itemtype=Tix.TEXT, data=key,
920 text=key)
921 slb.hlist.selection_clear()
922
923 run['state'] = 'disabled'
924 view['state'] = 'disabled'
925
Martin v. Löwis652e1912001-11-25 14:50:56 +0000926def Sample_Action(w, slb, stext, run, view, action):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000927 global demo
928
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000929 hlist = slb.hlist
930 anchor = hlist.info_anchor()
931 if not anchor:
932 run['state'] = 'disabled'
933 view['state'] = 'disabled'
934 elif not hlist.info_parent(anchor):
935 # a comment
936 return
937
938 run['state'] = 'normal'
939 view['state'] = 'normal'
940 key = hlist.info_data(anchor)
941 title = key
942 prog = samples[key]
943
944 if action == 'run':
945 exec('import ' + prog)
946 w = Tix.Toplevel()
947 w.title(title)
948 rtn = eval(prog + '.RunSample')
949 rtn(w)
950 elif action == 'view':
951 w = Tix.Toplevel()
952 w.title('Source view: ' + title)
953 LoadFile(w, demo.dir + '/samples/' + prog + '.py')
954 elif action == 'browse':
955 ReadFile(stext.text, demo.dir + '/samples/' + prog + '.py')
956
957def LoadFile(w, fname):
Martin v. Löwis20efa682001-11-11 14:07:37 +0000958 global root
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000959 b = Tix.Button(w, text='Close', command=w.destroy)
960 t = Tix.ScrolledText(w)
961 # b.form(left=0, bottom=0, padx=4, pady=4)
962 # t.form(left=0, bottom=b, right='-0', top=0)
963 t.pack()
964 b.pack()
965
Martin v. Löwis20efa682001-11-11 14:07:37 +0000966 font = root.tk.eval('tix option get fixed_font')
967 t.text.config(font=font)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000968 t.text['bd'] = 2
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000969 t.text['wrap'] = 'none'
970
971 ReadFile(t.text, fname)
972
973def ReadFile(w, fname):
974 old_state = w['state']
975 w['state'] = 'normal'
976 w.delete('0.0', Tix.END)
977
978 try:
979 f = open(fname)
980 lines = f.readlines()
981 for s in lines:
982 w.insert(Tix.END, s)
983 f.close()
984 finally:
985# w.see('1.0')
986 w['state'] = old_state
987
988if __name__ == '__main__':
Martin v. Löwis20efa682001-11-11 14:07:37 +0000989 root = Tix.Tk()
990 RunMain(root)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000991