1 #! /usr/local/bin/python
6 # This is a demo program of all Tix widgets available from Python. If
7 # you have installed Python & Tix properly, you can execute this as
20 demo
.dir = None # script directory
21 demo
.balloon
= None # balloon widget
22 demo
.useBalloons
= Tix
.StringVar()
23 demo
.useBalloons
.set('0')
24 demo
.statusbar
= None # status bar widget
25 demo
.welmsg
= None # Msg widget
26 demo
.welfont
= '' # font name
27 demo
.welsize
= '' # font size
32 progname
= sys
.argv
[0]
33 dirname
= os
.path
.dirname(progname
)
34 if dirname
and dirname
!= os
.curdir
:
37 for i
in range(len(sys
.path
)):
39 if p
in ("", os
.curdir
):
42 sys
.path
[index
] = dirname
44 sys
.path
.insert(0, dirname
)
46 demo
.dir = os
.getcwd()
47 sys
.path
.insert(0, demo
.dir+'/samples')
51 root
.title('Tix Widget Demonstration')
52 root
.geometry('780x570+50+50')
54 demo
.balloon
= Tix
.Balloon(root
)
55 frame1
= MkMainMenu(root
)
56 frame2
= MkMainNotebook(root
)
57 frame3
= MkMainStatus(root
)
58 frame1
.pack(side
=Tix
.TOP
, fill
=Tix
.X
)
59 frame3
.pack(side
=Tix
.BOTTOM
, fill
=Tix
.X
)
60 frame2
.pack(side
=Tix
.TOP
, expand
=1, fill
=Tix
.BOTH
, padx
=4, pady
=4)
61 demo
.balloon
['statusbar'] = demo
.statusbar
64 def exit_cmd(event
=None):
70 w
= Tix
.Frame(top
, bd
=2, relief
=Tix
.RAISED
)
71 file = Tix
.Menubutton(w
, text
='File', underline
=0, takefocus
=0)
72 help = Tix
.Menubutton(w
, text
='Help', underline
=0, takefocus
=0)
73 file.pack(side
=Tix
.LEFT
)
74 help.pack(side
=Tix
.RIGHT
)
80 fm
.add_command(label
='Exit', underline
=1, accelerator
='Ctrl+X',
82 hm
.add_checkbutton(label
='BalloonHelp', underline
=0, command
=ToggleHelp
,
83 variable
=demo
.useBalloons
)
84 # The trace variable option doesn't seem to work, instead I use 'command'
85 #apply(w.tk.call, ('trace', 'variable', demo.useBalloons, 'w',
87 top
.bind_all("<Control-x>", exit_cmd
)
88 top
.bind_all("<Control-X>", exit_cmd
)
91 def MkMainNotebook(top
):
92 top
.option_add('*TixNoteBook*tagPadX', 6)
93 top
.option_add('*TixNoteBook*tagPadY', 4)
94 top
.option_add('*TixNoteBook*borderWidth', 2)
95 top
.option_add('*TixNoteBook*font',
96 '-*-helvetica-bold-o-normal-*-14-*-*-*-*-*-*-*')
97 w
= Tix
.NoteBook(top
, ipadx
=5, ipady
=5)
98 w
.add('wel', label
='Welcome', underline
=0,
99 createcmd
=lambda w
=w
, name
='wel': MkWelcome(w
, name
))
100 w
.add('cho', label
='Choosers', underline
=0,
101 createcmd
=lambda w
=w
, name
='cho': MkChoosers(w
, name
))
102 w
.add('scr', label
='Scrolled Widgets', underline
=0,
103 createcmd
=lambda w
=w
, name
='scr': MkScroll(w
, name
))
104 w
.add('mgr', label
='Manager Widgets', underline
=0,
105 createcmd
=lambda w
=w
, name
='mgr': MkManager(w
, name
))
106 w
.add('dir', label
='Directory List', underline
=0,
107 createcmd
=lambda w
=w
, name
='dir': MkDirList(w
, name
))
108 w
.add('exp', label
='Run Sample Programs', underline
=0,
109 createcmd
=lambda w
=w
, name
='exp': MkSample(w
, name
))
112 def MkMainStatus(top
):
115 w
= Tix
.Frame(top
, relief
=Tix
.RAISED
, bd
=1)
116 demo
.statusbar
= Tix
.Label(w
, relief
=Tix
.SUNKEN
, bd
=1, font
='-*-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*')
117 demo
.statusbar
.form(padx
=3, pady
=3, left
=0, right
='%70')
120 def MkWelcome(nb
, name
):
122 bar
= MkWelcomeBar(w
)
123 text
= MkWelcomeText(w
)
124 bar
.pack(side
=Tix
.TOP
, fill
=Tix
.X
, padx
=2, pady
=2)
125 text
.pack(side
=Tix
.TOP
, fill
=Tix
.BOTH
, expand
=1)
127 def MkWelcomeBar(top
):
130 w
= Tix
.Frame(top
, bd
=2, relief
=Tix
.GROOVE
)
131 b1
= Tix
.ComboBox(w
, command
=lambda w
=top
: MainTextFont(w
))
132 b2
= Tix
.ComboBox(w
, command
=lambda w
=top
: MainTextFont(w
))
133 b1
.entry
['width'] = 15
134 b1
.slistbox
.listbox
['height'] = 3
135 b2
.entry
['width'] = 4
136 b2
.slistbox
.listbox
['height'] = 3
141 b1
.insert(Tix
.END
, 'Courier')
142 b1
.insert(Tix
.END
, 'Helvetica')
143 b1
.insert(Tix
.END
, 'Lucida')
144 b1
.insert(Tix
.END
, 'Times Roman')
146 b2
.insert(Tix
.END
, '8')
147 b2
.insert(Tix
.END
, '10')
148 b2
.insert(Tix
.END
, '12')
149 b2
.insert(Tix
.END
, '14')
150 b2
.insert(Tix
.END
, '18')
155 b1
.pack(side
=Tix
.LEFT
, padx
=4, pady
=4)
156 b2
.pack(side
=Tix
.LEFT
, padx
=4, pady
=4)
158 demo
.balloon
.bind_widget(b1
, msg
='Choose\na font',
159 statusmsg
='Choose a font for this page')
160 demo
.balloon
.bind_widget(b2
, msg
='Point size',
161 statusmsg
='Choose the font size for this page')
164 def MkWelcomeText(top
):
167 w
= Tix
.ScrolledWindow(top
, scrollbar
='auto')
169 text
= 'Welcome to TIX in Python'
170 title
= Tix
.Label(win
, font
='-*-times-bold-r-normal-*-18-*-*-*-*-*-*-*',
171 bd
=0, width
=30, anchor
=Tix
.N
, text
=text
)
172 msg
= Tix
.Message(win
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
173 bd
=0, width
=400, anchor
=Tix
.N
,
174 text
='Tix is a set of mega-widgets based on TK. This program \
175 demonstrates the widgets in the Tix widget set. You can choose the pages \
176 in this window to look at the corresponding widgets. \n\n\
177 To quit this program, choose the "File | Exit" command.\n\n\
178 For more information, see http://tix.sourceforge.net.')
179 title
.pack(expand
=1, fill
=Tix
.BOTH
, padx
=10, pady
=10)
180 msg
.pack(expand
=1, fill
=Tix
.BOTH
, padx
=10, pady
=10)
189 font
= demo
.welfont
['value']
190 point
= demo
.welsize
['value']
191 if font
== 'Times Roman':
193 fontstr
= '-*-%s-bold-r-normal-*-%s-*-*-*-*-*-*-*' % (font
, point
)
194 demo
.welmsg
['font'] = fontstr
197 if demo
.useBalloons
.get() == '1':
198 demo
.balloon
['state'] = 'both'
200 demo
.balloon
['state'] = 'none'
202 def MkChoosers(nb
, name
):
204 prefix
= Tix
.OptionName(w
)
207 w
.option_add('*' + prefix
+ '*TixLabelFrame*label.padX', 4)
209 til
= Tix
.LabelFrame(w
, label
='Chooser Widgets')
210 cbx
= Tix
.LabelFrame(w
, label
='tixComboBox')
211 ctl
= Tix
.LabelFrame(w
, label
='tixControl')
212 sel
= Tix
.LabelFrame(w
, label
='tixSelect')
213 opt
= Tix
.LabelFrame(w
, label
='tixOptionMenu')
214 fil
= Tix
.LabelFrame(w
, label
='tixFileEntry')
215 fbx
= Tix
.LabelFrame(w
, label
='tixFileSelectBox')
216 tbr
= Tix
.LabelFrame(w
, label
='Tool Bar')
227 # First column: comBox and selector
228 cbx
.form(top
=0, left
=0, right
='%33')
229 sel
.form(left
=0, right
='&'+str(cbx
), top
=cbx
)
230 opt
.form(left
=0, right
='&'+str(cbx
), top
=sel
, bottom
=-1)
232 # Second column: title .. etc
233 til
.form(left
=cbx
, top
=0,right
='%66')
234 ctl
.form(left
=cbx
, right
='&'+str(til
), top
=til
)
235 fil
.form(left
=cbx
, right
='&'+str(til
), top
=ctl
)
236 tbr
.form(left
=cbx
, right
='&'+str(til
), top
=fil
, bottom
=-1)
239 # Third column: file selection
240 fbx
.form(right
=-1, top
=0, left
='%66')
243 prefix
= Tix
.OptionName(w
)
244 if not prefix
: prefix
= ''
245 w
.option_add('*' + prefix
+ '*TixComboBox*label.width', 10)
246 w
.option_add('*' + prefix
+ '*TixComboBox*label.anchor', Tix
.E
)
247 w
.option_add('*' + prefix
+ '*TixComboBox*entry.width', 14)
249 static
= Tix
.ComboBox(w
, label
='Static', editable
=0)
250 editable
= Tix
.ComboBox(w
, label
='Editable', editable
=1)
251 history
= Tix
.ComboBox(w
, label
='History', editable
=1, history
=1,
253 static
.insert(Tix
.END
, 'January')
254 static
.insert(Tix
.END
, 'February')
255 static
.insert(Tix
.END
, 'March')
256 static
.insert(Tix
.END
, 'April')
257 static
.insert(Tix
.END
, 'May')
258 static
.insert(Tix
.END
, 'June')
259 static
.insert(Tix
.END
, 'July')
260 static
.insert(Tix
.END
, 'August')
261 static
.insert(Tix
.END
, 'September')
262 static
.insert(Tix
.END
, 'October')
263 static
.insert(Tix
.END
, 'November')
264 static
.insert(Tix
.END
, 'December')
266 editable
.insert(Tix
.END
, 'Angola')
267 editable
.insert(Tix
.END
, 'Bangladesh')
268 editable
.insert(Tix
.END
, 'China')
269 editable
.insert(Tix
.END
, 'Denmark')
270 editable
.insert(Tix
.END
, 'Ecuador')
272 history
.insert(Tix
.END
, '/usr/bin/ksh')
273 history
.insert(Tix
.END
, '/usr/local/lib/python')
274 history
.insert(Tix
.END
, '/var/adm')
276 static
.pack(side
=Tix
.TOP
, padx
=5, pady
=3)
277 editable
.pack(side
=Tix
.TOP
, padx
=5, pady
=3)
278 history
.pack(side
=Tix
.TOP
, padx
=5, pady
=3)
280 states
= ['Bengal', 'Delhi', 'Karnataka', 'Tamil Nadu']
282 def spin_cmd(w
, inc
):
283 idx
= states
.index(demo_spintxt
.get()) + inc
285 idx
= len(states
) - 1
286 elif idx
>= len(states
):
288 # following doesn't work.
290 demo_spintxt
.set(states
[idx
]) # this works
292 def spin_validate(w
):
293 global states
, demo_spintxt
296 i
= states
.index(demo_spintxt
.get())
300 # why this procedure works as opposed to the previous one beats me.
305 prefix
= Tix
.OptionName(w
)
306 if not prefix
: prefix
= ''
307 w
.option_add('*' + prefix
+ '*TixControl*label.width', 10)
308 w
.option_add('*' + prefix
+ '*TixControl*label.anchor', Tix
.E
)
309 w
.option_add('*' + prefix
+ '*TixControl*entry.width', 13)
311 demo_spintxt
= Tix
.StringVar()
312 demo_spintxt
.set(states
[0])
313 simple
= Tix
.Control(w
, label
='Numbers')
314 spintxt
= Tix
.Control(w
, label
='States', variable
=demo_spintxt
)
315 spintxt
['incrcmd'] = lambda w
=spintxt
: spin_cmd(w
, 1)
316 spintxt
['decrcmd'] = lambda w
=spintxt
: spin_cmd(w
, -1)
317 spintxt
['validatecmd'] = lambda w
=spintxt
: spin_validate(w
)
319 simple
.pack(side
=Tix
.TOP
, padx
=5, pady
=3)
320 spintxt
.pack(side
=Tix
.TOP
, padx
=5, pady
=3)
323 prefix
= Tix
.OptionName(w
)
324 if not prefix
: prefix
= ''
325 w
.option_add('*' + prefix
+ '*TixSelect*label.anchor', Tix
.CENTER
)
326 w
.option_add('*' + prefix
+ '*TixSelect*orientation', Tix
.VERTICAL
)
327 w
.option_add('*' + prefix
+ '*TixSelect*labelSide', Tix
.TOP
)
329 sel1
= Tix
.Select(w
, label
='Mere Mortals', allowzero
=1, radio
=1)
330 sel2
= Tix
.Select(w
, label
='Geeks', allowzero
=1, radio
=0)
332 sel1
.add('eat', text
='Eat')
333 sel1
.add('work', text
='Work')
334 sel1
.add('play', text
='Play')
335 sel1
.add('party', text
='Party')
336 sel1
.add('sleep', text
='Sleep')
338 sel2
.add('eat', text
='Eat')
339 sel2
.add('prog1', text
='Program')
340 sel2
.add('prog2', text
='Program')
341 sel2
.add('prog3', text
='Program')
342 sel2
.add('sleep', text
='Sleep')
344 sel1
.pack(side
=Tix
.LEFT
, padx
=5, pady
=3, fill
=Tix
.X
)
345 sel2
.pack(side
=Tix
.LEFT
, padx
=5, pady
=3, fill
=Tix
.X
)
348 prefix
= Tix
.OptionName(w
)
349 if not prefix
: prefix
= ''
350 w
.option_add('*' + prefix
+ '*TixOptionMenu*label.anchor', Tix
.E
)
351 m
= Tix
.OptionMenu(w
, label
='File Format : ', options
='menubutton.width 15')
352 m
.add_command('text', label
='Plain Text')
353 m
.add_command('post', label
='PostScript')
354 m
.add_command('format', label
='Formatted Text')
355 m
.add_command('html', label
='HTML')
357 m
.add_command('tex', label
='LaTeX')
358 m
.add_command('rtf', label
='Rich Text Format')
360 m
.pack(fill
=Tix
.X
, padx
=5, pady
=3)
363 msg
= Tix
.Message(w
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
364 relief
=Tix
.FLAT
, width
=240, anchor
=Tix
.N
,
365 text
='Press the "open file" icon button and a TixFileSelectDialog will popup.')
366 ent
= Tix
.FileEntry(w
, label
='Select a file : ')
367 msg
.pack(side
=Tix
.TOP
, expand
=1, fill
=Tix
.BOTH
, padx
=3, pady
=3)
368 ent
.pack(side
=Tix
.TOP
, fill
=Tix
.X
, padx
=3, pady
=3)
371 msg
= Tix
.Message(w
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
372 relief
=Tix
.FLAT
, width
=240, anchor
=Tix
.N
,
373 text
='The TixFileSelectBox 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.')
374 box
= Tix
.FileSelectBox(w
)
375 msg
.pack(side
=Tix
.TOP
, expand
=1, fill
=Tix
.BOTH
, padx
=3, pady
=3)
376 box
.pack(side
=Tix
.TOP
, fill
=Tix
.X
, padx
=3, pady
=3)
381 prefix
= Tix
.OptionName(w
)
382 if not prefix
: prefix
= ''
383 w
.option_add('*' + prefix
+ '*TixSelect*frame.borderWidth', 1)
384 msg
= Tix
.Message(w
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
385 relief
=Tix
.FLAT
, width
=240, anchor
=Tix
.N
,
386 text
='The Select widget is also good for arranging buttons in a tool bar.')
387 bar
= Tix
.Frame(w
, bd
=2, relief
=Tix
.RAISED
)
388 font
= Tix
.Select(w
, allowzero
=1, radio
=0, label
='')
389 para
= Tix
.Select(w
, allowzero
=0, radio
=1, label
='')
391 font
.add('bold', bitmap
='@' + demo
.dir + '/bitmaps/bold.xbm')
392 font
.add('italic', bitmap
='@' + demo
.dir + '/bitmaps/italic.xbm')
393 font
.add('underline', bitmap
='@' + demo
.dir + '/bitmaps/underline.xbm')
394 font
.add('capital', bitmap
='@' + demo
.dir + '/bitmaps/capital.xbm')
396 para
.add('left', bitmap
='@' + demo
.dir + '/bitmaps/leftj.xbm')
397 para
.add('right', bitmap
='@' + demo
.dir + '/bitmaps/rightj.xbm')
398 para
.add('center', bitmap
='@' + demo
.dir + '/bitmaps/centerj.xbm')
399 para
.add('justify', bitmap
='@' + demo
.dir + '/bitmaps/justify.xbm')
401 msg
.pack(side
=Tix
.TOP
, expand
=1, fill
=Tix
.BOTH
, padx
=3, pady
=3)
402 bar
.pack(side
=Tix
.TOP
, fill
=Tix
.X
, padx
=3, pady
=3)
403 font
.pack({'in':bar
}, side
=Tix
.LEFT
, padx
=3, pady
=3)
404 para
.pack({'in':bar
}, side
=Tix
.LEFT
, padx
=3, pady
=3)
407 prefix
= Tix
.OptionName(w
)
408 if not prefix
: prefix
= ''
409 w
.option_add('*' + prefix
+ '*TixSelect*frame.borderWidth', 1)
410 msg
= Tix
.Message(w
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
411 relief
=Tix
.FLAT
, width
=240, anchor
=Tix
.N
,
412 text
='There are many types of "chooser" widgets that allow the user to input different types of information')
413 msg
.pack(side
=Tix
.TOP
, expand
=1, fill
=Tix
.BOTH
, padx
=3, pady
=3)
415 def MkScroll(nb
, name
):
417 prefix
= Tix
.OptionName(w
)
420 w
.option_add('*' + prefix
+ '*TixLabelFrame*label.padX', 4)
422 sls
= Tix
.LabelFrame(w
, label
='tixScrolledListBox')
423 swn
= Tix
.LabelFrame(w
, label
='tixScrolledWindow')
424 stx
= Tix
.LabelFrame(w
, label
='tixScrolledText')
430 sls
.form(top
=0, left
=0, right
='%33', bottom
=-1)
431 swn
.form(top
=0, left
=sls
, right
='%66', bottom
=-1)
432 stx
.form(top
=0, left
=swn
, right
=-1, bottom
=-1)
435 top
= Tix
.Frame(w
, width
=300, height
=330)
437 msg
= Tix
.Message(top
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
438 relief
=Tix
.FLAT
, width
=200, anchor
=Tix
.N
,
439 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.')
441 list = Tix
.ScrolledListBox(top
, scrollbar
='auto')
442 list.place(x
=50, y
=150, width
=120, height
=80)
443 list.listbox
.insert(Tix
.END
, 'Alabama')
444 list.listbox
.insert(Tix
.END
, 'California')
445 list.listbox
.insert(Tix
.END
, 'Montana')
446 list.listbox
.insert(Tix
.END
, 'New Jersey')
447 list.listbox
.insert(Tix
.END
, 'New York')
448 list.listbox
.insert(Tix
.END
, 'Pennsylvania')
449 list.listbox
.insert(Tix
.END
, 'Washington')
451 rh
= Tix
.ResizeHandle(top
, bg
='black',
453 handlesize
=8, gridded
=1, minwidth
=50, minheight
=30)
454 btn
= Tix
.Button(bot
, text
='Reset', command
=lambda w
=rh
, x
=list: SList_reset(w
,x
))
457 btn
.pack(anchor
=Tix
.CENTER
)
458 top
.pack(expand
=1, fill
=Tix
.BOTH
)
459 bot
.pack(fill
=Tix
.BOTH
)
460 list.bind('<Map>', func
=lambda arg
=0, rh
=rh
, list=list:
461 list.tk
.call('tixDoWhenIdle', str(rh
), 'attachwidget', str(list)))
463 def SList_reset(rh
, list):
464 list.place(x
=50, y
=150, width
=120, height
=80)
466 rh
.attach_widget(list)
471 top
= Tix
.Frame(w
, width
=330, height
=330)
473 msg
= Tix
.Message(top
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
474 relief
=Tix
.FLAT
, width
=200, anchor
=Tix
.N
,
475 text
='The TixScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.')
476 win
= Tix
.ScrolledWindow(top
, scrollbar
='auto')
477 image
= Tix
.Image('photo', file=demo
.dir + "/bitmaps/tix.gif")
478 lbl
= Tix
.Label(win
.window
, image
=image
)
479 lbl
.pack(expand
=1, fill
=Tix
.BOTH
)
481 win
.place(x
=30, y
=150, width
=190, height
=120)
483 rh
= Tix
.ResizeHandle(top
, bg
='black',
485 handlesize
=8, gridded
=1, minwidth
=50, minheight
=30)
486 btn
= Tix
.Button(bot
, text
='Reset', command
=lambda w
=rh
, x
=win
: SWindow_reset(w
,x
))
489 btn
.pack(anchor
=Tix
.CENTER
)
490 top
.pack(expand
=1, fill
=Tix
.BOTH
)
491 bot
.pack(fill
=Tix
.BOTH
)
492 win
.bind('<Map>', func
=lambda arg
=0, rh
=rh
, win
=win
:
493 win
.tk
.call('tixDoWhenIdle', str(rh
), 'attachwidget', str(win
)))
495 def SWindow_reset(rh
, win
):
496 win
.place(x
=30, y
=150, width
=190, height
=120)
498 rh
.attach_widget(win
)
501 top
= Tix
.Frame(w
, width
=330, height
=330)
503 msg
= Tix
.Message(top
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
504 relief
=Tix
.FLAT
, width
=200, anchor
=Tix
.N
,
505 text
='The TixScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.')
507 win
= Tix
.ScrolledText(top
, scrollbar
='auto')
508 # win.text['wrap'] = 'none'
509 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.')
510 win
.place(x
=30, y
=150, width
=190, height
=100)
512 rh
= Tix
.ResizeHandle(top
, bg
='black',
514 handlesize
=8, gridded
=1, minwidth
=50, minheight
=30)
515 btn
= Tix
.Button(bot
, text
='Reset', command
=lambda w
=rh
, x
=win
: SText_reset(w
,x
))
518 btn
.pack(anchor
=Tix
.CENTER
)
519 top
.pack(expand
=1, fill
=Tix
.BOTH
)
520 bot
.pack(fill
=Tix
.BOTH
)
521 win
.bind('<Map>', func
=lambda arg
=0, rh
=rh
, win
=win
:
522 win
.tk
.call('tixDoWhenIdle', str(rh
), 'attachwidget', str(win
)))
524 def SText_reset(rh
, win
):
525 win
.place(x
=30, y
=150, width
=190, height
=120)
527 rh
.attach_widget(win
)
529 def MkManager(nb
, name
):
531 prefix
= Tix
.OptionName(w
)
534 w
.option_add('*' + prefix
+ '*TixLabelFrame*label.padX', 4)
536 pane
= Tix
.LabelFrame(w
, label
='tixPanedWindow')
537 note
= Tix
.LabelFrame(w
, label
='tixNoteBook')
539 MkPanedWindow(pane
.frame
)
540 MkNoteBook(note
.frame
)
542 pane
.form(top
=0, left
=0, right
=note
, bottom
=-1)
543 note
.form(top
=0, right
=-1, bottom
=-1)
545 def MkPanedWindow(w
):
546 msg
= Tix
.Message(w
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
547 relief
=Tix
.FLAT
, width
=240, anchor
=Tix
.N
,
548 text
='The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally.')
549 group
= Tix
.Label(w
, text
='Newsgroup: comp.lang.python')
550 pane
= Tix
.PanedWindow(w
, orientation
='vertical')
552 p1
= pane
.add('list', min=70, size
=100)
553 p2
= pane
.add('text', min=70)
554 list = Tix
.ScrolledListBox(p1
)
555 text
= Tix
.ScrolledText(p2
)
557 list.listbox
.insert(Tix
.END
, " 12324 Re: TK is good for your health")
558 list.listbox
.insert(Tix
.END
, "+ 12325 Re: TK is good for your health")
559 list.listbox
.insert(Tix
.END
, "+ 12326 Re: Tix is even better for your health (Was: TK is good...)")
560 list.listbox
.insert(Tix
.END
, " 12327 Re: Tix is even better for your health (Was: TK is good...)")
561 list.listbox
.insert(Tix
.END
, "+ 12328 Re: Tix is even better for your health (Was: TK is good...)")
562 list.listbox
.insert(Tix
.END
, " 12329 Re: Tix is even better for your health (Was: TK is good...)")
563 list.listbox
.insert(Tix
.END
, "+ 12330 Re: Tix is even better for your health (Was: TK is good...)")
565 text
.text
['bg'] = list.listbox
['bg']
566 text
.text
['wrap'] = 'none'
567 text
.text
.insert(Tix
.END
, """
568 Mon, 19 Jun 1995 11:39:52 comp.lang.tcl Thread 34 of 220
569 Lines 353 A new way to put text and bitmaps together iNo responses
570 ioi@blue.seas.upenn.edu Ioi K. Lam at University of Pennsylvania
574 I have implemented a new image type called "compound". It allows you
575 to glue together a bunch of bitmaps, images and text strings together
576 to form a bigger image. Then you can use this image with widgets that
577 support the -image option. For example, you can display a text string string
578 together with a bitmap, at the same time, inside a TK button widget.
580 list.pack(expand
=1, fill
=Tix
.BOTH
, padx
=4, pady
=6)
581 text
.pack(expand
=1, fill
=Tix
.BOTH
, padx
=4, pady
=6)
583 msg
.pack(side
=Tix
.TOP
, padx
=3, pady
=3, fill
=Tix
.BOTH
)
584 group
.pack(side
=Tix
.TOP
, padx
=3, pady
=3, fill
=Tix
.BOTH
)
585 pane
.pack(side
=Tix
.TOP
, padx
=3, pady
=3, fill
=Tix
.BOTH
, expand
=1)
588 msg
= Tix
.Message(w
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
589 relief
=Tix
.FLAT
, width
=240, anchor
=Tix
.N
,
590 text
='The NoteBook widget allows you to layout a complex interface into individual pages.')
591 prefix
= Tix
.OptionName(w
)
594 w
.option_add('*' + prefix
+ '*TixControl*entry.width', 10)
595 w
.option_add('*' + prefix
+ '*TixControl*label.width', 18)
596 w
.option_add('*' + prefix
+ '*TixControl*label.anchor', Tix
.E
)
597 w
.option_add('*' + prefix
+ '*TixNoteBook*tagPadX', 8)
599 nb
= Tix
.NoteBook(w
, ipadx
=6, ipady
=6)
600 nb
.add('hard_disk', label
="Hard Disk", underline
=0)
601 nb
.add('network', label
="Network", underline
=0)
603 # Frame for the buttons that are present on all pages
604 common
= Tix
.Frame(nb
.hard_disk
)
605 common
.pack(side
=Tix
.RIGHT
, padx
=2, pady
=2, fill
=Tix
.Y
)
606 CreateCommonButtons(common
)
608 # Widgets belonging only to this page
609 a
= Tix
.Control(nb
.hard_disk
, value
=12, label
='Access Time: ')
610 w
= Tix
.Control(nb
.hard_disk
, value
=400, label
='Write Throughput: ')
611 r
= Tix
.Control(nb
.hard_disk
, value
=400, label
='Read Throughput: ')
612 c
= Tix
.Control(nb
.hard_disk
, value
=1021, label
='Capacity: ')
613 a
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
614 w
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
615 r
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
616 c
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
618 common
= Tix
.Frame(nb
.network
)
619 common
.pack(side
=Tix
.RIGHT
, padx
=2, pady
=2, fill
=Tix
.Y
)
620 CreateCommonButtons(common
)
622 a
= Tix
.Control(nb
.network
, value
=12, label
='Access Time: ')
623 w
= Tix
.Control(nb
.network
, value
=400, label
='Write Throughput: ')
624 r
= Tix
.Control(nb
.network
, value
=400, label
='Read Throughput: ')
625 c
= Tix
.Control(nb
.network
, value
=1021, label
='Capacity: ')
626 u
= Tix
.Control(nb
.network
, value
=10, label
='Users: ')
627 a
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
628 w
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
629 r
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
630 c
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
631 u
.pack(side
=Tix
.TOP
, padx
=20, pady
=2)
633 msg
.pack(side
=Tix
.TOP
, padx
=3, pady
=3, fill
=Tix
.BOTH
)
634 nb
.pack(side
=Tix
.TOP
, padx
=5, pady
=5, fill
=Tix
.BOTH
, expand
=1)
636 def CreateCommonButtons(f
):
637 ok
= Tix
.Button(f
, text
='OK', width
= 6)
638 cancel
= Tix
.Button(f
, text
='Cancel', width
= 6)
639 ok
.pack(side
=Tix
.TOP
, padx
=2, pady
=2)
640 cancel
.pack(side
=Tix
.TOP
, padx
=2, pady
=2)
642 def MkDirList(nb
, name
):
644 prefix
= Tix
.OptionName(w
)
647 w
.option_add('*' + prefix
+ '*TixLabelFrame*label.padX', 4)
649 dir = Tix
.LabelFrame(w
, label
='tixDirList')
650 fsbox
= Tix
.LabelFrame(w
, label
='tixExFileSelectBox')
651 MkDirListWidget(dir.frame
)
652 MkExFileWidget(fsbox
.frame
)
653 dir.form(top
=0, left
=0, right
='%40', bottom
=-1)
654 fsbox
.form(top
=0, left
='%40', right
=-1, bottom
=-1)
656 def MkDirListWidget(w
):
657 msg
= Tix
.Message(w
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
658 relief
=Tix
.FLAT
, width
=240, anchor
=Tix
.N
,
659 text
='The TixDirList widget gives a graphical representation of the file system directory and makes it easy for the user to choose and access directories.')
660 dirlist
= Tix
.DirList(w
, options
='hlist.padY 1 hlist.width 25 hlist.height 16')
661 msg
.pack(side
=Tix
.TOP
, expand
=1, fill
=Tix
.BOTH
, padx
=3, pady
=3)
662 dirlist
.pack(side
=Tix
.TOP
, padx
=3, pady
=3)
664 def MkExFileWidget(w
):
665 msg
= Tix
.Message(w
, font
='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*',
666 relief
=Tix
.FLAT
, width
=240, anchor
=Tix
.N
,
667 text
='The TixExFileSelectBox widget is more user friendly than the Motif style FileSelectBox.')
668 # There's a bug in the ComboBoxes - the scrolledlistbox is destroyed
669 box
= Tix
.ExFileSelectBox(w
, bd
=2, relief
=Tix
.RAISED
)
670 msg
.pack(side
=Tix
.TOP
, expand
=1, fill
=Tix
.BOTH
, padx
=3, pady
=3)
671 box
.pack(side
=Tix
.TOP
, padx
=3, pady
=3)
674 ### List of all the demos we want to show off
675 comments
= {'widget' : 'Widget Demos', 'image' : 'Image Demos'}
676 samples
= {'Balloon' : 'Balloon',
677 'Button Box' : 'BtnBox',
678 'Combo Box' : 'ComboBox',
679 'Compound Image' : 'CmpImg',
680 'Control' : 'Control',
681 'Notebook' : 'NoteBook',
682 'Option Menu' : 'OptMenu',
683 'Popup Menu' : 'PopMenu',
684 'ScrolledHList (1)' : 'SHList1',
685 'ScrolledHList (2)' : 'SHList2',
686 'Tree (dynamic)' : 'Tree'
690 stypes
['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control',
691 'Notebook', 'Option Menu', 'Popup Menu',
692 'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)']
693 stypes
['image'] = ['Compound Image']
695 def MkSample(nb
, name
):
697 prefix
= Tix
.OptionName(w
)
700 w
.option_add('*' + prefix
+ '*TixLabelFrame*label.padX', 4)
702 lab
= Tix
.Label(w
, text
='Select a sample program:', anchor
=Tix
.W
)
703 lab1
= Tix
.Label(w
, text
='Source:', anchor
=Tix
.W
)
705 slb
= Tix
.ScrolledHList(w
, options
='listbox.exportSelection 0')
706 slb
.hlist
['command'] = lambda args
=0, w
=w
,slb
=slb
: Sample_Action(w
, slb
, 'run')
707 slb
.hlist
['browsecmd'] = lambda args
=0, w
=w
,slb
=slb
: Sample_Action(w
, slb
, 'browse')
709 stext
= Tix
.ScrolledText(w
, name
='stext')
710 stext
.text
.bind('<1>', stext
.text
.focus())
711 stext
.text
.bind('<Up>', lambda w
=stext
.text
: w
.yview(scroll
='-1 unit'))
712 stext
.text
.bind('<Down>', lambda w
=stext
.text
: w
.yview(scroll
='1 unit'))
713 stext
.text
.bind('<Left>', lambda w
=stext
.text
: w
.xview(scroll
='-1 unit'))
714 stext
.text
.bind('<Right>', lambda w
=stext
.text
: w
.xview(scroll
='1 unit'))
716 run
= Tix
.Button(w
, text
='Run ...', name
='run', command
=lambda args
=0, w
=w
,slb
=slb
: Sample_Action(w
, slb
, 'run'))
717 view
= Tix
.Button(w
, text
='View Source ...', name
='view', command
=lambda args
=0,w
=w
,slb
=slb
: Sample_Action(w
, slb
, 'view'))
719 lab
.form(top
=0, left
=0, right
='&'+str(slb
))
720 slb
.form(left
=0, top
=lab
, bottom
=-4)
721 lab1
.form(left
='&'+str(stext
), top
=0, right
='&'+str(stext
), bottom
=stext
)
722 run
.form(left
=str(slb
)+' 30', bottom
=-4)
723 view
.form(left
=run
, bottom
=-4)
724 stext
.form(bottom
=str(run
)+' -5', left
='&'+str(run
), right
='-0', top
='&'+str(slb
))
726 stext
.text
['bg'] = slb
.hlist
['bg']
727 stext
.text
['state'] = 'disabled'
728 stext
.text
['wrap'] = 'none'
729 #XXX stext.text['font'] = fixed_font
731 slb
.hlist
['separator'] = '.'
732 slb
.hlist
['width'] = 25
733 slb
.hlist
['drawbranch'] = 0
734 slb
.hlist
['indent'] = 10
735 slb
.hlist
['wideselect'] = 1
737 for type in ['widget', 'image']:
739 x
= Tix
.Frame(slb
.hlist
, bd
=2, height
=2, width
=150,
740 relief
=Tix
.SUNKEN
, bg
=slb
.hlist
['bg'])
741 slb
.hlist
.add_child(itemtype
=Tix
.WINDOW
, window
=x
, state
='disabled')
742 x
= slb
.hlist
.add_child(itemtype
=Tix
.TEXT
, state
='disabled',
744 for key
in stypes
[type]:
745 slb
.hlist
.add_child(x
, itemtype
=Tix
.TEXT
, data
=key
,
747 slb
.hlist
.selection_clear()
749 run
['state'] = 'disabled'
750 view
['state'] = 'disabled'
752 def Sample_Action(w
, slb
, action
):
755 run
= w
._nametowidget
(str(w
) + '.run')
756 view
= w
._nametowidget
(str(w
) + '.view')
757 stext
= w
._nametowidget
(str(w
) + '.stext')
760 anchor
= hlist
.info_anchor()
762 run
['state'] = 'disabled'
763 view
['state'] = 'disabled'
764 elif not hlist
.info_parent(anchor
):
768 run
['state'] = 'normal'
769 view
['state'] = 'normal'
770 key
= hlist
.info_data(anchor
)
775 exec('import ' + prog
)
778 rtn
= eval(prog
+ '.RunSample')
780 elif action
== 'view':
782 w
.title('Source view: ' + title
)
783 LoadFile(w
, demo
.dir + '/samples/' + prog
+ '.py')
784 elif action
== 'browse':
785 ReadFile(stext
.text
, demo
.dir + '/samples/' + prog
+ '.py')
787 def LoadFile(w
, fname
):
788 b
= Tix
.Button(w
, text
='Close', command
=w
.destroy
)
789 t
= Tix
.ScrolledText(w
)
790 # b.form(left=0, bottom=0, padx=4, pady=4)
791 # t.form(left=0, bottom=b, right='-0', top=0)
795 t
.text
['highlightcolor'] = t
['bg']
797 t
.text
['bg'] = t
['bg']
798 t
.text
['wrap'] = 'none'
800 ReadFile(t
.text
, fname
)
802 def ReadFile(w
, fname
):
803 old_state
= w
['state']
804 w
['state'] = 'normal'
805 w
.delete('0.0', Tix
.END
)
809 lines
= f
.readlines()
815 w
['state'] = old_state
817 if __name__
== '__main__':