add_keyarg(self,
name=None,
default=None,
basic_types=[ ] ,
container_types=[ ] ,
dim=( ) ,
arg_type=None,
min=0,
max=1000,
desc_short=None,
desc=None,
list_titles=None,
wiz_element_type=' default ' ,
wiz_combo_choices=None,
wiz_combo_data=None,
wiz_combo_iter=None,
wiz_combo_list_min=None,
wiz_filesel_wildcard=-1,
wiz_dirsel_style=-1,
wiz_read_only=None,
wiz_filesel_preview=True,
can_be_none=False,
can_be_empty=False,
none_elements=False)
| source code
|
Wrapper method for adding keyword argument information to the
container.
Types
The basic Python data types allowed for the argument are specified
via the basic_types argument. The currently supported values
include:
-
'all': Special value used to deactivate type-checking.
-
'bool': Boolean values (True and False).
-
'float': Floating point numbers.
-
'func': Python function objects.
-
'int': Integer numbers.
-
'number': Special value allowing for any number type.
-
'str': String objects.
-
'file object': File objects (instance of file or any object with
a write() method).
The 'number' value is special in that it allows for both 'int' and
'float' values. If the argument should be a higher rank object, then
the container_types argument should be supplied. The allowed values
currently include:
-
'all': Special value used to deactivate type-checking.
-
'list': Python lists.
-
'number array': Special value meaning both 'list' and 'numpy
array'.
-
'numpy array': NumPy array objects.
-
'set': Python sets.
-
'tuple': Python tuples.
Here, the 'number array' is also special and allows for both 'list'
and 'numpy array' containers. Note that only the basic types 'float',
'int', and 'number' are allowed with this value.
Rank and dimensionality
To distinguish between basic Python data types and higher rank
container types, as well as fixing the dimensionality of the higher
rank objects, the 'dim' parameter should be supplied. This should be a
tuple with elements consisting of integers or None. If multiple ranks
or dimensionality are allowed, then a list of tuples can be
supplied.
Rank
The number of elements of the 'dim' tuples define the rank. For
example a number is rank 0, a vector is rank 1, and a matrix is rank
2.
Dimensionality
The dimensionality, or number of elements, for each rank are fixed
by supplying integers in the 'dim' tuple. If the dimensionality can
be variable, the value of None should be supplied instead.
Examples
For basic Python data types, use the empty tuple:
For a list of basic data types of unknown length, use:
For a numpy array of 5 elements, use:
For a numpy 3D matrix, use:
For a simple string or list of string, use:
Special argument types
The 'arg_type' keyword enables a number of special argument types to
be defined. This is used to set up special UI elements. The current
set of values are:
-
'dir': This causes the argument to not be shown
in certain UIs, as this indicates that the user function already
has a 'file sel *' type argument and hence directory selection is
redundant.
-
'dir sel': Indicate to certain UIs that a dir
selection dialog is required.
-
'file sel read': Indicate to certain UIs that a file
selection dialog for reading a file is required.
-
'file sel write': Indicate to certain UIs that a file
selection dialog for writing a file is required.
-
'file sel multi read': The same as 'file sel read', except that
multiple files can be selected simultaneously.
-
'file sel multi write': The same as 'file sel write', except that
multiple files can be selected simultaneously.
-
'force flag': Used to suppress the argument in the GUI.
For example when writing a file, the normal 'force' argument is
meaningless in the GUI as the operating file system interface will
ask if the file should be overwritten.
-
'free format': Used in the GUI to suppress the default
argument UI element and instead show the special free file format
UI element.
-
'func': Used in the GUI to suppress the argument
as functions are not supported.
-
'func args': Used in the GUI to suppress the argument
as functions are not supported.
-
'spin ID': Activate the special spin ID UI element
in the GUI.
In addition, some of these values will automatically set the 'dim',
'basic_types', and 'container_types' arguments:
_________________________________________________________________________________________
| | | | |
| Argument | dim | basic_types | container_types |
|______________________|_______________|______________________________|_________________|
| | | | |
| dir | () | ['str'] | [] |
| dir sel | () | ['str'] | [] |
| file sel read | () | ['str', 'file object read'] | [] |
| file sel write | () | ['str', 'file object write'] | [] |
| file sel multi read | [(), (None,)] | ['str', 'file object read'] | ['list'] |
| file sel multi write | [(), (None,)] | ['str', 'file object write'] | ['list'] |
| force flag | () | ['bool'] | [] |
| func | () | ['func'] | [] |
| func args | (None,) | ['all'] | ['tuple'] |
| spin ID | () | ['str'] | [] |
|______________________|_______________|______________________________|_________________|
- Parameters:
name (str) - The name of the argument.
default (anything) - The default value of the argument.
dim (tuple of (int or None) or list of tuples of (int or None)) - The dimensions of the object to check.
basic_types (list of str) - The types of values are allowed for the argument.
container_types (list of str) - The container types allowed for the argument.
arg_type (str) - A special type of argument. See the docstring for details.
min (int) - The minimum value allowed for integer types. This is used in the
wx.SpinCtrl for example.
max (int) - The maximum value allowed for integer types. This is used in the
wx.SpinCtrl for example.
desc_short (str) - The short human-readable description of the argument. This is
used in the RelaxError messages to refer to the argument, as well
as in the GUI user function page elements.
desc (str) - The long human-readable description of the argument.
list_titles (list of str) - The titles of each of the elements of the fixed length lists.
This only applies to lists or list of lists.
wiz_element_type (str) - The type of GUI element to create. If left to 'default', then
the currently set default element will be used. If set to
'text', a wx.TextCtrl element will be used. If set to 'combo', a
wx.ComboBox element will be used.
wiz_combo_choices (list of str) - The list of choices to present to the user. This is only used if
the element_type is set to 'combo'.
wiz_combo_data (list) - The data returned by a call to GetValue(). This is only used if
the element_type is set to 'combo'. If supplied, it should be
the same length at the combo_choices list. If not supplied, the
combo_choices list will be used for the returned data.
wiz_combo_iter (iterator or None) - An iterator method for regenerating the ComboBox choices.
wiz_combo_list_min (int or None) - The minimum length of the Combo_list element.
wiz_filesel_wildcard (str or None) - The file selection dialog wildcard string. For example for
opening PDB files, this could be "PDB files
(*.pdb)|*.pdb;*.PDB".
wiz_dirsel_style (int) - The directory selection dialog style.
wiz_read_only (bool or None) - A flag which if True means that the text of the GUI wizard page
element cannot be edited. If the default of None is given, then
each UI element will decide for itself what to do.
wiz_filesel_preview (bool) - A flag which if True will enable the preview button in the file
selection GUI wizard page element.
can_be_none (bool) - A flag which specifies if the argument is allowed to have the
None value.
can_be_empty (bool) - A flag which if True allows the sequence type object to be empty.
none_elements (bool) - A flag which if True allows the sequence type object to contain
None elements.
|