Description: Pmw - a toolkit for building high-level compound widgets in Python

# 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 the test output to the maintainer at gregm@iname.com.

  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.

  - If the first element is a string, then it is treated as an option of the megawidget and configure() is called to set the option to the value specified by the second element. After setting the option, cget() is called to query the option. If the test tuple has three elements, then the value returned by cget() must equal the value specified by the third element. Otherwise, the value returned must equal the value specified by the second element. For example,

          ('vscrollmode', 'static'),
          ('text_relief', 'sunken'),
          ('vscrollmode', 'bogus', 'ValueError: bad vscrollmode ' +
            'option "bogus": should be static, dynamic, or none'),

  - If the first element is a function or method, then the function or method is called. The arguments to the call are given by the second element. (As a special case, if the second element is not a tuple, it is used as the only argument to the call.) The test tuple may have 2, 3 or 4 elements.

    - If it has two elements, then the value returned by the call must be None. For example,

            (c.exportfile, '/tmp/ScrolledText_test.py'),
            (os.unlink, '/tmp/ScrolledText_test.py'),

    - If it has four elements, then the third element is a dictionary to use for the keyword arguments in the call and the value returned by the call must equal the value specified by the fourth element. For example,

            (c.search, ('abc', '0.0'), {'nocase': 1}, '2.24'),

    - If is has three elements and the third element is a dictionary, then it is used for the keyword arguments in the call and the value returned by the call must be None. For example

            (c.configurepane, 'first', {'size' : 200}),

    - If is has three elements and the third element is not a dictionary, then the value returned by the call must equal the value specified by the third element. For example,

            (c.components, (), ['hull', 'label']),
            (c.add, ('Legumes',),
              'ValueError: name "Legumes" already exists'),

  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 1.3.3 - 29 Mar 2014 - Home