| Previous: Creating parameters | Up: Index | Next: Description of classes |
This HTML documentation is no longer maintained. See sciparam-manual.pdf for an updated version.

Creating dialogs and notebooks

Import of dialog classes

SciParam contains the following dialog classes: SciParam supports accessing these in several ways: This one is deprecated, except for saving keystrokes in interactive sessions: There are other possible ways to import them, but only these are guaranteed to work in future versions.

Using a dialog

Using a ParameterDialog works much like using any other dialog in wxPython. Additionally you have to specify a list of parameters and optionally a number of columns (defaults to one) to use:

    dialog = ParameterDialog(parent, -1, 'Dialog Title', parameter, columns=2)

ParameterNotebookDialog takes a list of pages instead of parameters as argument. Each page is a 2-tuple consisting of page name and parameter list for this page:

    dialog = ParameterNotebookDialog(parent, -1, 'Parameter Title',
                                     [('Page 1', parameter1),
                                      ('Page 2', parameter2)],
                                     columns=2)

Sample code

File examples/notebook_example.py:
#!/usr/bin/env python
#
# Copyright (C) 2002 by Intevation GmbH
# Authors:
# Thomas Arendsen Hein <thomas@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with the software for details.

"""
Notebook full of Scientific Parameter Controls for wxPython
"""

from wxPython.wx import *

from SciParam import FloatParam, IntParam, StringParam, ChoiceParam, DistParam
from SciParam import ParameterNotebookDialog


class MyApp(wxApp):
    def OnInit(self):
        parameter1 = [
            StringParam('Name', 'a unique identifier', required=1,
                        value='Silicon',
                        comment='This is an example for a required value.\n'
                                'The user can change this comment to note the '
                                'source of this information.'),
            StringParam('Symbol', 'chemical symbol', required=1, value='Si'),
            IntParam('Atomic No',
                     'Number in the periodic table of the elements',
                     value=14, wrange='[1;260]', erange='[1;oo['),
            FloatParam('Atomic Mass', None, value=28.0855, erange='[0;oo['),
            FloatParam('Melting Point', 'under normal conditions', '°C',
                       value=1414,
                       wrange='[-273.15;4e3]', erange='[-273.15;oo['),
            FloatParam('Boiling Point', 'under normal conditions', '°C',
                       value=3265, wrange='[-270;6e3]', erange='[-273.15;oo['),
            ChoiceParam('Crystal', 'crystal structure',
                        choices=[None, 'simple cubic', 'face centered cubic',
                                 'body centered cubic', 'diamond cubic',
                                 'tetragonal', 'orthorombic', 'monoclinc'],
                        value='face centered cubic', long=1),
            DistParam('Temperature', 'temperature of samples', '°C',
                      default=20, value=17.5, erange='[-273.15;oo[',
                      dist=(3.7, 'normal')),
            DistParam('Volume', 'Volume of used samples', 'cm³',
                      default='2;20/uniform', erange='[0;oo['),
            ChoiceParam('Verified', 'Have these values been checked?',
                        choices=ChoiceParam.yes_no, value=0),
        ]
        parameter2 = [
            StringParam('Name', 'a unique identifier'),
            IntParam('Things', 'Number of things', 'pcs',
                     erange='[0;oo['),
            FloatParam('Price', 'per thing', '¤', value=0.49, default=1.20,
                       wrange='[0.50;1e5[', erange='[0;oo[',
                       comment='This is too cheap'),
            ChoiceParam('Size', 'Select one of 3m, 5m, 7m', 'm',
                        default=5, choices=[3, 5, 7]),
            ChoiceParam('In Stock', 'Are there enough things?'),
        ]
        parameter = [["Element", parameter1],
                     ["Things", parameter2]]

        dialog = ParameterNotebookDialog(NULL, -1,
                                         'Scientific Parameter Notebook',
                                         parameter, columns=2)
        if dialog.ShowModal() == wxID_OK:
            print "OK"
        else:
            print "Cancel"
        for page in parameter:
            for par in page[1]:
                print par.name, "=", par.value
                print " comment =", par.comment
                if isinstance(par, DistParam):
                    print " dist =", par.dist
        dialog.Destroy()
        return true


if __name__ == "__main__":
    try:
        import locale
        locale.setlocale(locale.LC_ALL, "")
    except ImportError:
        # the locale module may not be available on some systems
        pass

    app = MyApp()
    app.MainLoop()


| Previous: Creating parameters | Up: Index | Next: Description of classes |