# This is a rough collection of tests that can not be automated.
# To add a new test, create a function with name ending in '_test'.
# ----------------------------------------------------------------------
def scrolledframeflashing_test():
# Script which demonstrates continuous flashing of dynamic scrollbars
# When this script is run, the two scrollbars will be continuously
# mapped and unmapped and the window will continuously change size.
frame
= Tkinter
.Frame(root
)
frame
.pack(fill
= 'both', expand
= 1)
sf
= Pmw
.ScrolledFrame(frame
, borderframe
= 0)
sf
.pack(fill
= 'both', expand
= 1)
inner
= Tkinter
.Frame(sf
.interior(),
inner
.pack(fill
= 'both', expand
= 1)
# ----------------------------------------------------------------------
def scrolledlistboxflashing_test():
# Script which demonstrates continuous flashing of dynamic scrollbars
# in Pmw.ScrolledListBox.
# When this script is run, the two scrollbars will be continuously
# mapped and unmapped and the window will continuously change size.
frame
= Tkinter
.Frame(root
)
frame
.pack(fill
= 'both', expand
= 1)
sf
= Pmw
.ScrolledListBox(frame
,
sf
.pack(fill
= 'both', expand
= 1)
sf
.insert('end', '2' * 20)
# ----------------------------------------------------------------------
def scrolledlistboxflashing2_test():
# Another script which demonstrates continuous flashing of dynamic
# scrollbars in Pmw.ScrolledListBox under Pmw.0.8.
# When this script is run, the two scrollbars will be continuously
# mapped and unmapped and the window will continuously change size.
# (This did not display error when tried with Pmw.0.8, 99/8/3)
sectionList
= ['1', '2', '3', '4', '5', '6', '7', '8', '9',
for counter
in sectionList
:
slb
.insert('end', counter
)
slb
= Pmw
.ScrolledListBox(root
)
# ----------------------------------------------------------------------
def scrolledtextflashing_test():
# Script which demonstrates continuous flashing of dynamic scrollbars
# When this script is run, the two scrollbars will be continuously
# mapped and unmapped and the window will continuously change size.
frame
= Tkinter
.Frame(root
)
frame
.pack(fill
= 'both', expand
= 1)
sf
= Pmw
.ScrolledText(frame
,
sf
.pack(fill
= 'both', expand
= 1)
sf
.insert('end', '2' * 20)
# ----------------------------------------------------------------------
def scrolledcanvasflashing_test():
# Script which demonstrates continuous flashing of dynamic scrollbars
# When this script is run, the two scrollbars will be continuously
# mapped and unmapped and the window will continuously change size.
frame
= Tkinter
.Frame(root
)
frame
.pack(fill
= 'both', expand
= 1)
sf
= Pmw
.ScrolledCanvas(frame
,
canvas_scrollregion
= (0, 0, 301, 200),
sf
.pack(fill
= 'both', expand
= 1)
# ----------------------------------------------------------------------
def scrolledframeflashing2_test():
# The two scrollbars will be continuously mapped and unmapped, but
# the toplevel window will remain the same size.
sf
= Pmw
.ScrolledFrame(frame
, borderframe
= 0)
inner
= Tkinter
.Frame(sf
.interior(),
# ----------------------------------------------------------------------
Demonstrates bug in Pmw.0.8.1 and earlier.
Click on this button, click on OK in the dialog, then Exit below.
When this window appears again, clicking on this button gives
TclError: can't invoke "wm" command: application has been destroyed
self
.messagedialog
= Pmw
.MessageDialog(message_text
= 'Testing')
self
.messagedialog
.withdraw()
text
= text
, command
= self
.messagedialog
.activate
)
exit
= Tkinter
.Button(text
= 'Exit', command
= root
.destroy
)
# ----------------------------------------------------------------------
def componentgroup_test():
bb
.configure(Button_background
= 'yellow')
bb
.after(3000, lambda bb
= bb
:
bb
.configure(Button_background
= 'green'))
bb
= Pmw
.ButtonBox(Button_background
= 'red')
mb
= Pmw
.MenuBar(Button_background
= 'red')
mb
.configure(Button_background
= 'yellow')
pw
= Pmw
.PanedWidget(Frame_background
= 'red')
pw
.configure(Frame_background
= 'yellow')
rs
= Pmw
.RadioSelect(Button_background
= 'red')
rs
.configure(Button_background
= 'yellow')
bb
.after(3000, lambda bb
= bb
, addbutton
= addbutton
: addbutton(bb
))
# ----------------------------------------------------------------------
# Test that the balloon does not reappear if the mouse button is
# pressed down inside a widget and then, while the mouse button is
# being held down, the mouse is moved outside of the widget and
# then moved back over the widget.
# Test that when a widget is destroyed while a balloon is being
# displayed for it then the balloon is withdrawn.
# Test that when a widget is destroyed while a balloon is being
# displayed for another widget then the balloon is not withdrawn.
# Test that there is no eror when a widget is destroyed during the
# initwait period (between when the mouse enters the widget and
# when the initwait timer goes off).
# Test that if unbind() is called on a widget that triggered the
# balloon to be displayed then the balloon is withdrawn. Also
# test that if another widget triggered the balloon then the
# balloon is not withdrawn.
# Test that if tagunbind() is called on a canvas or text item that
# triggered the balloon to be displayed then the balloon is
# withdrawn. Also test that if another widget or item triggered
# the balloon then the balloon is not withdrawn.
# ----------------------------------------------------------------------
# A class which prints out a message when an instance is deleted.
class MyToplevel(Tkinter
.Toplevel
):
Tkinter
.Toplevel
.__init
__(self
)
def _runMemoryLeakTest():
Pmw
.ButtonBox(top
).pack()
Pmw
.EntryField(top
).pack()
Pmw
.LabeledWidget(top
).pack()
Pmw
.MessageBar(top
).pack()
Pmw
.OptionMenu(top
).pack()
Pmw
.PanedWidget(top
).pack()
Pmw
.RadioSelect(top
).pack()
Pmw
.ScrolledCanvas(top
).pack()
Pmw
.ScrolledField(top
).pack()
Pmw
.ScrolledFrame(top
).pack()
Pmw
.ScrolledListBox(top
).pack()
Pmw
.ScrolledText(top
).pack()
Pmw
.TimeCounter(top
).pack()
def _killMemoryLeakTest():
Click on the "Run test" button to create instances of
all Pmw megawidgets. Then click on the "Destroy" button.
The message "Window deleted" should be printed to
label
= Tkinter
.Label(text
= memoryLeakMessage
)
run
= Tkinter
.Button(text
= 'Run test', command
= _runMemoryLeakTest
)
kill
= Tkinter
.Button(text
= 'Destroy', command
= _killMemoryLeakTest
)
# ----------------------------------------------------------------------
print 'This test continuously creates and deletes megawidgets and'
print 'their components. It calls the "top" program, so'
print 'may not work on non-Unix operating systems. Run it for a long,'
print 'long time and check that the process memory size does not'
print 'continue to increase. Kill with <Control-C>.'
# 1. Create/delete all megawidgets:
Pmw
.AboutDialog
, Pmw
.Balloon
, Pmw
.ButtonBox
, Pmw
.ComboBox
,
Pmw
.ComboBoxDialog
, Pmw
.Counter
, Pmw
.CounterDialog
, Pmw
.Dialog
,
Pmw
.EntryField
, Pmw
.Group
, Pmw
.HistoryText
, Pmw
.LabeledWidget
,
Pmw
.MainMenuBar
, Pmw
.MenuBar
, Pmw
.MessageBar
, Pmw
.MessageDialog
,
Pmw
.NoteBook
, Pmw
.OptionMenu
, Pmw
.PanedWidget
, Pmw
.PromptDialog
,
Pmw
.RadioSelect
, Pmw
.ScrolledCanvas
, Pmw
.ScrolledField
,
Pmw
.ScrolledFrame
, Pmw
.ScrolledListBox
, Pmw
.ScrolledText
,
Pmw
.SelectionDialog
, Pmw
.TextDialog
, Pmw
.TimeCounter
,
toplevel
= Tkinter
.Toplevel()
balloon
= Pmw
.Balloon(toplevel
)
button
= Tkinter
.Button(toplevel
)
canvas
= Tkinter
.Canvas(toplevel
)
item
= canvas
.create_rectangle(0, 0, 100, 100)
# 3. Adding and deleting menu:
toplevel
= Tkinter
.Toplevel()
mainmenu
= Pmw
.MainMenuBar(toplevel
)
mainmenu
.addmenu('Foo', 'help')
toplevel
.configure(menu
= mainmenu
)
# 4. Adding and deleting notebook page:
toplevel
= Tkinter
.Toplevel()
notebook
= Pmw
.NoteBook(toplevel
)
# 5. Adding and deleting panedwidget pane:
toplevel
= Tkinter
.Toplevel()
panedwidget
= Pmw
.PanedWidget(toplevel
)
panedwidget
.insert('Foo', size
= 100)
# 6. Adding and deleting MenuBar menu:
toplevel
= Tkinter
.Toplevel()
menubar
= Pmw
.MenuBar(toplevel
)
# 7. Setting OptionMenu items:
toplevel
= Tkinter
.Toplevel()
optionmenu
= Pmw
.OptionMenu(toplevel
, items
= ('XXX', 'YYY', 'ZZZ'))
# 8. Setting Tkinter.Canvas scrollcommand option:
toplevel
= Tkinter
.Toplevel()
scrollcanvas
= Pmw
.ScrolledCanvas(toplevel
)
# Loop and run each test:
label
.configure(text
= count
)
# 1. Create/delete all megawidgets:
for widgetClass
in megawidgets
:
if widgetClass
== Pmw
.MainMenuBar
:
root
.configure(menu
= widget
)
elif hasattr(widgetClass
, 'pack'):
balloon
.bind(button
, 'help')
balloon
.tagbind(canvas
, item
, 'help')
# tagbind leaks due to a bug in Tkinter (v1.127) Canvas - it adds
# bindings to self._tagcommands but does not delete them.
# 3. Adding and deleting MainMenuBar menu:
mainmenu
.addmenu('File', 'help')
mainmenu
.deletemenu('File')
# 4. Adding and deleting notebook page:
# 5. Adding and deleting panedwidget pane:
panedwidget
.insert('File', size
= 100)
panedwidget
.delete('File')
# 6. Adding and deleting MenuBar menu:
menubar
.addmenu('File', 'help')
menubar
.deletemenu('File')
# 7. Setting OptionMenu items:
optionmenu
.setitems(('aaa', 'bbb', 'ccc'))
# 8. Setting Tkinter.Canvas scrollcommand option:
scrollcanvas
.configure(hscrollmode
= 'static')
scrollcanvas
.configure(hscrollmode
= 'dynamic')
# lines = os.popen('top').readlines()
lines
= os
.popen('top -b -n 1 -p %d' % pid
).readlines()
# if string.find(line, 'python1.5.2') > 0:
if string
.find(line
, '^ *%d' % pid
) > 0:
# size = string.atoi(string.lstrip(line[27:32]))
size
= string
.atoi(string
.lstrip(line
[22:29]))
print time
.strftime('%H:%M:%S', time
.localtime(time
.time())),
# ----------------------------------------------------------------------
print 'Usage:', sys
.argv
[0], '<test>'
print ' where <test> is one of:'
for name
in locals().keys():
if testName
not in tests
:
print 'Unknown test "' + testName
+ '"'
if testName
== 'reinitialise_test':
# Run this by itself, since it calls Tkinter.Tk, mainloop, etc.
# Use Pmw version in this distribution:
# To use a different version of Pmw, comment out the three above lines
# and the "import Test" line and uncomment these three:
testFunction
= locals()[testName
]
if testName
!= 'memoryleak2_test':
# This does not use mainloop.