There are two aspects of Pmw, unrelated to megawidgets, that require special attention. Firstly, Pmw is made up of many sub-modules, potentially making access to its various classes and functions cumbersome for the user. Secondly, Pmw is regularly being modified and added to, thus requiring the release of new versions. Therefore, techniques for making access to the sub-modules easy and efficient and for dealing with the different versions have been developed. These techniques are incorporated into the dynamic loader which Pmw creates when it is first imported.
The first purpose of the loader is to give access to all Pmw classes
and functions through a single entry point, the Pmw. prefix. For
example, to access the ComboBox class (which resides in one of the
sub-modules of Pmw), you just have to use Pmw.ComboBox
. Without
the loader, this would be a more complicated reference, such as,
hypothetically, Pmw.PmwComboBox.Combobox
.
The second purpose of the loader is to delay the importing of the sub-modules until they are needed. This improves the startup time of applications which only use a few Pmw megawidgets. It also allows more megawidgets to be added to the library without slowing down applications which do not use them.
The third purpose of the loader is to allow a script using Pmw to specify which version of Pmw it requires. This allows an application to continue working correctly even after newer releases of Pmw have been made which are not compatible with the version expected by the application. Several versions of Pmw can be installed at once, with the actual version used being specified by each application. In addition, the loader can be configured to search in one or more alpha versions of Pmw. These versions may contain new megawidgets, or new versions of existing megawidgets, that are currently not in the base releases.
Several functions are available to set and query the version of
Pmw being used. These are Pmw.setversion()
and
Pmw.setalphaversions()
which specify the version and alpha
versions (if any) to use for this session; Pmw.version()
which
returns the version(s) being used by this session; and
Pmw.installedversions()
which returns the version(s) of Pmw
currently installed. These are described in the
Pmw functions reference manual.
When Pmw is first imported, an instance of PmwLoader is created
and placed into sys.modules['Pmw']
. From that point on, any
reference to attributes of the Pmw 'module' is handled by the
loader. The real Pmw package is stored in sys.modules['_Pmw']
.
The loader searches the Pmw package base directory for
sub-directories with the prefixes Pmw_
and Alpha_
, which
contain Pmw base releases and alpha releases. The version numbers
are given by the part of the directory name following the prefix.
These versions are available for use and are those returned by the
Pmw.installedversions
function. The current version is set to
the base release with the greatest version number. When the first
reference to a Pmw class or function is made, the loader reads the
files named Pmw.def in the current base version directory and
also in the alpha directories (if any). These files list all the
classes and functions supported by the version. Pmw attributes
are first searched for in the alpha directories and then in the
base version directory. The first directory which supports the
reference is used. In this way, alpha versions override base
versions.
The directory Alpha_99_9_example
contains a simple example of
how to structure an alpha version. The following code can be used
to request that the alpha version be used and then creates an
instance of a new megawidget defined in the alpha version.
import Pmw Pmw.setalphaversions('99.9.example') # Create a standard message dialog using the base Pmw version. ordinary = Pmw.MessageDialog( message_text = 'Ordinary\nPmw Dialog') # Create an example dialog using the alpha Pmw version. alpha = Pmw.AlphaExample()
Home. Pmw 0.6.2 Maintainer gregm@iname.com. 23 Feb 1998