UI tools

We group many functions useful for when building GUIS.

copyright:by Hyperion Authors, see AUTHORS for more details.
license:BSD, see LICENSE for more details.
hyperion.tools.ui_tools.add_pint_to_combo(comboBox_units, manual_list=None)

When GUI has a QComboBox with units, this function can convert the display texts of the units to pint units and stores them inside the combobox object. (Run this function once). It is possible to manually specify the list to store, but it’s safer to try automatic conversion.

Parameters:
  • comboBox_units (QComboBox) –
  • manual_list (list of pint units) – OPTIONAL list of pint units corresponding to the display units
hyperion.tools.ui_tools.pint_to_spin_combo(pint_quantity, doubleSpinBox, comboBox_units)

When a GUI has a combination of a Q(Double)SpinBox and a QComboBox that hold the numeric value and the unit respectively, this function can be used to easily put a pint quantity into that combination. It is strongly recommended to use add_pint_to_combo(comboBox_units) before using this function! Complementary function is spin_combo_to_pint_apply_limits()

Parameters:
  • pint_quantity (pint quantity) – the pint quantity to write into the gui objects
  • doubleSpinBox (QDoubleSpinBox (Maybe QSpinBox also works. Not tested)) – the QDoubleSpinBox (or QSpinBox?) that holds the numeric value
  • comboBox_units (QComboBox) – the QComboBox that holds the units
hyperion.tools.ui_tools.spin_combo_to_pint_apply_limits(doubleSpinBox, comboBox_units, pint_lower_limit=None, pint_upper_limit=None)

When a GUI has a combination of a Q(Double)SpinBox and a QComboBox that hold the numeric value and the unit respectively, this function can be used to convert the combined values to a pint quantity. In addition it applies limits if they are specified. Typically you’ll make one function limit_and_apply_X in your gui code, and connect both

>>> doubleSpinBox.valueChanged.connect(limit_and_apply_X)
>>> comboBox_units.currentIndexChanged.connect(limit_and_apply_X)

to this function. Inside limit_and_apply_X() you would use this function spin_combo_to_pint_apply_limits() to apply limits and convert it to a pint quantity

It is strongly recommended to use add_pint_to_combo(comboBox_units) before using this function! Complementary function is pint_to_spin_combo()

Parameters:
  • doubleSpinBox – Q(Double)SpinBox that holds the numeric value
  • comboBox_units – QComboBox that holds the units
  • pint_lower_limit – OPTIONAL pint quantity for the lower limit to apply
  • pint_upper_limit – OPTIONAL pint quantity for the upper limit to apply
Returns:

pint quantity