mirror of https://github.com/python/cpython
Properly set static options for tixBalloon and tixResizeHandle.
Expose Tix.ResizeHandle.{detach_widget,hide,show}. Update Tix demos.
This commit is contained in:
parent
3a89b2b131
commit
652e1917c6
|
@ -0,0 +1,98 @@
|
|||
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# Tix Demostration Program
|
||||
#
|
||||
# This sample program is structured in such a way so that it can be
|
||||
# executed from the Tix demo program "tixwidgets.py": it must have a
|
||||
# procedure called "RunSample". It should also have the "if" statment
|
||||
# at the end of this file so that it can be run as a standalone
|
||||
# program.
|
||||
|
||||
# This file demonstrates the use of the tixPanedWindow widget. This program
|
||||
# is a dummy news reader: the user can adjust the sizes of the list
|
||||
# of artical names and the size of the text widget that shows the body
|
||||
# of the article.
|
||||
|
||||
import Tix
|
||||
|
||||
TCL_ALL_EVENTS = 0
|
||||
|
||||
def RunSample (root):
|
||||
panedwin = DemoPanedwin(root)
|
||||
panedwin.mainloop()
|
||||
panedwin.destroy()
|
||||
|
||||
class DemoPanedwin:
|
||||
def __init__(self, w):
|
||||
self.root = w
|
||||
self.exit = -1
|
||||
|
||||
z = w.winfo_toplevel()
|
||||
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
|
||||
|
||||
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)
|
||||
p2 = pane.add('text', min=70)
|
||||
list = Tix.ScrolledListBox(p1)
|
||||
list.listbox['width'] = 80
|
||||
list.listbox['height'] = 5
|
||||
text = Tix.ScrolledText(p2)
|
||||
text.text['width'] = 80
|
||||
text.text['height'] = 20
|
||||
|
||||
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.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
|
||||
|
||||
Hi,
|
||||
|
||||
I have implemented a new image type called "compound". It allows you
|
||||
to glue together a bunch of bitmaps, images and text strings together
|
||||
to form a bigger image. Then you can use this image with widgets that
|
||||
support the -image option. For example, you can display a text string string
|
||||
together with a bitmap, at the same time, inside a TK button widget.
|
||||
""")
|
||||
text.text['state'] = 'disabled'
|
||||
|
||||
list.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6)
|
||||
text.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6)
|
||||
|
||||
group.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH)
|
||||
pane.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH, expand=1)
|
||||
|
||||
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
|
||||
box.add('ok', text='Ok', underline=0, width=6,
|
||||
command=self.quitcmd)
|
||||
box.add('cancel', text='Cancel', underline=0, width=6,
|
||||
command=self.quitcmd)
|
||||
box.pack(side=Tix.BOTTOM, fill=Tix.X)
|
||||
|
||||
def quitcmd (self):
|
||||
self.exit = 0
|
||||
|
||||
def mainloop(self):
|
||||
while self.exit < 0:
|
||||
self.root.tk.dooneevent(TCL_ALL_EVENTS)
|
||||
|
||||
def destroy (self):
|
||||
self.root.destroy()
|
||||
|
||||
if __name__ == '__main__':
|
||||
root = Tix.Tk()
|
||||
RunSample(root)
|
|
@ -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:
|
||||
|
|
|
@ -489,7 +489,9 @@ class Balloon(TixWidget):
|
|||
message Message"""
|
||||
|
||||
def __init__(self, master=None, cnf={}, **kw):
|
||||
TixWidget.__init__(self, master, 'tixBalloon', ['options'], cnf, kw)
|
||||
# static seem to be -installcolormap -initwait -statusbar -cursor
|
||||
static = ['options', 'installcolormap', 'initwait', 'statusbar', 'cursor']
|
||||
TixWidget.__init__(self, master, 'tixBalloon', static, cnf, kw)
|
||||
self.subwidget_list['label'] = _dummyLabel(self, 'label',
|
||||
destroy_physically=0)
|
||||
self.subwidget_list['message'] = _dummyLabel(self, 'message',
|
||||
|
@ -1194,12 +1196,27 @@ class ResizeHandle(TixWidget):
|
|||
"""Internal widget to draw resize handles on Scrolled widgets."""
|
||||
|
||||
def __init__(self, master, cnf={}, **kw):
|
||||
# There seems to be a Tix bug rejecting the configure method
|
||||
# Let's try making the flags -static
|
||||
flags = ['options', 'command', 'cursorfg', 'cursorbg',
|
||||
'handlesize', 'hintcolor', 'hintwidth',
|
||||
'x', 'y']
|
||||
# In fact, x y height width are configurable
|
||||
TixWidget.__init__(self, master, 'tixResizeHandle',
|
||||
['options'], cnf, kw)
|
||||
flags, cnf, kw)
|
||||
|
||||
def attach_widget(self, widget):
|
||||
self.tk.call(self._w, 'attachwidget', widget._w)
|
||||
|
||||
def detach_widget(self, widget):
|
||||
self.tk.call(self._w, 'detachwidget', widget._w)
|
||||
|
||||
def hide(self, widget):
|
||||
self.tk.call(self._w, 'hide', widget._w)
|
||||
|
||||
def show(self, widget):
|
||||
self.tk.call(self._w, 'show', widget._w)
|
||||
|
||||
class ScrolledHList(TixWidget):
|
||||
"""ScrolledHList - HList with automatic scrollbars."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue