FSRSModule¶
Apart from the basic FSRSModule class detailed below, there exist some more specialized module classes that are especially interesting for extending pyFSRS:
FSRSModule.FSRSModule¶
-
class
core.FSRSModule.
FSRSModule
[source]¶ Base class for pyFSRS modules - all devices, experiments, and general settings objects have to be derived from this class.
Note
There are a number of specialized subclasses for input and output devices, stages, experimental controls, etc. which define the necessary interface functions and new modules should be derived from those instead.
-
addProperty
(prop)[source]¶ Add a property to the module.
Parameters: prop (ModProp) – Instance of ModProp containing the property to be added. Returns: Id (= index) of added property.
-
canQuit
()[source]¶ This function is called by the pyFSRS app when the user requests to close the program. If this module is ok with leaving, return True, otherwise return False. For instance, when a scan is still running this would be the right time to ask whether the user really wants to quit.
Important
This function should be overwritten by any derived FSRSModule to perform the module specific shutdown steps.
-
category
= None¶ Category of the module; used by the main app for sorting.
-
freezeUI
(freeze=True)[source]¶ Enable of disable the user interface, i.e. all property widgets when freeze is False or True. This function is handy to block the user from messing with parameters during a scan, for example.
-
getPropertyByLabel
(label)[source]¶ Extremely useful function that returns the property whose label matches label. It is sufficient if the property label contains the string label irrespective of upper or lowercase lettering.
-
hasProperty
(label)[source]¶ Returns true if a property width the given label exists. It is sufficient if the property label contains the string label irrespective of upper or lowercase lettering.
-
initialize
(others=[])[source]¶ Startup handler called by the pyFSRS app after all modules have been loaded.
Important
This function should be overwritten by any derived FSRSModule to perform the module specific initialization steps.
Parameters: others (list) – A list of all loaded and available FSRSModules. Use this to a) check how many instances of this module have been loaded already and b) make connections to available hardware, for instance. Returns: Number of modules of the same type that are already in the list.
-
name
= None¶ Name of the module as it appears in the treectrl.
-
parsePropertiesDict
(dct)[source]¶ Create a list of properties directly by parsing a list of python dictionaries defining those properties.
Parameters: dct (list) – Python list of dictionaries defining the properties. Required keys are:
- label: Name of the property.
- type: Type of the property (label, input, choice, button, checkbox, progress, file, toggle, and spin).
- value: Initial value of the property according to its type.
- choices: If type=’choice’, a list of choice strings has to be given.
If type is ‘file’, ‘toggle’, ‘spin’, or ‘input’, also the info-key should to be present:
- file: info = ‘open’ / ‘save’ / ‘path’
- toggle: info = label of control element to be displayed next to the checkbox.
- spin: info = (min, max)-tuple for spin control limits
- input: info = allowed data type ‘float’ / ‘int’ / ‘str’ (or empty)
An event handler may be given by its function name within the same module and passed along with the event-key.
Window handles are not parsed and will be populated automatically by initialize.
-
properties
= None¶ List of property entries, each entry is one line in the treectrl.
-
propindex
= None¶ Dictionary containing a mapping from label to index - created on the go.
-
setProperty
(id, prop)[source]¶ Set / overwrite an existing property of the module.
Parameters: - id (int) – (= index) of added property.
- prop (ModProp) – Instance of ModProp containing the new property.
-
shutdown
()[source]¶ This function is called by the pyFSRS app when the program is about to close. At this point, no veto is possible. Use this function to perform the necessary steps for a safe exit, like close connections to libraries or moving any stages to their initial positions, and so on.
Important
This function should be overwritten by any derived FSRSModule to perform the module specific shutdown steps.
-
type
= None¶ Type of module (‘input’, ‘output’, ‘axis’, ‘experiment’).
-
Utility and helper classes / functions¶
-
core.FSRSModule.
load_from_file
(filepath)[source]¶ Dynamically load a FSRSModule given by filepath and try to return an instance of the module class. The module class has to have the identical name as the file!
If the module provides a howMany function, this function initiates the necessary number of class instances and returns them as a list.
Note
This function is not limited to FSRSModules but can be used to dynamically import any python module.
Parameters: filepath (str) – Filename of the module to load including the file extension (.pyc or .py). Returns: List of module class instances or None if no class could be found.
-
class
core.FSRSModule.
ModProp
[source]¶ Base class for a property element associated with a FSRSModule.
A property has a name, a type, some value, a window handle to its control widget, an event handler and additional infos. Currently supported types are label, input, choice, button, checkbox, progress, file, toggle, and spin. Additional infos are:
- file: info = ‘open’ / ‘save’ / ‘path’
- toggle: info = label of control element to be displayed next to the checkbox.
- spin: info = (min, max)-tuple for spin control limits
- input: info = allowed data type ‘float’ / ‘int’ / ‘str’ (or empty)
-
createHandle
(parent)[source]¶ Create and return the wxWidget corresponding to the property type and attach to parent. parent is the wxTreeCtrl instance that holds the widgets. If an event handler is given, the correct binding is also created.
-
freezeUI
(freeze=True)[source]¶ Enable or disable the user interface, i.e., the associated wxWidget when freeze is False or True.
-
getValue
()[source]¶ Returns the current property value. If a window handle exists, the property value is directly read out from that widget.
-
setChoices
(ch=[])[source]¶ Set list of choices. Accepts a python list as argument. If a widget is attached to the property, the list of choices of the wxChoice box is also updated.
-
setEvent
(evt=None)[source]¶ Set event handler. evt is either a python function or None to disable the event handler.
-
setInfo
(info='')[source]¶ Set the info field according to the type of property. For some types (‘file’ and ‘input’), this variable defines the appearance of the widgets and therefore has to be changed before the window handle is created.
-
class
core.FSRSModule.
NumValidator
(type='float')[source]¶ Custom text control validator to be used internally with text inputs for numerical values. The validator test for conversion of the entered string into the desired numerical or string data type. If it fails, it displays a messge box asking the user to correct his input.
Parameters: type (str) – Type of allowed input (‘float’ = default, ‘int’, ‘str’).