nspyre.gui.widgets.params
Widget that generates a simple GUI that allows the user to enter a set of parameters.
Module Contents
Classes
Qt widget containing a set of GUI elements for the user to enter experiment parameters into. |
- class nspyre.gui.widgets.params.ParamsWidget(params_config, get_param_value_funs=None)
Qt widget containing a set of GUI elements for the user to enter experiment parameters into.
Typical usage example:
from pyqtgraph import SpinBox from pyqtgraph.Qt import QtWidgets class MyWidget(QtWidgets.QWidget) def __init__(self): super().__init__() self.params_widget = ParamsWidget({ 'start_freq': { 'display_text': 'Start Frequency', 'widget': SpinBox( value=3e9, suffix='Hz', siPrefix=True, bounds=(100e3, 10e9), dec=True, ), }, 'stop_freq': { 'display_text': 'Stop Frequency', 'widget': SpinBox( value=4e9, suffix='Hz', siPrefix=True, bounds=(100e3, 10e9), dec=True, ), }, 'num_points': { 'display_text': 'Number of Scan Points', 'widget': SpinBox(value=100, int=True, bounds=(1, None), dec=True), }, 'iterations': { 'display_text': 'Number of Experiment Repeats', 'widget': SpinBox(value=20, int=True, bounds=(1, None), dec=True), }, 'dataset': { 'display_text': 'Data Set', 'widget': QtWidgets.QLineEdit('odmr'), }, }) ... def doSomething(self): print(f'Scanning from = {self.params_widget.start_freq} Hz to = {self.params_widget.stop_freq} Hz.'
- Parameters:
params_config (Dict) –
Dictionary mapping parameter names to a parameter configuration dictionary, which should contain:
widget
: QWidget instance that represents the parameterdisplay_text
[optional]: parameter text label
get_param_value_funs (Optional[Dict]) –
Dictionary mapping Python classes to a function that takes an instance of that class and returns its value. This can be used to show ParamsWidget how to handle new QWidgets. There is built-in support for pyqtgraph SpinBox, QLineEdit, QComboBox, QCheckBox. E.g.:
def get_lineedit_val(lineedit): return lineedit.text() pw = ParamsWidget({ 'dataset': { 'display_text': 'Data Set', 'widget': QtWidgets.QLineEdit('odmr'), }, ... }, get_param_value_funs={QLineEdit: get_lineedit_val} )
- all_params()
Return the current value of all user parameters as a dictionary.