~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Demo/tix/tixwidgets.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
 
2
#
 
3
# $Id: tixwidgets.py 68309 2009-01-04 18:53:28Z benjamin.peterson $
 
4
#
 
5
# tixwidgets.py --
 
6
#
 
7
#       For Tix, see http://tix.sourceforge.net
 
8
#
 
9
#       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
 
11
#
 
12
#               % python tixwidgets.py
 
13
#
 
14
 
 
15
import os, os.path, sys, tkinter.tix
 
16
from tkinter.constants import *
 
17
import traceback, tkinter.messagebox
 
18
 
 
19
TCL_DONT_WAIT           = 1<<1
 
20
TCL_WINDOW_EVENTS       = 1<<2
 
21
TCL_FILE_EVENTS         = 1<<3
 
22
TCL_TIMER_EVENTS        = 1<<4
 
23
TCL_IDLE_EVENTS         = 1<<5
 
24
TCL_ALL_EVENTS          = 0
 
25
 
 
26
class Demo:
 
27
    def __init__(self, top):
 
28
        self.root = top
 
29
        self.exit = -1
 
30
 
 
31
        self.dir = None                         # script directory
 
32
        self.balloon = None                     # balloon widget
 
33
        self.useBalloons = tkinter.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
 
39
 
 
40
        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')
 
56
 
 
57
    def MkMainMenu(self):
 
58
        top = self.root
 
59
        w = tkinter.tix.Frame(top, bd=2, relief=RAISED)
 
60
        file = tkinter.tix.Menubutton(w, text='File', underline=0, takefocus=0)
 
61
        help = tkinter.tix.Menubutton(w, text='Help', underline=0, takefocus=0)
 
62
        file.pack(side=LEFT)
 
63
        help.pack(side=RIGHT)
 
64
        fm = tkinter.tix.Menu(file, tearoff=0)
 
65
        file['menu'] = fm
 
66
        hm = tkinter.tix.Menu(help, tearoff=0)
 
67
        help['menu'] = hm
 
68
 
 
69
        fm.add_command(label='Exit', underline=1,
 
70
                     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
        #w.tk.call('trace', 'variable', self.useBalloons, 'w', ToggleHelp))
 
75
 
 
76
        return w
 
77
 
 
78
    def MkMainNotebook(self):
 
79
        top = self.root
 
80
        w = tkinter.tix.NoteBook(top, ipadx=5, ipady=5, options="""
 
81
        tagPadX 6
 
82
        tagPadY 4
 
83
        borderWidth 2
 
84
        """)
 
85
        # This may be required if there is no *Background option
 
86
        top['bg'] = w['bg']
 
87
 
 
88
        w.add('wel', label='Welcome', underline=0,
 
89
              createcmd=lambda w=w, name='wel': MkWelcome(w, name))
 
90
        w.add('cho', label='Choosers', underline=0,
 
91
              createcmd=lambda w=w, name='cho': MkChoosers(w, name))
 
92
        w.add('scr', label='Scrolled Widgets', underline=0,
 
93
              createcmd=lambda w=w, name='scr': MkScroll(w, name))
 
94
        w.add('mgr', label='Manager Widgets', underline=0,
 
95
              createcmd=lambda w=w, name='mgr': MkManager(w, name))
 
96
        w.add('dir', label='Directory List', underline=0,
 
97
              createcmd=lambda w=w, name='dir': MkDirList(w, name))
 
98
        w.add('exp', label='Run Sample Programs', underline=0,
 
99
              createcmd=lambda w=w, name='exp': MkSample(w, name))
 
100
        return w
 
101
 
 
102
    def MkMainStatus(self):
 
103
        global demo
 
104
        top = self.root
 
105
 
 
106
        w = tkinter.tix.Frame(top, relief=tkinter.tix.RAISED, bd=1)
 
107
        demo.statusbar = tkinter.tix.Label(w, relief=tkinter.tix.SUNKEN, bd=1)
 
108
        demo.statusbar.form(padx=3, pady=3, left=0, right='%70')
 
109
        return w
 
110
 
 
111
    def build(self):
 
112
        root = self.root
 
113
        z = root.winfo_toplevel()
 
114
        z.wm_title('Tix Widget Demonstration')
 
115
        if z.winfo_screenwidth() <= 800:
 
116
            z.geometry('790x590+10+10')
 
117
        else:
 
118
            z.geometry('890x640+10+10')
 
119
        demo.balloon = tkinter.tix.Balloon(root)
 
120
        frame1 = self.MkMainMenu()
 
121
        frame2 = self.MkMainNotebook()
 
122
        frame3 = self.MkMainStatus()
 
123
        frame1.pack(side=TOP, fill=X)
 
124
        frame3.pack(side=BOTTOM, fill=X)
 
125
        frame2.pack(side=TOP, expand=1, fill=BOTH, padx=4, pady=4)
 
126
        demo.balloon['statusbar'] = demo.statusbar
 
127
        z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
 
128
 
 
129
        # To show Tcl errors - uncomment this to see the listbox bug.
 
130
        # Tkinter defines a Tcl tkerror procedure that in effect
 
131
        # silences all background Tcl error reporting.
 
132
        # root.tk.eval('if {[info commands tkerror] != ""} {rename tkerror pytkerror}')
 
133
    def quitcmd (self):
 
134
        """Quit our mainloop. It is up to you to call root.destroy() after."""
 
135
        self.exit = 0
 
136
 
 
137
    def loop(self):
 
138
        """This is an explict replacement for _tkinter mainloop()
 
139
        It lets you catch keyboard interrupts easier, and avoids
 
140
        the 20 msec. dead sleep() which burns a constant CPU."""
 
141
        while self.exit < 0:
 
142
            # There are 2 whiles here. The outer one lets you continue
 
143
            # after a ^C interrupt.
 
144
            try:
 
145
                # This is the replacement for _tkinter mainloop()
 
146
                # It blocks waiting for the next Tcl event using select.
 
147
                while self.exit < 0:
 
148
                    self.root.tk.dooneevent(TCL_ALL_EVENTS)
 
149
            except SystemExit:
 
150
                # Tkinter uses SystemExit to exit
 
151
                #print 'Exit'
 
152
                self.exit = 1
 
153
                return
 
154
            except KeyboardInterrupt:
 
155
                if tkinter.messagebox.askquestion ('Interrupt', 'Really Quit?') == 'yes':
 
156
                    # self.tk.eval('exit')
 
157
                    self.exit = 1
 
158
                    return
 
159
                continue
 
160
            except:
 
161
                # Otherwise it's some other error - be nice and say why
 
162
                t, v, tb = sys.exc_info()
 
163
                text = ""
 
164
                for line in traceback.format_exception(t,v,tb):
 
165
                    text += line + '\n'
 
166
                try: tkinter.messagebox.showerror ('Error', text)
 
167
                except: pass
 
168
                self.exit = 1
 
169
                raise SystemExit(1)
 
170
 
 
171
    def destroy (self):
 
172
        self.root.destroy()
 
173
 
 
174
def RunMain(root):
 
175
    global demo
 
176
 
 
177
    demo = Demo(root)
 
178
 
 
179
    demo.build()
 
180
    demo.loop()
 
181
    demo.destroy()
 
182
 
 
183
# Tabs
 
184
def MkWelcome(nb, name):
 
185
    w = nb.page(name)
 
186
    bar = MkWelcomeBar(w)
 
187
    text = MkWelcomeText(w)
 
188
    bar.pack(side=TOP, fill=X, padx=2, pady=2)
 
189
    text.pack(side=TOP, fill=BOTH, expand=1)
 
190
 
 
191
def MkWelcomeBar(top):
 
192
    global demo
 
193
 
 
194
    w = tkinter.tix.Frame(top, bd=2, relief=tkinter.tix.GROOVE)
 
195
    b1 = tkinter.tix.ComboBox(w, command=lambda w=top: MainTextFont(w))
 
196
    b2 = tkinter.tix.ComboBox(w, command=lambda w=top: MainTextFont(w))
 
197
    b1.entry['width'] = 15
 
198
    b1.slistbox.listbox['height'] = 3
 
199
    b2.entry['width'] = 4
 
200
    b2.slistbox.listbox['height'] = 3
 
201
 
 
202
    demo.welfont = b1
 
203
    demo.welsize = b2
 
204
 
 
205
    b1.insert(tkinter.tix.END, 'Courier')
 
206
    b1.insert(tkinter.tix.END, 'Helvetica')
 
207
    b1.insert(tkinter.tix.END, 'Lucida')
 
208
    b1.insert(tkinter.tix.END, 'Times Roman')
 
209
 
 
210
    b2.insert(tkinter.tix.END, '8')
 
211
    b2.insert(tkinter.tix.END, '10')
 
212
    b2.insert(tkinter.tix.END, '12')
 
213
    b2.insert(tkinter.tix.END, '14')
 
214
    b2.insert(tkinter.tix.END, '18')
 
215
 
 
216
    b1.pick(1)
 
217
    b2.pick(3)
 
218
 
 
219
    b1.pack(side=tkinter.tix.LEFT, padx=4, pady=4)
 
220
    b2.pack(side=tkinter.tix.LEFT, padx=4, pady=4)
 
221
 
 
222
    demo.balloon.bind_widget(b1, msg='Choose\na font',
 
223
                             statusmsg='Choose a font for this page')
 
224
    demo.balloon.bind_widget(b2, msg='Point size',
 
225
                             statusmsg='Choose the font size for this page')
 
226
    return w
 
227
 
 
228
def MkWelcomeText(top):
 
229
    global demo
 
230
 
 
231
    w = tkinter.tix.ScrolledWindow(top, scrollbar='auto')
 
232
    win = w.window
 
233
    text = 'Welcome to TIX in Python'
 
234
    title = tkinter.tix.Label(win,
 
235
                      bd=0, width=30, anchor=tkinter.tix.N, text=text)
 
236
    msg = tkinter.tix.Message(win,
 
237
                      bd=0, width=400, anchor=tkinter.tix.N,
 
238
                      text='Tix is a set of mega-widgets based on TK. This program \
 
239
demonstrates the widgets in the Tix widget set. You can choose the pages \
 
240
in this window to look at the corresponding widgets. \n\n\
 
241
To quit this program, choose the "File | Exit" command.\n\n\
 
242
For more information, see http://tix.sourceforge.net.')
 
243
    title.pack(expand=1, fill=tkinter.tix.BOTH, padx=10, pady=10)
 
244
    msg.pack(expand=1, fill=tkinter.tix.BOTH, padx=10, pady=10)
 
245
    demo.welmsg = msg
 
246
    return w
 
247
 
 
248
def MainTextFont(w):
 
249
    global demo
 
250
 
 
251
    if not demo.welmsg:
 
252
        return
 
253
    font = demo.welfont['value']
 
254
    point = demo.welsize['value']
 
255
    if font == 'Times Roman':
 
256
        font = 'times'
 
257
    fontstr = '%s %s' % (font, point)
 
258
    demo.welmsg['font'] = fontstr
 
259
 
 
260
def ToggleHelp():
 
261
    if demo.useBalloons.get() == '1':
 
262
        demo.balloon['state'] = 'both'
 
263
    else:
 
264
        demo.balloon['state'] = 'none'
 
265
 
 
266
def MkChoosers(nb, name):
 
267
    w = nb.page(name)
 
268
    options = "label.padX 4"
 
269
 
 
270
    til = tkinter.tix.LabelFrame(w, label='Chooser Widgets', options=options)
 
271
    cbx = tkinter.tix.LabelFrame(w, label='tixComboBox', options=options)
 
272
    ctl = tkinter.tix.LabelFrame(w, label='tixControl', options=options)
 
273
    sel = tkinter.tix.LabelFrame(w, label='tixSelect', options=options)
 
274
    opt = tkinter.tix.LabelFrame(w, label='tixOptionMenu', options=options)
 
275
    fil = tkinter.tix.LabelFrame(w, label='tixFileEntry', options=options)
 
276
    fbx = tkinter.tix.LabelFrame(w, label='tixFileSelectBox', options=options)
 
277
    tbr = tkinter.tix.LabelFrame(w, label='Tool Bar', options=options)
 
278
 
 
279
    MkTitle(til.frame)
 
280
    MkCombo(cbx.frame)
 
281
    MkControl(ctl.frame)
 
282
    MkSelect(sel.frame)
 
283
    MkOptMenu(opt.frame)
 
284
    MkFileEnt(fil.frame)
 
285
    MkFileBox(fbx.frame)
 
286
    MkToolBar(tbr.frame)
 
287
 
 
288
    # First column: comBox and selector
 
289
    cbx.form(top=0, left=0, right='%33')
 
290
    sel.form(left=0, right='&'+str(cbx), top=cbx)
 
291
    opt.form(left=0, right='&'+str(cbx), top=sel, bottom=-1)
 
292
 
 
293
    # Second column: title .. etc
 
294
    til.form(left=cbx, top=0,right='%66')
 
295
    ctl.form(left=cbx, right='&'+str(til), top=til)
 
296
    fil.form(left=cbx, right='&'+str(til), top=ctl)
 
297
    tbr.form(left=cbx, right='&'+str(til), top=fil, bottom=-1)
 
298
 
 
299
    #
 
300
    # Third column: file selection
 
301
    fbx.form(right=-1, top=0, left='%66')
 
302
 
 
303
def MkCombo(w):
 
304
    options="label.width %d label.anchor %s entry.width %d" % (10, tkinter.tix.E, 14)
 
305
 
 
306
    static = tkinter.tix.ComboBox(w, label='Static', editable=0, options=options)
 
307
    editable = tkinter.tix.ComboBox(w, label='Editable', editable=1, options=options)
 
308
    history = tkinter.tix.ComboBox(w, label='History', editable=1, history=1,
 
309
                           anchor=tkinter.tix.E, options=options)
 
310
    static.insert(tkinter.tix.END, 'January')
 
311
    static.insert(tkinter.tix.END, 'February')
 
312
    static.insert(tkinter.tix.END, 'March')
 
313
    static.insert(tkinter.tix.END, 'April')
 
314
    static.insert(tkinter.tix.END, 'May')
 
315
    static.insert(tkinter.tix.END, 'June')
 
316
    static.insert(tkinter.tix.END, 'July')
 
317
    static.insert(tkinter.tix.END, 'August')
 
318
    static.insert(tkinter.tix.END, 'September')
 
319
    static.insert(tkinter.tix.END, 'October')
 
320
    static.insert(tkinter.tix.END, 'November')
 
321
    static.insert(tkinter.tix.END, 'December')
 
322
 
 
323
    editable.insert(tkinter.tix.END, 'Angola')
 
324
    editable.insert(tkinter.tix.END, 'Bangladesh')
 
325
    editable.insert(tkinter.tix.END, 'China')
 
326
    editable.insert(tkinter.tix.END, 'Denmark')
 
327
    editable.insert(tkinter.tix.END, 'Ecuador')
 
328
 
 
329
    history.insert(tkinter.tix.END, '/usr/bin/ksh')
 
330
    history.insert(tkinter.tix.END, '/usr/local/lib/python')
 
331
    history.insert(tkinter.tix.END, '/var/adm')
 
332
 
 
333
    static.pack(side=tkinter.tix.TOP, padx=5, pady=3)
 
334
    editable.pack(side=tkinter.tix.TOP, padx=5, pady=3)
 
335
    history.pack(side=tkinter.tix.TOP, padx=5, pady=3)
 
336
 
 
337
states = ['Bengal', 'Delhi', 'Karnataka', 'Tamil Nadu']
 
338
 
 
339
def spin_cmd(w, inc):
 
340
    idx = states.index(demo_spintxt.get()) + inc
 
341
    if idx < 0:
 
342
        idx = len(states) - 1
 
343
    elif idx >= len(states):
 
344
        idx = 0
 
345
# following doesn't work.
 
346
#    return states[idx]
 
347
    demo_spintxt.set(states[idx])       # this works
 
348
 
 
349
def spin_validate(w):
 
350
    global states, demo_spintxt
 
351
 
 
352
    try:
 
353
        i = states.index(demo_spintxt.get())
 
354
    except ValueError:
 
355
        return states[0]
 
356
    return states[i]
 
357
    # why this procedure works as opposed to the previous one beats me.
 
358
 
 
359
def MkControl(w):
 
360
    global demo_spintxt
 
361
 
 
362
    options="label.width %d label.anchor %s entry.width %d" % (10, tkinter.tix.E, 13)
 
363
 
 
364
    demo_spintxt = tkinter.tix.StringVar()
 
365
    demo_spintxt.set(states[0])
 
366
    simple = tkinter.tix.Control(w, label='Numbers', options=options)
 
367
    spintxt = tkinter.tix.Control(w, label='States', variable=demo_spintxt,
 
368
                          options=options)
 
369
    spintxt['incrcmd'] = lambda w=spintxt: spin_cmd(w, 1)
 
370
    spintxt['decrcmd'] = lambda w=spintxt: spin_cmd(w, -1)
 
371
    spintxt['validatecmd'] = lambda w=spintxt: spin_validate(w)
 
372
 
 
373
    simple.pack(side=tkinter.tix.TOP, padx=5, pady=3)
 
374
    spintxt.pack(side=tkinter.tix.TOP, padx=5, pady=3)
 
375
 
 
376
def MkSelect(w):
 
377
    options = "label.anchor %s" % tkinter.tix.CENTER
 
378
 
 
379
    sel1 = tkinter.tix.Select(w, label='Mere Mortals', allowzero=1, radio=1,
 
380
                      orientation=tkinter.tix.VERTICAL,
 
381
                      labelside=tkinter.tix.TOP,
 
382
                      options=options)
 
383
    sel2 = tkinter.tix.Select(w, label='Geeks', allowzero=1, radio=0,
 
384
                      orientation=tkinter.tix.VERTICAL,
 
385
                      labelside= tkinter.tix.TOP,
 
386
                      options=options)
 
387
 
 
388
    sel1.add('eat', text='Eat')
 
389
    sel1.add('work', text='Work')
 
390
    sel1.add('play', text='Play')
 
391
    sel1.add('party', text='Party')
 
392
    sel1.add('sleep', text='Sleep')
 
393
 
 
394
    sel2.add('eat', text='Eat')
 
395
    sel2.add('prog1', text='Program')
 
396
    sel2.add('prog2', text='Program')
 
397
    sel2.add('prog3', text='Program')
 
398
    sel2.add('sleep', text='Sleep')
 
399
 
 
400
    sel1.pack(side=tkinter.tix.LEFT, padx=5, pady=3, fill=tkinter.tix.X)
 
401
    sel2.pack(side=tkinter.tix.LEFT, padx=5, pady=3, fill=tkinter.tix.X)
 
402
 
 
403
def MkOptMenu(w):
 
404
    options='menubutton.width 15 label.anchor %s' % tkinter.tix.E
 
405
 
 
406
    m = tkinter.tix.OptionMenu(w, label='File Format : ', options=options)
 
407
    m.add_command('text', label='Plain Text')
 
408
    m.add_command('post', label='PostScript')
 
409
    m.add_command('format', label='Formatted Text')
 
410
    m.add_command('html', label='HTML')
 
411
    m.add_command('sep')
 
412
    m.add_command('tex', label='LaTeX')
 
413
    m.add_command('rtf', label='Rich Text Format')
 
414
 
 
415
    m.pack(fill=tkinter.tix.X, padx=5, pady=3)
 
416
 
 
417
def MkFileEnt(w):
 
418
    msg = tkinter.tix.Message(w,
 
419
                      relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
 
420
                      text='Press the "open file" icon button and a TixFileSelectDialog will popup.')
 
421
    ent = tkinter.tix.FileEntry(w, label='Select a file : ')
 
422
    msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
 
423
    ent.pack(side=tkinter.tix.TOP, fill=tkinter.tix.X, padx=3, pady=3)
 
424
 
 
425
def MkFileBox(w):
 
426
    """The FileSelectBox is a Motif-style box with various enhancements.
 
427
    For example, you can adjust the size of the two listboxes
 
428
    and your past selections are recorded.
 
429
    """
 
430
    msg = tkinter.tix.Message(w,
 
431
                      relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
 
432
                      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.')
 
433
    box = tkinter.tix.FileSelectBox(w)
 
434
    msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
 
435
    box.pack(side=tkinter.tix.TOP, fill=tkinter.tix.X, padx=3, pady=3)
 
436
 
 
437
def MkToolBar(w):
 
438
    """The Select widget is also good for arranging buttons in a tool bar.
 
439
    """
 
440
    global demo
 
441
 
 
442
    options='frame.borderWidth 1'
 
443
 
 
444
    msg = tkinter.tix.Message(w,
 
445
                      relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
 
446
                      text='The Select widget is also good for arranging buttons in a tool bar.')
 
447
    bar = tkinter.tix.Frame(w, bd=2, relief=tkinter.tix.RAISED)
 
448
    font = tkinter.tix.Select(w, allowzero=1, radio=0, label='', options=options)
 
449
    para = tkinter.tix.Select(w, allowzero=0, radio=1, label='', options=options)
 
450
 
 
451
    font.add('bold', bitmap='@' + demo.dir + '/bitmaps/bold.xbm')
 
452
    font.add('italic', bitmap='@' + demo.dir + '/bitmaps/italic.xbm')
 
453
    font.add('underline', bitmap='@' + demo.dir + '/bitmaps/underline.xbm')
 
454
    font.add('capital', bitmap='@' + demo.dir + '/bitmaps/capital.xbm')
 
455
 
 
456
    para.add('left', bitmap='@' + demo.dir + '/bitmaps/leftj.xbm')
 
457
    para.add('right', bitmap='@' + demo.dir + '/bitmaps/rightj.xbm')
 
458
    para.add('center', bitmap='@' + demo.dir + '/bitmaps/centerj.xbm')
 
459
    para.add('justify', bitmap='@' + demo.dir + '/bitmaps/justify.xbm')
 
460
 
 
461
    msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
 
462
    bar.pack(side=tkinter.tix.TOP, fill=tkinter.tix.X, padx=3, pady=3)
 
463
    font.pack({'in':bar}, side=tkinter.tix.LEFT, padx=3, pady=3)
 
464
    para.pack({'in':bar}, side=tkinter.tix.LEFT, padx=3, pady=3)
 
465
 
 
466
def MkTitle(w):
 
467
    msg = tkinter.tix.Message(w,
 
468
                      relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
 
469
                      text='There are many types of "chooser" widgets that allow the user to input different types of information')
 
470
    msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
 
471
 
 
472
def MkScroll(nb, name):
 
473
    w = nb.page(name)
 
474
    options='label.padX 4'
 
475
 
 
476
    sls = tkinter.tix.LabelFrame(w, label='Tix.ScrolledListBox', options=options)
 
477
    swn = tkinter.tix.LabelFrame(w, label='Tix.ScrolledWindow', options=options)
 
478
    stx = tkinter.tix.LabelFrame(w, label='Tix.ScrolledText', options=options)
 
479
 
 
480
    MkSList(sls.frame)
 
481
    MkSWindow(swn.frame)
 
482
    MkSText(stx.frame)
 
483
 
 
484
    sls.form(top=0, left=0, right='%33', bottom=-1)
 
485
    swn.form(top=0, left=sls, right='%66', bottom=-1)
 
486
    stx.form(top=0, left=swn, right=-1, bottom=-1)
 
487
 
 
488
 
 
489
def MkSList(w):
 
490
    """This TixScrolledListBox is configured so that it uses scrollbars
 
491
    only when it is necessary. Use the handles to resize the listbox and
 
492
    watch the scrollbars automatically appear and disappear.  """
 
493
    top = tkinter.tix.Frame(w, width=300, height=330)
 
494
    bot = tkinter.tix.Frame(w)
 
495
    msg = tkinter.tix.Message(top,
 
496
                      relief=tkinter.tix.FLAT, width=200, anchor=tkinter.tix.N,
 
497
                      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.')
 
498
 
 
499
    list = tkinter.tix.ScrolledListBox(top, scrollbar='auto')
 
500
    list.place(x=50, y=150, width=120, height=80)
 
501
    list.listbox.insert(tkinter.tix.END, 'Alabama')
 
502
    list.listbox.insert(tkinter.tix.END, 'California')
 
503
    list.listbox.insert(tkinter.tix.END, 'Montana')
 
504
    list.listbox.insert(tkinter.tix.END, 'New Jersey')
 
505
    list.listbox.insert(tkinter.tix.END, 'New York')
 
506
    list.listbox.insert(tkinter.tix.END, 'Pennsylvania')
 
507
    list.listbox.insert(tkinter.tix.END, 'Washington')
 
508
 
 
509
    rh = tkinter.tix.ResizeHandle(top, bg='black',
 
510
                          relief=tkinter.tix.RAISED,
 
511
                          handlesize=8, gridded=1, minwidth=50, minheight=30)
 
512
    btn = tkinter.tix.Button(bot, text='Reset', command=lambda w=rh, x=list: SList_reset(w,x))
 
513
    top.propagate(0)
 
514
    msg.pack(fill=tkinter.tix.X)
 
515
    btn.pack(anchor=tkinter.tix.CENTER)
 
516
    top.pack(expand=1, fill=tkinter.tix.BOTH)
 
517
    bot.pack(fill=tkinter.tix.BOTH)
 
518
    list.bind('<Map>', func=lambda arg=0, rh=rh, list=list:
 
519
              list.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(list)))
 
520
 
 
521
def SList_reset(rh, list):
 
522
    list.place(x=50, y=150, width=120, height=80)
 
523
    list.update()
 
524
    rh.attach_widget(list)
 
525
 
 
526
def MkSWindow(w):
 
527
    """The ScrolledWindow widget allows you to scroll any kind of Tk
 
528
    widget. It is more versatile than a scrolled canvas widget.
 
529
    """
 
530
    global demo
 
531
 
 
532
    text = 'The Tix ScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.'
 
533
 
 
534
    file = os.path.join(demo.dir, 'bitmaps', 'tix.gif')
 
535
    if not os.path.isfile(file):
 
536
        text += ' (Image missing)'
 
537
 
 
538
    top = tkinter.tix.Frame(w, width=330, height=330)
 
539
    bot = tkinter.tix.Frame(w)
 
540
    msg = tkinter.tix.Message(top,
 
541
                      relief=tkinter.tix.FLAT, width=200, anchor=tkinter.tix.N,
 
542
                      text=text)
 
543
 
 
544
    win = tkinter.tix.ScrolledWindow(top, scrollbar='auto')
 
545
 
 
546
    image1 = win.window.image_create('photo', file=file)
 
547
    lbl = tkinter.tix.Label(win.window, image=image1)
 
548
    lbl.pack(expand=1, fill=tkinter.tix.BOTH)
 
549
 
 
550
    win.place(x=30, y=150, width=190, height=120)
 
551
 
 
552
    rh = tkinter.tix.ResizeHandle(top, bg='black',
 
553
                          relief=tkinter.tix.RAISED,
 
554
                          handlesize=8, gridded=1, minwidth=50, minheight=30)
 
555
    btn = tkinter.tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SWindow_reset(w,x))
 
556
    top.propagate(0)
 
557
    msg.pack(fill=tkinter.tix.X)
 
558
    btn.pack(anchor=tkinter.tix.CENTER)
 
559
    top.pack(expand=1, fill=tkinter.tix.BOTH)
 
560
    bot.pack(fill=tkinter.tix.BOTH)
 
561
 
 
562
    win.bind('<Map>', func=lambda arg=0, rh=rh, win=win:
 
563
             win.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(win)))
 
564
 
 
565
def SWindow_reset(rh, win):
 
566
    win.place(x=30, y=150, width=190, height=120)
 
567
    win.update()
 
568
    rh.attach_widget(win)
 
569
 
 
570
def MkSText(w):
 
571
    """The TixScrolledWindow widget allows you to scroll any kind of Tk
 
572
    widget. It is more versatile than a scrolled canvas widget."""
 
573
    top = tkinter.tix.Frame(w, width=330, height=330)
 
574
    bot = tkinter.tix.Frame(w)
 
575
    msg = tkinter.tix.Message(top,
 
576
                      relief=tkinter.tix.FLAT, width=200, anchor=tkinter.tix.N,
 
577
                      text='The Tix ScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.')
 
578
 
 
579
    win = tkinter.tix.ScrolledText(top, scrollbar='auto')
 
580
    win.text['wrap'] = 'none'
 
581
    win.text.insert(tkinter.tix.END, '''When -scrollbar is set to "auto", the
 
582
scrollbars are shown only when needed.
 
583
Additional modifiers can be used to force a
 
584
scrollbar to be shown or hidden. For example,
 
585
"auto -y" means the horizontal scrollbar
 
586
should be shown when needed but the vertical
 
587
scrollbar should always be hidden;
 
588
"auto +x" means the vertical scrollbar
 
589
should be shown when needed but the horizontal
 
590
scrollbar should always be shown, and so on.'''
 
591
)
 
592
    win.place(x=30, y=150, width=190, height=100)
 
593
 
 
594
    rh = tkinter.tix.ResizeHandle(top, bg='black',
 
595
                          relief=tkinter.tix.RAISED,
 
596
                          handlesize=8, gridded=1, minwidth=50, minheight=30)
 
597
    btn = tkinter.tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SText_reset(w,x))
 
598
    top.propagate(0)
 
599
    msg.pack(fill=tkinter.tix.X)
 
600
    btn.pack(anchor=tkinter.tix.CENTER)
 
601
    top.pack(expand=1, fill=tkinter.tix.BOTH)
 
602
    bot.pack(fill=tkinter.tix.BOTH)
 
603
    win.bind('<Map>', func=lambda arg=0, rh=rh, win=win:
 
604
             win.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(win)))
 
605
 
 
606
def SText_reset(rh, win):
 
607
    win.place(x=30, y=150, width=190, height=120)
 
608
    win.update()
 
609
    rh.attach_widget(win)
 
610
 
 
611
def MkManager(nb, name):
 
612
    w = nb.page(name)
 
613
    options='label.padX 4'
 
614
 
 
615
    pane = tkinter.tix.LabelFrame(w, label='Tix.PanedWindow', options=options)
 
616
    note = tkinter.tix.LabelFrame(w, label='Tix.NoteBook', options=options)
 
617
 
 
618
    MkPanedWindow(pane.frame)
 
619
    MkNoteBook(note.frame)
 
620
 
 
621
    pane.form(top=0, left=0, right=note, bottom=-1)
 
622
    note.form(top=0, right=-1, bottom=-1)
 
623
 
 
624
def MkPanedWindow(w):
 
625
    """The PanedWindow widget allows the user to interactively manipulate
 
626
    the sizes of several panes. The panes can be arranged either vertically
 
627
    or horizontally.
 
628
    """
 
629
    msg = tkinter.tix.Message(w,
 
630
                      relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
 
631
                      text='The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally.')
 
632
    group = tkinter.tix.LabelEntry(w, label='Newsgroup:', options='entry.width 25')
 
633
    group.entry.insert(0,'comp.lang.python')
 
634
    pane = tkinter.tix.PanedWindow(w, orientation='vertical')
 
635
 
 
636
    p1 = pane.add('list', min=70, size=100)
 
637
    p2 = pane.add('text', min=70)
 
638
    list = tkinter.tix.ScrolledListBox(p1)
 
639
    text = tkinter.tix.ScrolledText(p2)
 
640
 
 
641
    list.listbox.insert(tkinter.tix.END, "  12324 Re: Tkinter is good for your health")
 
642
    list.listbox.insert(tkinter.tix.END, "+ 12325 Re: Tkinter is good for your health")
 
643
    list.listbox.insert(tkinter.tix.END, "+ 12326 Re: Tix is even better for your health (Was: Tkinter is good...)")
 
644
    list.listbox.insert(tkinter.tix.END, "  12327 Re: Tix is even better for your health (Was: Tkinter is good...)")
 
645
    list.listbox.insert(tkinter.tix.END, "+ 12328 Re: Tix is even better for your health (Was: Tkinter is good...)")
 
646
    list.listbox.insert(tkinter.tix.END, "  12329 Re: Tix is even better for your health (Was: Tkinter is good...)")
 
647
    list.listbox.insert(tkinter.tix.END, "+ 12330 Re: Tix is even better for your health (Was: Tkinter is good...)")
 
648
 
 
649
    text.text['bg'] = list.listbox['bg']
 
650
    text.text['wrap'] = 'none'
 
651
    text.text.insert(tkinter.tix.END, """
 
652
Mon, 19 Jun 1995 11:39:52        comp.lang.python              Thread   34 of  220
 
653
Lines 353       A new way to put text and bitmaps together iNo responses
 
654
ioi@blue.seas.upenn.edu                Ioi K. Lam at University of Pennsylvania
 
655
 
 
656
Hi,
 
657
 
 
658
I have implemented a new image type called "compound". It allows you
 
659
to glue together a bunch of bitmaps, images and text strings together
 
660
to form a bigger image. Then you can use this image with widgets that
 
661
support the -image option. For example, you can display a text string string
 
662
together with a bitmap, at the same time, inside a TK button widget.
 
663
""")
 
664
    list.pack(expand=1, fill=tkinter.tix.BOTH, padx=4, pady=6)
 
665
    text.pack(expand=1, fill=tkinter.tix.BOTH, padx=4, pady=6)
 
666
 
 
667
    msg.pack(side=tkinter.tix.TOP, padx=3, pady=3, fill=tkinter.tix.BOTH)
 
668
    group.pack(side=tkinter.tix.TOP, padx=3, pady=3, fill=tkinter.tix.BOTH)
 
669
    pane.pack(side=tkinter.tix.TOP, padx=3, pady=3, fill=tkinter.tix.BOTH, expand=1)
 
670
 
 
671
def MkNoteBook(w):
 
672
    msg = tkinter.tix.Message(w,
 
673
                      relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
 
674
                      text='The NoteBook widget allows you to layout a complex interface into individual pages.')
 
675
    # prefix = Tix.OptionName(w)
 
676
    # if not prefix: prefix = ''
 
677
    # w.option_add('*' + prefix + '*TixNoteBook*tagPadX', 8)
 
678
    options = "entry.width %d label.width %d label.anchor %s" % (10, 18, tkinter.tix.E)
 
679
 
 
680
    nb = tkinter.tix.NoteBook(w, ipadx=6, ipady=6, options=options)
 
681
    nb.add('hard_disk', label="Hard Disk", underline=0)
 
682
    nb.add('network', label="Network", underline=0)
 
683
 
 
684
    # Frame for the buttons that are present on all pages
 
685
    common = tkinter.tix.Frame(nb.hard_disk)
 
686
    common.pack(side=tkinter.tix.RIGHT, padx=2, pady=2, fill=tkinter.tix.Y)
 
687
    CreateCommonButtons(common)
 
688
 
 
689
    # Widgets belonging only to this page
 
690
    a = tkinter.tix.Control(nb.hard_disk, value=12, label='Access Time: ')
 
691
    w = tkinter.tix.Control(nb.hard_disk, value=400, label='Write Throughput: ')
 
692
    r = tkinter.tix.Control(nb.hard_disk, value=400, label='Read Throughput: ')
 
693
    c = tkinter.tix.Control(nb.hard_disk, value=1021, label='Capacity: ')
 
694
    a.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
695
    w.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
696
    r.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
697
    c.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
698
 
 
699
    common = tkinter.tix.Frame(nb.network)
 
700
    common.pack(side=tkinter.tix.RIGHT, padx=2, pady=2, fill=tkinter.tix.Y)
 
701
    CreateCommonButtons(common)
 
702
 
 
703
    a = tkinter.tix.Control(nb.network, value=12, label='Access Time: ')
 
704
    w = tkinter.tix.Control(nb.network, value=400, label='Write Throughput: ')
 
705
    r = tkinter.tix.Control(nb.network, value=400, label='Read Throughput: ')
 
706
    c = tkinter.tix.Control(nb.network, value=1021, label='Capacity: ')
 
707
    u = tkinter.tix.Control(nb.network, value=10, label='Users: ')
 
708
    a.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
709
    w.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
710
    r.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
711
    c.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
712
    u.pack(side=tkinter.tix.TOP, padx=20, pady=2)
 
713
 
 
714
    msg.pack(side=tkinter.tix.TOP, padx=3, pady=3, fill=tkinter.tix.BOTH)
 
715
    nb.pack(side=tkinter.tix.TOP, padx=5, pady=5, fill=tkinter.tix.BOTH, expand=1)
 
716
 
 
717
def CreateCommonButtons(f):
 
718
    ok = tkinter.tix.Button(f, text='OK', width = 6)
 
719
    cancel = tkinter.tix.Button(f, text='Cancel', width = 6)
 
720
    ok.pack(side=tkinter.tix.TOP, padx=2, pady=2)
 
721
    cancel.pack(side=tkinter.tix.TOP, padx=2, pady=2)
 
722
 
 
723
def MkDirList(nb, name):
 
724
    w = nb.page(name)
 
725
    options = "label.padX 4"
 
726
 
 
727
    dir = tkinter.tix.LabelFrame(w, label='Tix.DirList', options=options)
 
728
    fsbox = tkinter.tix.LabelFrame(w, label='Tix.ExFileSelectBox', options=options)
 
729
    MkDirListWidget(dir.frame)
 
730
    MkExFileWidget(fsbox.frame)
 
731
    dir.form(top=0, left=0, right='%40', bottom=-1)
 
732
    fsbox.form(top=0, left='%40', right=-1, bottom=-1)
 
733
 
 
734
def MkDirListWidget(w):
 
735
    """The TixDirList widget gives a graphical representation of the file
 
736
    system directory and makes it easy for the user to choose and access
 
737
    directories.
 
738
    """
 
739
    msg = tkinter.tix.Message(w,
 
740
                      relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
 
741
                      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.')
 
742
    dirlist = tkinter.tix.DirList(w, options='hlist.padY 1 hlist.width 25 hlist.height 16')
 
743
    msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
 
744
    dirlist.pack(side=tkinter.tix.TOP, padx=3, pady=3)
 
745
 
 
746
def MkExFileWidget(w):
 
747
    """The TixExFileSelectBox widget is more user friendly than the Motif
 
748
    style FileSelectBox.  """
 
749
    msg = tkinter.tix.Message(w,
 
750
                      relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
 
751
                      text='The Tix ExFileSelectBox widget is more user friendly than the Motif style FileSelectBox.')
 
752
    # There's a bug in the ComboBoxes - the scrolledlistbox is destroyed
 
753
    box = tkinter.tix.ExFileSelectBox(w, bd=2, relief=tkinter.tix.RAISED)
 
754
    msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
 
755
    box.pack(side=tkinter.tix.TOP, padx=3, pady=3)
 
756
 
 
757
###
 
758
### List of all the demos we want to show off
 
759
comments = {'widget' : 'Widget Demos', 'image' : 'Image Demos'}
 
760
samples = {'Balloon'            : 'Balloon',
 
761
           'Button Box'         : 'BtnBox',
 
762
           'Combo Box'          : 'ComboBox',
 
763
           'Compound Image'     : 'CmpImg',
 
764
           'Directory List'     : 'DirList',
 
765
           'Directory Tree'     : 'DirTree',
 
766
           'Control'            : 'Control',
 
767
           'Notebook'           : 'NoteBook',
 
768
           'Option Menu'        : 'OptMenu',
 
769
           'Paned Window'       : 'PanedWin',
 
770
           'Popup Menu'         : 'PopMenu',
 
771
           'ScrolledHList (1)'  : 'SHList1',
 
772
           'ScrolledHList (2)'  : 'SHList2',
 
773
           'Tree (dynamic)'     : 'Tree'
 
774
}
 
775
 
 
776
# There are still a lot of demos to be translated:
 
777
##      set root {
 
778
##          {d "File Selectors"         file    }
 
779
##          {d "Hierachical ListBox"    hlist   }
 
780
##          {d "Tabular ListBox"        tlist   {c tixTList}}
 
781
##          {d "Grid Widget"            grid    {c tixGrid}}
 
782
##          {d "Manager Widgets"        manager }
 
783
##          {d "Scrolled Widgets"       scroll  }
 
784
##          {d "Miscellaneous Widgets"  misc    }
 
785
##          {d "Image Types"            image   }
 
786
##      }
 
787
##
 
788
##      set image {
 
789
##          {d "Compound Image"         cmpimg  }
 
790
##          {d "XPM Image"              xpm     {i pixmap}}
 
791
##      }
 
792
##
 
793
##      set cmpimg {
 
794
##done      {f "In Buttons"             CmpImg.tcl      }
 
795
##          {f "In NoteBook"            CmpImg2.tcl     }
 
796
##          {f "Notebook Color Tabs"    CmpImg4.tcl     }
 
797
##          {f "Icons"                  CmpImg3.tcl     }
 
798
##      }
 
799
##
 
800
##      set xpm {
 
801
##          {f "In Button"              Xpm.tcl         {i pixmap}}
 
802
##          {f "In Menu"                Xpm1.tcl        {i pixmap}}
 
803
##      }
 
804
##
 
805
##      set file {
 
806
##added     {f DirList                          DirList.tcl     }
 
807
##added     {f DirTree                          DirTree.tcl     }
 
808
##          {f DirSelectDialog                  DirDlg.tcl      }
 
809
##          {f ExFileSelectDialog               EFileDlg.tcl    }
 
810
##          {f FileSelectDialog                 FileDlg.tcl     }
 
811
##          {f FileEntry                        FileEnt.tcl     }
 
812
##      }
 
813
##
 
814
##      set hlist {
 
815
##          {f HList                    HList1.tcl      }
 
816
##          {f CheckList                ChkList.tcl     {c tixCheckList}}
 
817
##done      {f "ScrolledHList (1)"      SHList.tcl      }
 
818
##done      {f "ScrolledHList (2)"      SHList2.tcl     }
 
819
##done      {f Tree                     Tree.tcl        }
 
820
##done      {f "Tree (Dynamic)"         DynTree.tcl     {v win}}
 
821
##      }
 
822
##
 
823
##      set tlist {
 
824
##          {f "ScrolledTList (1)"      STList1.tcl     {c tixTList}}
 
825
##          {f "ScrolledTList (2)"      STList2.tcl     {c tixTList}}
 
826
##      }
 
827
##      global tcl_platform
 
828
##      #  This demo hangs windows
 
829
##      if {$tcl_platform(platform) != "windows"} {
 
830
##na    lappend tlist     {f "TList File Viewer"        STList3.tcl     {c tixTList}}
 
831
##      }
 
832
##
 
833
##      set grid {
 
834
##na        {f "Simple Grid"            SGrid0.tcl      {c tixGrid}}
 
835
##na        {f "ScrolledGrid"           SGrid1.tcl      {c tixGrid}}
 
836
##na        {f "Editable Grid"          EditGrid.tcl    {c tixGrid}}
 
837
##      }
 
838
##
 
839
##      set scroll {
 
840
##          {f ScrolledListBox          SListBox.tcl    }
 
841
##          {f ScrolledText             SText.tcl       }
 
842
##          {f ScrolledWindow           SWindow.tcl     }
 
843
##na        {f "Canvas Object View"     CObjView.tcl    {c tixCObjView}}
 
844
##      }
 
845
##
 
846
##      set manager {
 
847
##          {f ListNoteBook             ListNBK.tcl     }
 
848
##done      {f NoteBook                 NoteBook.tcl    }
 
849
##done      {f PanedWindow              PanedWin.tcl    }
 
850
##      }
 
851
##
 
852
##      set misc {
 
853
##done      {f Balloon                  Balloon.tcl     }
 
854
##done      {f ButtonBox                BtnBox.tcl      }
 
855
##done      {f ComboBox                 ComboBox.tcl    }
 
856
##done      {f Control                  Control.tcl     }
 
857
##          {f LabelEntry               LabEntry.tcl    }
 
858
##          {f LabelFrame               LabFrame.tcl    }
 
859
##          {f Meter                    Meter.tcl       {c tixMeter}}
 
860
##done      {f OptionMenu               OptMenu.tcl     }
 
861
##done      {f PopupMenu                PopMenu.tcl     }
 
862
##          {f Select                   Select.tcl      }
 
863
##          {f StdButtonBox             StdBBox.tcl     }
 
864
##      }
 
865
##
 
866
 
 
867
stypes = {}
 
868
stypes['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control',
 
869
                    'Directory List', 'Directory Tree',
 
870
                    'Notebook', 'Option Menu', 'Popup Menu', 'Paned Window',
 
871
                    'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)']
 
872
stypes['image'] = ['Compound Image']
 
873
 
 
874
def MkSample(nb, name):
 
875
    w = nb.page(name)
 
876
    options = "label.padX 4"
 
877
 
 
878
    pane = tkinter.tix.PanedWindow(w, orientation='horizontal')
 
879
    pane.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH)
 
880
    f1 = pane.add('list', expand='1')
 
881
    f2 = pane.add('text', expand='5')
 
882
    f1['relief'] = 'flat'
 
883
    f2['relief'] = 'flat'
 
884
 
 
885
    lab = tkinter.tix.LabelFrame(f1, label='Select a sample program:')
 
886
    lab.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=5, pady=5)
 
887
    lab1 = tkinter.tix.LabelFrame(f2, label='Source:')
 
888
    lab1.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=5, pady=5)
 
889
 
 
890
    slb = tkinter.tix.Tree(lab.frame, options='hlist.width 20')
 
891
    slb.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=5)
 
892
 
 
893
    stext = tkinter.tix.ScrolledText(lab1.frame, name='stext')
 
894
    font = root.tk.eval('tix option get fixed_font')
 
895
    stext.text.config(font=font)
 
896
 
 
897
    frame = tkinter.tix.Frame(lab1.frame, name='frame')
 
898
 
 
899
    run = tkinter.tix.Button(frame, text='Run ...', name='run')
 
900
    view = tkinter.tix.Button(frame, text='View Source ...', name='view')
 
901
    run.pack(side=tkinter.tix.LEFT, expand=0, fill=tkinter.tix.NONE)
 
902
    view.pack(side=tkinter.tix.LEFT, expand=0, fill=tkinter.tix.NONE)
 
903
 
 
904
    stext.text['bg'] = slb.hlist['bg']
 
905
    stext.text['state'] = 'disabled'
 
906
    stext.text['wrap'] = 'none'
 
907
    stext.text['width'] = 80
 
908
 
 
909
    frame.pack(side=tkinter.tix.BOTTOM, expand=0, fill=tkinter.tix.X, padx=7)
 
910
    stext.pack(side=tkinter.tix.TOP, expand=0, fill=tkinter.tix.BOTH, padx=7)
 
911
 
 
912
    slb.hlist['separator'] = '.'
 
913
    slb.hlist['width'] = 25
 
914
    slb.hlist['drawbranch'] = 0
 
915
    slb.hlist['indent'] = 10
 
916
    slb.hlist['wideselect'] = 1
 
917
    slb.hlist['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
 
918
    slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'browse')
 
919
 
 
920
    run['command']      = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
 
921
    view['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'view')
 
922
 
 
923
    for type in ['widget', 'image']:
 
924
        if type != 'widget':
 
925
            x = tkinter.tix.Frame(slb.hlist, bd=2, height=2, width=150,
 
926
                          relief=tkinter.tix.SUNKEN, bg=slb.hlist['bg'])
 
927
            slb.hlist.add_child(itemtype=tkinter.tix.WINDOW, window=x, state='disabled')
 
928
        x = slb.hlist.add_child(itemtype=tkinter.tix.TEXT, state='disabled',
 
929
                                text=comments[type])
 
930
        for key in stypes[type]:
 
931
            slb.hlist.add_child(x, itemtype=tkinter.tix.TEXT, data=key,
 
932
                                text=key)
 
933
    slb.hlist.selection_clear()
 
934
 
 
935
    run['state'] = 'disabled'
 
936
    view['state'] = 'disabled'
 
937
 
 
938
def Sample_Action(w, slb, stext, run, view, action):
 
939
    global demo
 
940
 
 
941
    hlist = slb.hlist
 
942
    anchor = hlist.info_anchor()
 
943
    if not anchor:
 
944
        run['state'] = 'disabled'
 
945
        view['state'] = 'disabled'
 
946
    elif not hlist.info_parent(anchor):
 
947
        # a comment
 
948
        return
 
949
 
 
950
    run['state'] = 'normal'
 
951
    view['state'] = 'normal'
 
952
    key = hlist.info_data(anchor)
 
953
    title = key
 
954
    prog = samples[key]
 
955
 
 
956
    if action == 'run':
 
957
        exec('import ' + prog)
 
958
        w = tkinter.tix.Toplevel()
 
959
        w.title(title)
 
960
        rtn = eval(prog + '.RunSample')
 
961
        rtn(w)
 
962
    elif action == 'view':
 
963
        w = tkinter.tix.Toplevel()
 
964
        w.title('Source view: ' + title)
 
965
        LoadFile(w, demo.dir + '/samples/' + prog + '.py')
 
966
    elif action == 'browse':
 
967
        ReadFile(stext.text, demo.dir + '/samples/' + prog + '.py')
 
968
 
 
969
def LoadFile(w, fname):
 
970
    global root
 
971
    b = tkinter.tix.Button(w, text='Close', command=w.destroy)
 
972
    t = tkinter.tix.ScrolledText(w)
 
973
    #    b.form(left=0, bottom=0, padx=4, pady=4)
 
974
    #    t.form(left=0, bottom=b, right='-0', top=0)
 
975
    t.pack()
 
976
    b.pack()
 
977
 
 
978
    font = root.tk.eval('tix option get fixed_font')
 
979
    t.text.config(font=font)
 
980
    t.text['bd'] = 2
 
981
    t.text['wrap'] = 'none'
 
982
 
 
983
    ReadFile(t.text, fname)
 
984
 
 
985
def ReadFile(w, fname):
 
986
    old_state = w['state']
 
987
    w['state'] = 'normal'
 
988
    w.delete('0.0', tkinter.tix.END)
 
989
 
 
990
    try:
 
991
        f = open(fname)
 
992
        lines = f.readlines()
 
993
        for s in lines:
 
994
            w.insert(tkinter.tix.END, s)
 
995
        f.close()
 
996
    finally:
 
997
#       w.see('1.0')
 
998
        w['state'] = old_state
 
999
 
 
1000
if __name__ == '__main__':
 
1001
    root = tkinter.tix.Tk()
 
1002
    RunMain(root)