Pmw demonstrations and tests

Pmw comes with an extensive range of demonstrations and tests. The demonstrations can be used to get a feel for what is provided by Pmw and the demonstration code can be viewed to see examples of how to use Pmw. The tests can be executed to check that there are no problems with running Pmw in your environment.

Demonstrations

The Pmw demos directory contains demonstration scripts showing many of the features of Pmw megawidgets. To view a comprehensive package of all the demonstrations, including a view of the source code, run the All.py script. Run All.py -help for a short description of the script's options.

All of the demonstrations may also be run separately. Most of the demonstrations show some of the features of one of the Pmw megawidgets. For example, to see a demonstration of the ButtonBox megawidget, change into the demos directory and run

python ButtonBox.py

Other demonstrations, which show other features of Pmw include

BltGraph.py         demonstrates the Pmw interface to
                    the BLT graph and vector commands
BltTabset.py        demonstrates the Pmw interface to
                    the BLT tabset command
Colors.py           how to set color schemes
ConfigClass.py      how to configure the python class
                    of a megawidger component
ErrorHandling.py    how Pmw displays run time errors
                    in a window
ExampleDemo.py      template for new demonstrations
Grid.py             the tkinter Grid geometry manager
LogicalFont.py      how to use standard values for fonts
MessageInfo.py      how to extend the Pmw MegaToplevel
                    class
NestedDialogs.py    how nested modal dialogs behave
Resources.py        how to use the option database to
                    modify Tk widget option defaults
Resources_Pmw.py    how to use the option database to
                    modify megawidget option defaults
ShowBusy.py         demonstrates the Pmw interface to
                    the BLT busy command
SpecialEntry.py     deriving from Pmw.EntryField
Spectrum.py         some of the Pmw color handling
                    functions
SpeedTest.py        tests the speed of creating Pmw
                    megawidgets
TextDisplay.py      how to extend the Pmw MegaWidget
                    class
WidgetDestroy.py    megawidget destruction
Creating demonstrations of new megawidgets

If you create a new megawidget you can create a demonstration for it by using the file ExampleDemo.py as a template. This template allows the demonstration to be run individually or to be automatically included as part of the demonstration package All.py. You should take a copy of the template and name the new file after your megawidget. You should then replace each instance of the word EXAMPLE with the name of your megawidget and replace the code in the __init__ method with code to create and initialise one or more instances of your megawidget, which should be a child of parent. You can add other methods as necessary.

Tests

The Pmw tests directory contains a test framework and a set of test scripts for Pmw. The tests cover the standard tkinter module and most of the Pmw megawidgets. The tests make a great demonstration of the flexibility of the megawidgets. Simply change into the tests directory and run python All.py.

If all tests pass there should be no output printed to standard output. If any of the tests fail, please send to the Pmw discussion and announcement mailing list.

All of the tests may be run separately. Most of the tests test the features of one of the Pmw megawidgets. For example, to execute the test for the ButtonBox megawidget, run

python ButtonBox_test.py

The Test.py file contains general testing functions and is imported by all test files. Other files, which test other features of Pmw include

Blt_test.py           BLT vector and graph interface
Colors_test.py        setting color schemes
MegaWidget_test.py    creation of megawidget classes
Options_test.py       option and component handling
PmwBase_test.py       more option and component handling
Tkinter_test.py       Tk widgets in the tkinter module
Creating tests for new megawidgets

If you create a new megawidget you should create a test for it. There is no template file for creating tests, but by looking at the other Pmw tests (for example, ScrolledText_test.py) you will get some idea of how to create a test for your megawidget.

The test files are designed to be run both individually or automatically by the test package All.py. Each test file must define the testData tuple. This consists of a sequence of 2-element tuples, each tuple being a test specification for one megawidget. Usually a file tests only one megawidget and so there is only one test specification. The first element in the specification is the megawidget class and the second is a sequence of (yet more) 2-element tuples. In each of these tuples, the first element is a sequence of individual tests to perform on an instance of the megawidget and the second element is a dictionary to use for the keyword arguments when creating the instance. Each individual test is a tuple, the meaning of which depends on the type of the first element, which may be either a string, a function or a method of the megawidget class, as explained below.

Some special functions and values supplied by the Test module that may be used in the tests include:

Test.callback       callback taking no arguments
Test.callback1      callback taking one argument
Test.callbackN      callback taking any number of arguments

Test.currentWidget  returns the widget instance being tested
Test.num_options    returns number of options for the widget

Test.earthris       a sample tkinter.PhotoImage
Test.flagup         a sample tkinter.BitmapImage
Test.floatvar       a tkinter.DoubleVar
Test.stringvar      a tkinter.StringVar

To slow down a test (to see what is being displayed), add the following line which sets the delay between tests to (say) 1000 milliseconds:

Test.setdelay(1000)

To print information about what is being tested, add the line:

Test.setverbose(1)

Pmw 2.1 - 31 Dec 2020 - Home