nspyre.gui.widgets.experiment
Module Contents
Classes
Qt widget for automatically generating a GUI for a simple experiment. |
Functions
|
Reads messages sent/received to/from a multiprocessing |
- class nspyre.gui.widgets.experiment.ExperimentWidget(params_config, module, cls, fun_name, constructor_args=None, constructor_kwargs=None, fun_args=None, fun_kwargs=None, title=None, kill=False, layout=None)
Qt widget for automatically generating a GUI for a simple experiment. Parameters can be entered by the user in a
ParamsWidget
. Buttons are generated for the user to run, stop, and kill the experiment process.- Parameters:
params_config (dict) – Dictionary that is passed to the constructor of
ParamsWidget
.module (types.ModuleType) – Python module that contains cls.
cls (str) – Python class name as a string. An instance of this class will be created in a subprocess when the user presses the ‘Run’ button. The
__enter__
and__exit__
methods will be called if implemented. In addition, if the class constructor takes keyword argumentsqueue_to_exp
and/orqueue_from_exp
, multiprocessingQueue
objects will be passed in that can be used to communicate with the GUI.fun_name (str) – Name of function within cls to run. All of the values from the ParamsWidget will be passed as keyword arguments to this function.
constructor_args (Optional[list]) – Args to pass to cls.
constructor_kwargs (Optional[dict]) – Keyword arguments to pass to cls.
fun_args (Optional[list]) – Args to pass to
cls.fun
.fun_kwargs (Optional[dict]) – Keyword arguments to pass to
cls.fun
.title (Optional[str]) – Window title.
kill (bool) – Add a kill button to allow the user to forcibly kill the subprocess running the experiment function.
layout (pyqtgraph.Qt.QtWidgets.QLayout) – Additional Qt layout to place between the parameters and run/stop/kill buttons.
- queue_to_exp: multiprocessing.Queue
multiprocessing Queue to pass to the experiment subprocess and use for sending messages to the subprocess.
- queue_from_exp: multiprocessing.Queue
multiprocessing Queue to pass to the experiment subprocess and use for receiving messages from the subprocess.
- additional_run_kwargs()
Users can override this function to provide additional kwargs to the experiment function. It is called when the user clicks the ‘Run’ button.
- Returns:
A dict containing any additional kwargs to be passed to the experiment function.
- Return type:
Dict
- run()
Run the experiment function in a subprocess.
- stop(log=True)
Request the experiment subprocess to stop by sending the string
stop
toqueue_to_exp
.- Parameters:
log (bool) – if True, log when stop is called but the process isn’t running.
- kill()
Kill the experiment subprocess.
- nspyre.gui.widgets.experiment.experiment_widget_process_queue(msg_queue)
Reads messages sent/received to/from a multiprocessing
Queue
byExperimentWidget
.- Parameters:
msg_queue – multiprocessing Queue object.
- Returns:
The message received from the experiment subprocess.
- Return type:
Optional[str]