Widget Utility Functions
hardware_control.gui.widgets.hc_widgets module
Qt widgets that are well integrate with Hardware Control.
Here you will find versions of Qt widgets, such as QLabel, QPushButton, etc. that can be connected to a certain instrument parameter and automatically be updated.
This module also provides some more additional widgets that do not have equivalent ones in Qt directly.
- class hardware_control.gui.widgets.hc_widgets.HCComboBox(app, instrument: str, parameter: str, label: str, items: list, label_align: str = 'left', lookuptable: dict | None = None, upper: bool = False, auto_update=True)
Bases:
HCMixin,QComboBoxA simple control widget with a label (QLabel) and an input box (QComboBox).
- Parameters:
items (list) – List of options to be place in the HCComboBox
lookuptable (dict) – An optional table that can be used to convert the items in the HCComboBox into values to be sent to the instrument
- value_change() None
- widget_update(value) None
- class hardware_control.gui.widgets.hc_widgets.HCDoubleSpinBox(app, instrument: str, parameter: str, label: str, label_align='left', auto_update=True)
Bases:
HCMixin,QDoubleSpinBoxA simple control widget with a label (QLabel) and an input box (QDoubleSpinBox).
- value_change() None
- widget_update(value) None
- class hardware_control.gui.widgets.hc_widgets.HCDoubleSpinComboBox(app, instrument: str, parameter: str, label: str, units: dict[str, float], label_align: str = 'left', auto_update=True)
Bases:
HCMixinA simple control widget with a label (QLabel) and two input boxes (QSpinBox, QComboBox).
- Parameters:
units (dict) – A dictionary with keys that are units (str) and values that are the corresponding scale factors (float) to convert to the fundamental unit
- value_change() None
- widget_update(value) None
- class hardware_control.gui.widgets.hc_widgets.HCFixedLabel(app, instrument: str, parameter: str, init_label: str = '', unit: str = '', use_prefix: bool = True, color: str = None, fontsize: int = 18, bold: bool = False, label_align: str = 'center', auto_update=True)
Bases:
HCMixin,QLabelA simple control widget with a label (QLabel)that fixes its width to the given initial string.
- setText(self, a0: str | None)
- widget_update(value) None
- class hardware_control.gui.widgets.hc_widgets.HCGridLayout(HCwidgets: list, offset: int = 0, columns: int = 1)
Bases:
QGridLayoutPlaces HCwidgets into a Gridlayout.
This is a 2*columns (columns=1 by default) column grid with the label of the HCWidget in the left column and the widget itself in the right column.
A special case is a HCDoubleSpinComboBox where an additional 3rd column is created.
- class hardware_control.gui.widgets.hc_widgets.HCHeader(icon_name)
Bases:
QLabelDisplay an image as a header.
- class hardware_control.gui.widgets.hc_widgets.HCLabel(app, instrument: str, parameter: str, label: str, unit: str = '', use_prefix: bool = True, label_align: str = 'left', min_width: int = 10, auto_update=True)
Bases:
HCMixin,QLabelA simple indicator widget for a label (QLabel) and a value (QLabel).
- setText(self, a0: str | None)
- widget_update(value) None
- class hardware_control.gui.widgets.hc_widgets.HCLineEdit(app, instrument: str, parameter: str, label: str, label_align: str = 'left', return_set_value: bool = False, default_txt: str = '----', validator=<class 'PyQt6.QtGui.QDoubleValidator'>, auto_update=True)
Bases:
HCMixin,QLineEditA simple control widget with a label (QLabel) and an input box (QLineEdit).
- Parameters:
return_set_value – If True, retain the input in the HCLinEdit; if False, periodiccaly update the input with the parameter readout
validator – A QValidator object to be used to validate the lineedit input
- value_change() None
- widget_update(value) None
- class hardware_control.gui.widgets.hc_widgets.HCMixin(**kwargs)
Bases:
objectConnect a Qt element to a setting or command in the app.
This mixin sets the app, instrument, and parameter values; connects to the app; and defines an hc_update function. The hc_update function still needs to be overwritten to connect to the actual widget since there might be custom code needed to do this.
HCwidgets generally inherit from this class.
Any parameter listed here will be automatically added to the app’s auto_update list
- Parameters:
app – The main app
instrument – The name of the instrument
parameter – The name of the parameter
auto_update – Should the variable be added to the auto_update function. Set this to False in case you want to run this on a different schedule. In this case you need to create your own timer though and call the appropiate update function.
- add_widget_hook(function: Callable[[Any], Any])
Add a hook function to be called when a value in a widgets gets updated from app._data.
- hc_update()
Get the HC widget parameter value from the instrument and apply hooks to that value.
When this function finishes running it calls the widget_update function which should be written for each HC widget. If this function has not been defined the default widget_update function raises an AttributeError.
- widget_update(value)
- class hardware_control.gui.widgets.hc_widgets.HCOnOffButton(app, instrument: str, parameter: str, label: str = '', label_align: str = 'left', show_text: bool = True, show_icon: bool = False, text_checked: str = 'On', text_unchecked: str = 'Off', icon_checked: str = 'button-power-on.svg', icon_unchecked: str = 'button-power-off.svg', show_set_text: bool = False, auto_update=True)
Bases:
HCMixin,QPushButtonA simple control widget with a push-button (QPushButton) with graphical indicators for on/off state.
One also has the option of (only or additionally) introducing text to indicate on-off status.
- Parameters:
show_text (bool) – Option to show a text indicator of the on-off status
show_icon (bool) – Option to show an icon indicator of the on-off status
text_checked (str) – Text to show when instrument parameter is ‘On’
text_unchecked (str) – Text to show when instrument parameter is ‘Off’
icon_checked (str) – Icon to show when instrument parameter is ‘On’
icon_unchecked (str) – Icon to show when instrument parameter is ‘Off’
- is_true(value: bool | str) bool
Handle multiple versions (of different data type and case) of the option ‘True’.
- set_btn_state(value)
Change the icon and/or text display.
- value_change() None
Change value to opposite of current value.
- widget_update(value)
- class hardware_control.gui.widgets.hc_widgets.HCOnOffIndicator(app, instrument: str, parameter: str, label: str = '', label_align: str = 'left', show_text: bool = False, show_icon: bool = False, text_checked: str = 'On', text_unchecked: str = 'Off', icon_checked: str = 'on-off-indicator-on.svg', icon_unchecked: str = 'on-off-indicator-off.svg', tooltip: str = '', auto_update=True)
Bases:
HCMixin,QLabelA simple control widget with a label (QLabel) image or text that indicates on/off state.
- Parameters:
show_text (bool) – Option to show a text indicator of the on-off status; if show_text is True, the show_icon option will be ignored
show_icon (bool) – Option to show an icon indicator of the on-off status
text_checked (str) – Text to show when instrument parameter is ‘On’
text_unchecked (str) – Text to show when instrument parameter is ‘Off’
icon_checked (str) – Icon to show when instrument parameter is ‘On’
icon_unchecked (str) – Icon to show when instrument parameter is ‘Off’
tooltip (str) – Optional text to be displayed when mousing over the indicator
- is_true(value: bool | str) bool
Handle multiple versions (of different data type and case) of the option ‘True’.
- set_state(value)
Change the icon and/or text display.
- sizeHint(self) QSize
- widget_update(value)
- class hardware_control.gui.widgets.hc_widgets.HCPushButton(app, instrument: str, parameter: str, label: str = '', label_align: str = 'left')
Bases:
HCMixin,QPushButtonA simple control widget with a push-button (QPushButton).
- value_change() None
- widget_update(value) None
- class hardware_control.gui.widgets.hc_widgets.HCSpinBox(app, instrument: str, parameter: str, label: str, label_align: str = 'left', auto_update=True)
Bases:
HCMixin,QSpinBoxA simple control widget with a label (QLabel) and an input box (QSpinBox).
- value_change() None
- widget_update(value) None
- hardware_control.gui.widgets.hc_widgets.convert_prefix(value: str, decimals: int = 3) list[str]
Handle units prefix conversions.
- hardware_control.gui.widgets.hc_widgets.icon_filename(name: str)
Get the icon filename from the installed package location.
- hardware_control.gui.widgets.hc_widgets.load_icon(name: str) QPixmap
Load an icon from the installed package location as a QIcon.
- hardware_control.gui.widgets.hc_widgets.load_pixmap(name: str) QPixmap
Load an icon from the installed package location as a QPixmap.