Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 652e191

Browse files
committed
Properly set static options for tixBalloon and tixResizeHandle.
Expose Tix.ResizeHandle.{detach_widget,hide,show}. Update Tix demos.
1 parent 3a89b2b commit 652e191

4 files changed

Lines changed: 214 additions & 52 deletions

File tree

Demo/tix/samples/PanedWin.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
2+
#
3+
# $Id$
4+
#
5+
# Tix Demostration Program
6+
#
7+
# This sample program is structured in such a way so that it can be
8+
# executed from the Tix demo program "tixwidgets.py": it must have a
9+
# procedure called "RunSample". It should also have the "if" statment
10+
# at the end of this file so that it can be run as a standalone
11+
# program.
12+
13+
# This file demonstrates the use of the tixPanedWindow widget. This program
14+
# is a dummy news reader: the user can adjust the sizes of the list
15+
# of artical names and the size of the text widget that shows the body
16+
# of the article.
17+
18+
import Tix
19+
20+
TCL_ALL_EVENTS = 0
21+
22+
def RunSample (root):
23+
panedwin = DemoPanedwin(root)
24+
panedwin.mainloop()
25+
panedwin.destroy()
26+
27+
class DemoPanedwin:
28+
def __init__(self, w):
29+
self.root = w
30+
self.exit = -1
31+
32+
z = w.winfo_toplevel()
33+
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
34+
35+
group = Tix.LabelEntry(w, label='Newsgroup:', options='entry.width 25')
36+
group.entry.insert(0,'comp.lang.python')
37+
pane = Tix.PanedWindow(w, orientation='vertical')
38+
39+
p1 = pane.add('list', min=70, size=100)
40+
p2 = pane.add('text', min=70)
41+
list = Tix.ScrolledListBox(p1)
42+
list.listbox['width'] = 80
43+
list.listbox['height'] = 5
44+
text = Tix.ScrolledText(p2)
45+
text.text['width'] = 80
46+
text.text['height'] = 20
47+
48+
list.listbox.insert(Tix.END, " 12324 Re: Tkinter is good for your health")
49+
list.listbox.insert(Tix.END, "+ 12325 Re: Tkinter is good for your health")
50+
list.listbox.insert(Tix.END, "+ 12326 Re: Tix is even better for your health (Was: Tkinter is good...)")
51+
list.listbox.insert(Tix.END, " 12327 Re: Tix is even better for your health (Was: Tkinter is good...)")
52+
list.listbox.insert(Tix.END, "+ 12328 Re: Tix is even better for your health (Was: Tkinter is good...)")
53+
list.listbox.insert(Tix.END, " 12329 Re: Tix is even better for your health (Was: Tkinter is good...)")
54+
list.listbox.insert(Tix.END, "+ 12330 Re: Tix is even better for your health (Was: Tkinter is good...)")
55+
56+
text.text['bg'] = list.listbox['bg']
57+
text.text['wrap'] = 'none'
58+
text.text.insert(Tix.END, """
59+
Mon, 19 Jun 1995 11:39:52 comp.lang.python Thread 34 of 220
60+
Lines 353 A new way to put text and bitmaps together iNo responses
61+
[email protected] Ioi K. Lam at University of Pennsylvania
62+
63+
Hi,
64+
65+
I have implemented a new image type called "compound". It allows you
66+
to glue together a bunch of bitmaps, images and text strings together
67+
to form a bigger image. Then you can use this image with widgets that
68+
support the -image option. For example, you can display a text string string
69+
together with a bitmap, at the same time, inside a TK button widget.
70+
""")
71+
text.text['state'] = 'disabled'
72+
73+
list.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6)
74+
text.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6)
75+
76+
group.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH)
77+
pane.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH, expand=1)
78+
79+
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
80+
box.add('ok', text='Ok', underline=0, width=6,
81+
command=self.quitcmd)
82+
box.add('cancel', text='Cancel', underline=0, width=6,
83+
command=self.quitcmd)
84+
box.pack(side=Tix.BOTTOM, fill=Tix.X)
85+
86+
def quitcmd (self):
87+
self.exit = 0
88+
89+
def mainloop(self):
90+
while self.exit < 0:
91+
self.root.tk.dooneevent(TCL_ALL_EVENTS)
92+
93+
def destroy (self):
94+
self.root.destroy()
95+
96+
if __name__ == '__main__':
97+
root = Tix.Tk()
98+
RunSample(root)

Demo/tix/tixwidgets.py

Lines changed: 95 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
# This is a demo program of all Tix widgets available from Python. If
1010
# you have installed Python & Tix properly, you can execute this as
1111
#
12-
# % python tixwidget.py
12+
# % python tixwidgets.py
1313
#
1414

15-
import os, sys, Tix
15+
import os, os.path, sys, Tix
1616
from Tkconstants import *
1717

1818
TCL_DONT_WAIT = 1<<1
@@ -60,16 +60,16 @@ def MkMainMenu(self):
6060
help = Tix.Menubutton(w, text='Help', underline=0, takefocus=0)
6161
file.pack(side=LEFT)
6262
help.pack(side=RIGHT)
63-
fm = Tix.Menu(file)
63+
fm = Tix.Menu(file, tearoff=0)
6464
file['menu'] = fm
65-
hm = Tix.Menu(help)
65+
hm = Tix.Menu(help, tearoff=0)
6666
help['menu'] = hm
6767

6868
if w.tk.eval ('info commands console') == "console":
6969
fm.add_command(label='Console', underline=1,
7070
command=lambda w=w: w.tk.eval('console show'))
7171

72-
fm.add_command(label='Exit', underline=1, accelerator='Ctrl+X',
72+
fm.add_command(label='Exit', underline=1,
7373
command = lambda self=self: self.quitcmd () )
7474
hm.add_checkbutton(label='BalloonHelp', underline=0, command=ToggleHelp,
7575
variable=self.useBalloons)
@@ -128,25 +128,43 @@ def build(self):
128128
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
129129

130130
def quitcmd (self):
131-
# self.root.destroy()
131+
"""Quit our mainloop. It is up to you to call root.destroy() after."""
132132
self.exit = 0
133133

134134
def loop(self):
135+
import tkMessageBox, traceback
136+
while self.exit < 0:
137+
try:
135138
while self.exit < 0:
136139
self.root.tk.dooneevent(TCL_ALL_EVENTS)
137-
# self.root.tk.dooneevent(TCL_DONT_WAIT)
140+
except SystemExit:
141+
#print 'Exit'
142+
self.exit = 1
143+
break
144+
except KeyboardInterrupt:
145+
if tkMessageBox.askquestion ('Interrupt', 'Really Quit?') == 'yes':
146+
# self.tk.eval('exit')
147+
return
148+
else:
149+
pass
150+
continue
151+
except:
152+
t, v, tb = sys.exc_info()
153+
text = ""
154+
for line in traceback.format_exception(t,v,tb):
155+
text += line + '\n'
156+
try: tkMessageBox.showerror ('Error', text)
157+
except: pass
158+
tkinspect_quit (1)
138159

139160
def destroy (self):
140161
self.root.destroy()
141162

142-
def RunMain(top):
143-
global demo, root
163+
def RunMain(root):
164+
global demo
144165

145-
demo = Demo(top)
166+
demo = Demo(root)
146167

147-
# top.withdraw()
148-
# root = Tix.Toplevel()
149-
root = top
150168
demo.build()
151169
demo.loop()
152170
demo.destroy()
@@ -500,17 +518,32 @@ def SList_reset(rh, list):
500518
list.update()
501519
rh.attach_widget(list)
502520

521+
# See below why this is necessary.
522+
global image1
523+
image1 = None
503524
def MkSWindow(w):
504-
global demo
525+
global demo, image1
526+
527+
text = 'The TixScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.'
528+
529+
file = os.path.join(demo.dir, 'bitmaps', 'tix.gif')
530+
if not os.path.isfile(file):
531+
text += ' (Image missing)'
505532

506533
top = Tix.Frame(w, width=330, height=330)
507534
bot = Tix.Frame(w)
508535
msg = Tix.Message(top,
509536
relief=Tix.FLAT, width=200, anchor=Tix.N,
510-
text='The TixScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.')
537+
text=text)
538+
511539
win = Tix.ScrolledWindow(top, scrollbar='auto')
512-
image = Tix.Image('photo', file=demo.dir + "/bitmaps/tix.gif")
513-
lbl = Tix.Label(win.window, image=image)
540+
541+
# This image is not showing up under Python unless it is set to a
542+
# global variable - no problem under Tcl. I assume it is being garbage
543+
# collected some how, even though the tcl command 'image names' shows
544+
# that as far as Tcl is concerned, the image exists and is called pyimage1.
545+
image1 = Tix.Image('photo', file=file)
546+
lbl = Tix.Label(win.window, image=image1)
514547
lbl.pack(expand=1, fill=Tix.BOTH)
515548

516549
win.place(x=30, y=150, width=190, height=120)
@@ -581,26 +614,27 @@ def MkPanedWindow(w):
581614
msg = Tix.Message(w,
582615
relief=Tix.FLAT, width=240, anchor=Tix.N,
583616
text='The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally.')
584-
group = Tix.Label(w, text='Newsgroup: comp.lang.python')
617+
group = Tix.LabelEntry(w, label='Newsgroup:', options='entry.width 25')
618+
group.entry.insert(0,'comp.lang.python')
585619
pane = Tix.PanedWindow(w, orientation='vertical')
586620

587621
p1 = pane.add('list', min=70, size=100)
588622
p2 = pane.add('text', min=70)
589623
list = Tix.ScrolledListBox(p1)
590624
text = Tix.ScrolledText(p2)
591625

592-
list.listbox.insert(Tix.END, " 12324 Re: TK is good for your health")
593-
list.listbox.insert(Tix.END, "+ 12325 Re: TK is good for your health")
594-
list.listbox.insert(Tix.END, "+ 12326 Re: Tix is even better for your health (Was: TK is good...)")
595-
list.listbox.insert(Tix.END, " 12327 Re: Tix is even better for your health (Was: TK is good...)")
596-
list.listbox.insert(Tix.END, "+ 12328 Re: Tix is even better for your health (Was: TK is good...)")
597-
list.listbox.insert(Tix.END, " 12329 Re: Tix is even better for your health (Was: TK is good...)")
598-
list.listbox.insert(Tix.END, "+ 12330 Re: Tix is even better for your health (Was: TK is good...)")
626+
list.listbox.insert(Tix.END, " 12324 Re: Tkinter is good for your health")
627+
list.listbox.insert(Tix.END, "+ 12325 Re: Tkinter is good for your health")
628+
list.listbox.insert(Tix.END, "+ 12326 Re: Tix is even better for your health (Was: Tkinter is good...)")
629+
list.listbox.insert(Tix.END, " 12327 Re: Tix is even better for your health (Was: Tkinter is good...)")
630+
list.listbox.insert(Tix.END, "+ 12328 Re: Tix is even better for your health (Was: Tkinter is good...)")
631+
list.listbox.insert(Tix.END, " 12329 Re: Tix is even better for your health (Was: Tkinter is good...)")
632+
list.listbox.insert(Tix.END, "+ 12330 Re: Tix is even better for your health (Was: Tkinter is good...)")
599633

600634
text.text['bg'] = list.listbox['bg']
601635
text.text['wrap'] = 'none'
602636
text.text.insert(Tix.END, """
603-
Mon, 19 Jun 1995 11:39:52 comp.lang.tcl Thread 34 of 220
637+
Mon, 19 Jun 1995 11:39:52 comp.lang.python Thread 34 of 220
604638
Lines 353 A new way to put text and bitmaps together iNo responses
605639
[email protected] Ioi K. Lam at University of Pennsylvania
606640
@@ -717,6 +751,7 @@ def MkExFileWidget(w):
717751
'Control' : 'Control',
718752
'Notebook' : 'NoteBook',
719753
'Option Menu' : 'OptMenu',
754+
'Paned Window' : 'PanedWin',
720755
'Popup Menu' : 'PopMenu',
721756
'ScrolledHList (1)' : 'SHList1',
722757
'ScrolledHList (2)' : 'SHList2',
@@ -795,8 +830,8 @@ def MkExFileWidget(w):
795830
##
796831
## set manager {
797832
##na {f ListNoteBook ListNBK.tcl }
798-
## {f NoteBook NoteBook.tcl }
799-
## {f PanedWindow PanedWin.tcl }
833+
##done {f NoteBook NoteBook.tcl }
834+
##done {f PanedWindow PanedWin.tcl }
800835
## }
801836
##
802837
## set misc {
@@ -817,7 +852,7 @@ def MkExFileWidget(w):
817852
stypes = {}
818853
stypes['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control',
819854
'Directory List', 'Directory Tree',
820-
'Notebook', 'Option Menu', 'Popup Menu',
855+
'Notebook', 'Option Menu', 'Popup Menu', 'Paned Window',
821856
'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)']
822857
stypes['image'] = ['Compound Image']
823858

@@ -826,43 +861,57 @@ def MkSample(nb, name):
826861
prefix = Tix.OptionName(w)
827862
if not prefix:
828863
prefix = ''
829-
w.option_add('*' + prefix + '*TixLabelFrame*label.padX', 4)
864+
else:
865+
prefix = '*' + prefix
866+
w.option_add(prefix + '*TixLabelFrame*label.padX', 4)
830867

831-
lab = Tix.Label(w, text='Select a sample program:', anchor=Tix.W)
832-
lab1 = Tix.Label(w, text='Source:', anchor=Tix.W)
868+
pane = Tix.PanedWindow(w, orientation='horizontal')
869+
pane.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH)
870+
f1 = pane.add('list', expand='1')
871+
f2 = pane.add('text', expand='5')
872+
f1['relief'] = 'flat'
873+
f2['relief'] = 'flat'
833874

834-
slb = Tix.ScrolledHList(w, options='listbox.exportSelection 0')
835-
slb.hlist['command'] = lambda args=0, w=w,slb=slb: Sample_Action(w, slb, 'run')
836-
slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb: Sample_Action(w, slb, 'browse')
875+
lab = Tix.Label(f1, text='Select a sample program:', anchor=Tix.W)
876+
lab.pack(side=Tix.TOP, expand=0, fill=Tix.X, padx=5, pady=5)
877+
lab1 = Tix.Label(f2, text='Source:', anchor=Tix.W)
878+
lab1.pack(side=Tix.TOP, expand=0, fill=Tix.X, padx=5, pady=5)
837879

838-
stext = Tix.ScrolledText(w, name='stext')
880+
slb = Tix.Tree(f1, options='hlist.width 25')
881+
slb.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5)
882+
883+
stext = Tix.ScrolledText(f2, name='stext')
839884
font = root.tk.eval('tix option get fixed_font')
840885
stext.text.config(font=font)
841-
# stext.text.bind('<1>', stext.text.focus())
842886
stext.text.bind('<Up>', lambda w=stext.text: w.yview(scroll='-1 unit'))
843887
stext.text.bind('<Down>', lambda w=stext.text: w.yview(scroll='1 unit'))
844888
stext.text.bind('<Left>', lambda w=stext.text: w.xview(scroll='-1 unit'))
845889
stext.text.bind('<Right>', lambda w=stext.text: w.xview(scroll='1 unit'))
890+
stext.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=7)
846891

847-
run = Tix.Button(w, text='Run ...', name='run', command=lambda args=0, w=w,slb=slb: Sample_Action(w, slb, 'run'))
848-
view = Tix.Button(w, text='View Source ...', name='view', command=lambda args=0,w=w,slb=slb: Sample_Action(w, slb, 'view'))
892+
frame = Tix.Frame(f2, name='frame')
893+
frame.pack(side=Tix.TOP, expand=0, fill=Tix.X, padx=7)
849894

850-
lab.form(top=0, left=0, right='&'+str(slb))
851-
slb.form(left=0, top=lab, bottom=-4)
852-
lab1.form(left='&'+str(stext), top=0, right='&'+str(stext), bottom=stext)
853-
run.form(left=str(slb)+' 30', bottom=-4)
854-
view.form(left=run, bottom=-4)
855-
stext.form(bottom=str(run)+' -5', left='&'+str(run), right='-0', top='&'+str(slb))
895+
run = Tix.Button(frame, text='Run ...', name='run')
896+
view = Tix.Button(frame, text='View Source ...', name='view')
897+
run.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE)
898+
view.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE)
856899

857900
stext.text['bg'] = slb.hlist['bg']
858901
stext.text['state'] = 'disabled'
859902
stext.text['wrap'] = 'none'
903+
stext.text['width'] = 80
860904

861905
slb.hlist['separator'] = '.'
862906
slb.hlist['width'] = 25
863907
slb.hlist['drawbranch'] = 0
864908
slb.hlist['indent'] = 10
865909
slb.hlist['wideselect'] = 1
910+
slb.hlist['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
911+
slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'browse')
912+
913+
run['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
914+
view['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'view')
866915

867916
for type in ['widget', 'image']:
868917
if type != 'widget':
@@ -879,13 +928,9 @@ def MkSample(nb, name):
879928
run['state'] = 'disabled'
880929
view['state'] = 'disabled'
881930

882-
def Sample_Action(w, slb, action):
931+
def Sample_Action(w, slb, stext, run, view, action):
883932
global demo
884933

885-
run = w._nametowidget(str(w) + '.run')
886-
view = w._nametowidget(str(w) + '.view')
887-
stext = w._nametowidget(str(w) + '.stext')
888-
889934
hlist = slb.hlist
890935
anchor = hlist.info_anchor()
891936
if not anchor:

0 commit comments

Comments
 (0)