diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-11-25 14:50:56 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-11-25 14:50:56 (GMT) |
commit | 652e1917c6f2bcdccb784d9d37950c381948a77c (patch) | |
tree | 717489558ffed3495a75ac253ac26a5e26795166 /Demo/tix/tixwidgets.py | |
parent | 3a89b2b13134767475c8e0c14381c1a722d7b836 (diff) | |
download | cpython-652e1917c6f2bcdccb784d9d37950c381948a77c.zip cpython-652e1917c6f2bcdccb784d9d37950c381948a77c.tar.gz cpython-652e1917c6f2bcdccb784d9d37950c381948a77c.tar.bz2 |
Properly set static options for tixBalloon and tixResizeHandle.
Expose Tix.ResizeHandle.{detach_widget,hide,show}.
Update Tix demos.
Diffstat (limited to 'Demo/tix/tixwidgets.py')
-rw-r--r-- | Demo/tix/tixwidgets.py | 145 |
1 files changed, 95 insertions, 50 deletions
diff --git a/Demo/tix/tixwidgets.py b/Demo/tix/tixwidgets.py index 177e452..68cf56e 100644 --- a/Demo/tix/tixwidgets.py +++ b/Demo/tix/tixwidgets.py @@ -9,10 +9,10 @@ # This is a demo program of all Tix widgets available from Python. If # you have installed Python & Tix properly, you can execute this as # -# % python tixwidget.py +# % python tixwidgets.py # -import os, sys, Tix +import os, os.path, sys, Tix from Tkconstants import * TCL_DONT_WAIT = 1<<1 @@ -60,16 +60,16 @@ class Demo: help = Tix.Menubutton(w, text='Help', underline=0, takefocus=0) file.pack(side=LEFT) help.pack(side=RIGHT) - fm = Tix.Menu(file) + fm = Tix.Menu(file, tearoff=0) file['menu'] = fm - hm = Tix.Menu(help) + hm = Tix.Menu(help, tearoff=0) help['menu'] = hm if w.tk.eval ('info commands console') == "console": fm.add_command(label='Console', underline=1, command=lambda w=w: w.tk.eval('console show')) - fm.add_command(label='Exit', underline=1, accelerator='Ctrl+X', + fm.add_command(label='Exit', underline=1, command = lambda self=self: self.quitcmd () ) hm.add_checkbutton(label='BalloonHelp', underline=0, command=ToggleHelp, variable=self.useBalloons) @@ -128,25 +128,43 @@ class Demo: z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) def quitcmd (self): - # self.root.destroy() + """Quit our mainloop. It is up to you to call root.destroy() after.""" self.exit = 0 def loop(self): + import tkMessageBox, traceback + while self.exit < 0: + try: while self.exit < 0: self.root.tk.dooneevent(TCL_ALL_EVENTS) - # self.root.tk.dooneevent(TCL_DONT_WAIT) + except SystemExit: + #print 'Exit' + self.exit = 1 + break + except KeyboardInterrupt: + if tkMessageBox.askquestion ('Interrupt', 'Really Quit?') == 'yes': + # self.tk.eval('exit') + return + else: + pass + continue + except: + t, v, tb = sys.exc_info() + text = "" + for line in traceback.format_exception(t,v,tb): + text += line + '\n' + try: tkMessageBox.showerror ('Error', text) + except: pass + tkinspect_quit (1) def destroy (self): self.root.destroy() -def RunMain(top): - global demo, root +def RunMain(root): + global demo - demo = Demo(top) + demo = Demo(root) - # top.withdraw() - # root = Tix.Toplevel() - root = top demo.build() demo.loop() demo.destroy() @@ -500,17 +518,32 @@ def SList_reset(rh, list): list.update() rh.attach_widget(list) +# See below why this is necessary. +global image1 +image1 = None def MkSWindow(w): - global demo + global demo, image1 + + text = 'The TixScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.' + + file = os.path.join(demo.dir, 'bitmaps', 'tix.gif') + if not os.path.isfile(file): + text += ' (Image missing)' top = Tix.Frame(w, width=330, height=330) bot = Tix.Frame(w) msg = Tix.Message(top, relief=Tix.FLAT, width=200, anchor=Tix.N, - text='The TixScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.') + text=text) + win = Tix.ScrolledWindow(top, scrollbar='auto') - image = Tix.Image('photo', file=demo.dir + "/bitmaps/tix.gif") - lbl = Tix.Label(win.window, image=image) + + # This image is not showing up under Python unless it is set to a + # global variable - no problem under Tcl. I assume it is being garbage + # collected some how, even though the tcl command 'image names' shows + # that as far as Tcl is concerned, the image exists and is called pyimage1. + image1 = Tix.Image('photo', file=file) + lbl = Tix.Label(win.window, image=image1) lbl.pack(expand=1, fill=Tix.BOTH) win.place(x=30, y=150, width=190, height=120) @@ -581,7 +614,8 @@ def MkPanedWindow(w): msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally.') - group = Tix.Label(w, text='Newsgroup: comp.lang.python') + group = Tix.LabelEntry(w, label='Newsgroup:', options='entry.width 25') + group.entry.insert(0,'comp.lang.python') pane = Tix.PanedWindow(w, orientation='vertical') p1 = pane.add('list', min=70, size=100) @@ -589,18 +623,18 @@ def MkPanedWindow(w): list = Tix.ScrolledListBox(p1) text = Tix.ScrolledText(p2) - list.listbox.insert(Tix.END, " 12324 Re: TK is good for your health") - list.listbox.insert(Tix.END, "+ 12325 Re: TK is good for your health") - list.listbox.insert(Tix.END, "+ 12326 Re: Tix is even better for your health (Was: TK is good...)") - list.listbox.insert(Tix.END, " 12327 Re: Tix is even better for your health (Was: TK is good...)") - list.listbox.insert(Tix.END, "+ 12328 Re: Tix is even better for your health (Was: TK is good...)") - list.listbox.insert(Tix.END, " 12329 Re: Tix is even better for your health (Was: TK is good...)") - list.listbox.insert(Tix.END, "+ 12330 Re: Tix is even better for your health (Was: TK is good...)") + list.listbox.insert(Tix.END, " 12324 Re: Tkinter is good for your health") + list.listbox.insert(Tix.END, "+ 12325 Re: Tkinter is good for your health") + list.listbox.insert(Tix.END, "+ 12326 Re: Tix is even better for your health (Was: Tkinter is good...)") + list.listbox.insert(Tix.END, " 12327 Re: Tix is even better for your health (Was: Tkinter is good...)") + list.listbox.insert(Tix.END, "+ 12328 Re: Tix is even better for your health (Was: Tkinter is good...)") + list.listbox.insert(Tix.END, " 12329 Re: Tix is even better for your health (Was: Tkinter is good...)") + list.listbox.insert(Tix.END, "+ 12330 Re: Tix is even better for your health (Was: Tkinter is good...)") text.text['bg'] = list.listbox['bg'] text.text['wrap'] = 'none' text.text.insert(Tix.END, """ -Mon, 19 Jun 1995 11:39:52 comp.lang.tcl Thread 34 of 220 +Mon, 19 Jun 1995 11:39:52 comp.lang.python Thread 34 of 220 Lines 353 A new way to put text and bitmaps together iNo responses ioi@blue.seas.upenn.edu Ioi K. Lam at University of Pennsylvania @@ -717,6 +751,7 @@ samples = {'Balloon' : 'Balloon', 'Control' : 'Control', 'Notebook' : 'NoteBook', 'Option Menu' : 'OptMenu', + 'Paned Window' : 'PanedWin', 'Popup Menu' : 'PopMenu', 'ScrolledHList (1)' : 'SHList1', 'ScrolledHList (2)' : 'SHList2', @@ -795,8 +830,8 @@ samples = {'Balloon' : 'Balloon', ## ## set manager { ##na {f ListNoteBook ListNBK.tcl } -## {f NoteBook NoteBook.tcl } -## {f PanedWindow PanedWin.tcl } +##done {f NoteBook NoteBook.tcl } +##done {f PanedWindow PanedWin.tcl } ## } ## ## set misc { @@ -817,7 +852,7 @@ samples = {'Balloon' : 'Balloon', stypes = {} stypes['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control', 'Directory List', 'Directory Tree', - 'Notebook', 'Option Menu', 'Popup Menu', + 'Notebook', 'Option Menu', 'Popup Menu', 'Paned Window', 'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)'] stypes['image'] = ['Compound Image'] @@ -826,43 +861,57 @@ def MkSample(nb, name): prefix = Tix.OptionName(w) if not prefix: prefix = '' - w.option_add('*' + prefix + '*TixLabelFrame*label.padX', 4) + else: + prefix = '*' + prefix + w.option_add(prefix + '*TixLabelFrame*label.padX', 4) - lab = Tix.Label(w, text='Select a sample program:', anchor=Tix.W) - lab1 = Tix.Label(w, text='Source:', anchor=Tix.W) + pane = Tix.PanedWindow(w, orientation='horizontal') + pane.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH) + f1 = pane.add('list', expand='1') + f2 = pane.add('text', expand='5') + f1['relief'] = 'flat' + f2['relief'] = 'flat' - slb = Tix.ScrolledHList(w, options='listbox.exportSelection 0') - slb.hlist['command'] = lambda args=0, w=w,slb=slb: Sample_Action(w, slb, 'run') - slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb: Sample_Action(w, slb, 'browse') + lab = Tix.Label(f1, text='Select a sample program:', anchor=Tix.W) + lab.pack(side=Tix.TOP, expand=0, fill=Tix.X, padx=5, pady=5) + lab1 = Tix.Label(f2, text='Source:', anchor=Tix.W) + lab1.pack(side=Tix.TOP, expand=0, fill=Tix.X, padx=5, pady=5) - stext = Tix.ScrolledText(w, name='stext') + slb = Tix.Tree(f1, options='hlist.width 25') + slb.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5) + + stext = Tix.ScrolledText(f2, name='stext') font = root.tk.eval('tix option get fixed_font') stext.text.config(font=font) - # stext.text.bind('<1>', stext.text.focus()) stext.text.bind('<Up>', lambda w=stext.text: w.yview(scroll='-1 unit')) stext.text.bind('<Down>', lambda w=stext.text: w.yview(scroll='1 unit')) stext.text.bind('<Left>', lambda w=stext.text: w.xview(scroll='-1 unit')) stext.text.bind('<Right>', lambda w=stext.text: w.xview(scroll='1 unit')) + stext.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=7) - run = Tix.Button(w, text='Run ...', name='run', command=lambda args=0, w=w,slb=slb: Sample_Action(w, slb, 'run')) - view = Tix.Button(w, text='View Source ...', name='view', command=lambda args=0,w=w,slb=slb: Sample_Action(w, slb, 'view')) + frame = Tix.Frame(f2, name='frame') + frame.pack(side=Tix.TOP, expand=0, fill=Tix.X, padx=7) - lab.form(top=0, left=0, right='&'+str(slb)) - slb.form(left=0, top=lab, bottom=-4) - lab1.form(left='&'+str(stext), top=0, right='&'+str(stext), bottom=stext) - run.form(left=str(slb)+' 30', bottom=-4) - view.form(left=run, bottom=-4) - stext.form(bottom=str(run)+' -5', left='&'+str(run), right='-0', top='&'+str(slb)) + run = Tix.Button(frame, text='Run ...', name='run') + view = Tix.Button(frame, text='View Source ...', name='view') + run.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE) + view.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE) stext.text['bg'] = slb.hlist['bg'] stext.text['state'] = 'disabled' stext.text['wrap'] = 'none' + stext.text['width'] = 80 slb.hlist['separator'] = '.' slb.hlist['width'] = 25 slb.hlist['drawbranch'] = 0 slb.hlist['indent'] = 10 slb.hlist['wideselect'] = 1 + slb.hlist['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run') + slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'browse') + + run['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run') + view['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'view') for type in ['widget', 'image']: if type != 'widget': @@ -879,13 +928,9 @@ def MkSample(nb, name): run['state'] = 'disabled' view['state'] = 'disabled' -def Sample_Action(w, slb, action): +def Sample_Action(w, slb, stext, run, view, action): global demo - run = w._nametowidget(str(w) + '.run') - view = w._nametowidget(str(w) + '.view') - stext = w._nametowidget(str(w) + '.stext') - hlist = slb.hlist anchor = hlist.info_anchor() if not anchor: |