Package user_functions :: Module objects :: Class Uf_container
[hide private]
[frames] | no frames]

Class Uf_container

source code


This class is used to process and store all of the user function specific information.

Instance Methods [hide private]
 
__init__(self)
Initialise all the data.
source code
 
__setattr__(self, name, value)
Override the class __setattr__ method.
source code
 
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=u'*', wiz_dirsel_style=536877120, wiz_read_only=None, wiz_filesel_preview=True, can_be_none=False, can_be_empty=False, none_elements=False)
Wrapper method for adding keyword argument information to the container.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  __mod_attr__ = ['title', 'title_short', 'kargs', 'backend', 'd...
Instance Variables [hide private]
executable object backend
The user function back end.
list of Desc_container instances desc
The multi-paragraph description defined via the Desc_container class.
str display
A flag specifying if the user function displays output to STDOUT.
str or None gui_icon
The code for the icon to use in the GUI.
bool gui_sync
A GUI flag which if left on the default of False will cause user functions to be called in asynchronous mode.
list of dict kargs
The list of keyword argument details.
str menu_text
The text to use for the GUI menu entry.
str title
The long title of the user function.
str or None title_short
The optional short title.
bool wizard_apply_button
A flag specifying if the apply button should be shown or not.
int wizard_height_desc
The height in pixels of the description part of the wizard.
str wizard_image
The 200 pixel wide image to use for the user function wizard.
tuple of int or None wizard_size
The size for the GUI user function wizard.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

Initialise all the data.

Overrides: object.__init__

__setattr__(self, name, value)

source code 

Override the class __setattr__ method.

Parameters:
  • name (str) - The name of the attribute to modify.
  • value (anything) - The new value of the attribute.
Overrides: object.__setattr__

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=u'*', wiz_dirsel_style=536877120, 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:

  • dim=()

For a list of basic data types of unknown length, use:

  • dim=(None,)

For a numpy array of 5 elements, use:

  • dim=(5,)

For a numpy 3D matrix, use:

  • dim=(3,3)

For a simple string or list of string, use:

  • dim=[(), (None,)]

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.

Class Variable Details [hide private]

__mod_attr__

Value:
['title',
 'title_short',
 'kargs',
 'backend',
 'display',
 'desc',
 'menu_text',
 'gui_icon',
...

Instance Variable Details [hide private]

backend

The user function back end. This should be a string version with full module path of the function which executes the back end. For example 'pipe_control.pipes.create'. Note, this should be importable as __import__(backend)!
Type:
executable object

display

A flag specifying if the user function displays output to STDOUT. This is used for certain UIs to display that output.
Type:
str

gui_sync

A GUI flag which if left on the default of False will cause user functions to be called in asynchronous mode. If changed to True, then synchronous operation of the user functions will occur.
Type:
bool

wizard_apply_button

A flag specifying if the apply button should be shown or not. This defaults to True.
Type:
bool

wizard_image

The 200 pixel wide image to use for the user function wizard. This should be the path to the bitmap image. This defaults to the relax Ulysses butterfly image.
Type:
str

wizard_size

The size for the GUI user function wizard. This defaults to (700, 500) if not supplied.
Type:
tuple of int or None