The widgets.parameter_config sub-package#

Package with individual QWidgets used for displaying and editing pydidas Parameters.

class pydidas.widgets.parameter_config.ParameterEditCanvas(**kwargs: Any)#

Bases: ParameterWidgetsMixIn, EmptyWidget

The ParameterEditCanvas is widget for handling Parameter edit widgets.

Parameters:

**kwargs (Any) – Additional keyword arguments

class pydidas.widgets.parameter_config.ParameterWidget(param: Parameter, parent: QWidget | None = None, **kwargs: Any)#

Bases: EmptyWidget

A composite widget to display and modify a Parameter with name, value and unit.

This widget is a wrapper and includes labels for name and unit and the respective Parameter edit widget which is selected based on the Parameter type and choices.

This is the public widget should be added to the GUI to display and modify Parameters. It includes the following signals:

sig_new_valueQtCore.Signal(str)
Emitted when a new value is entered in the I/O widget. The new value is

emitted as string representation.

sig_value_changedQtCore.Signal()

Emitted when the value in the I/O widget has changed and been accepted.

Parameters:
  • param (pydidas.core.Parameter) – The associated Parameter.

  • **kwargs (Any) –

    Additional keyword arguments. Note that many keywords supported by the generic mixin-class are ignored here because this is a composite widget. Note that the I/O has no width setting here because it is determined automatically based on the remaining space after allocating space for the name and unit fields. Supported keyword arguments are:

    width_textfloat

    The relative width of the text field for the Parameter name. The default is defined in pydidas.core.constants.PARAM_WIDGET_TEXT_WIDTH.

    width_unitfloat

    The relative width of the text field for the Parameter unit. The default is defined in pydidas.core.constants.PARAM_WIDGET_UNIT_WIDTH.

    linebreakbool

    If True, the layout will include a linebreak between the name label and the I/O widget. The default is False.

    font_metric_width_factorint | None

    The width of the widget in multiples of the font metric width. If None, the widget will use the default size policy. The default is pydidas.core.constants.FONT_METRIC_PARAM_EDIT_WIDTH.

    validatorQValidator | None

    A custom validator to be used in the I/O widget, if applicable. The default is None.

property display_value: str#

Get the current display value from the I/O widget.

Returns:

The current display value as string.

Return type:

str

property io_widget: BaseParamIoWidget#

Returns the I/O widget for the Parameter.

set_param_value(value_str_repr: str)#

Update the Parameter value with the entry from the widget.

This method tries to update the Parameter value with the entry from the widget. If unsuccessful, an exception box will be opened and the widget input will be reset to the stored Parameter value.

Parameters:

value_str_repr (str) – The new value as string representation.

set_value(value: Any) None#

Set a new value in the I/O widget and emit the respective signals if required.

Parameters:

value (Any) – The new value to be set.

sizeHint() QSize#

Set a reasonable sizeHint based on the font metrics and configuration.

Returns:

The widget sizeHint

Return type:

QtCore.QSize

update_choices_from_param() None#

Update the choices of the Parameter’s widget from the Parameter.

NOTE: THIS METHOD WILL NOT UPDATE THE PARAMETER VALUE OR THE PARAMETER’S CHOICES. IT ONLY UPDATES THE WIDGET IN PLACE.

update_display_value(value: Any) None#

Update the displayed value in the I/O widget without emitting signals.

Parameters:

value (Any) – The new value to be displayed.

class pydidas.widgets.parameter_config.ParameterWidgetsMixIn#

Bases: object

The ParameterWidgetsMixIn class includes methods which can be added to other classes to add functionality to create Parameter widgets and to have access to convenience functions for settings Parameter values.

create_param_widget(param: Parameter | str, **kwargs: Any) None#

Add a name label and input widget for a specific parameter to the widget.

Parameters:
  • param (Parameter | str) – A Parameter class instance.

  • **kwargs (Any) –

    Optional keyword arguments. Supported keys are:

    gridPostuple, optional

    The grid position in the layout. The default is (-1, 0, 1, 1)

    width_textfloat, optional

    The relative width of the text field for the Parameter name. The default is defined in pydidas.core.constants.PARAM_WIDGET_TEXT_WIDTH.

    width_unitfloat, optional

    The relative width of the text field for the Parameter unit. The default is defined in pydidas.core.constants.PARAM_WIDGET_UNIT_WIDTH.

    linebreakbool, optional

    Keyword to toggle a line break between the text label and the input widget. The default is False.

    halign_ioQtCore.Qt.Alignment, optional

    The horizontal alignment for the input widget. The default is QtCore.Qt.AlignRight.

    halign_textQtCore.Qt.Alignment, optional

    The horizontal alignment for the text (label) widget. The default is QtCore.Qt.AlignRight.

    parent_widgetUnion[QWidget, str, None], optional

    The widget to which the label is added. If a string, this picks up the calling class’s ._widgets dictionary and selects the string key’s value. The default is self.

set_param_and_widget_value(key: str, value: Any, emit_signal: bool = True) None#

Update a parameter value both in the Parameter and the widget.

This method will update the parameter referenced by <key> and update both the Parameter.value and the displayed widget entry.

Parameters:
  • key (str) – The reference key for the Parameter.

  • value (Any) – The new parameter value. This must be of the same type as the Parameter datatype (or supported by a converter).

  • emit_signal (bool) – Flag to toggle emitting a changed signal after updating the value (if the value has changed). The default is True.

Raises:

KeyError – If no parameter or widget has been registered with this key.

set_param_and_widget_value_and_choices(key: str, value: Any, choices: None | Sequence[Any], emit_signal: bool = True) None#

Update a Parameter’s value and choices as well as the associated widget.

Parameters:
  • key (str) – The reference key for the Parameter.

  • value (Any) – The new value for the Parameter.

  • choices (None or Sequence[Any]) – The new list of choices for the Parameter. If None, the choices for the Parameter will be disabled.

  • emit_signal (bool) – Flag to toggle emitting a changed signal after updating the value and choices (if the value has changed). The default is True.

toggle_param_widget_visibility(key: str, visible: bool) None#

Toggle the visibility of widgets referenced with the key.

This method allows showing/hiding the label and input widget for a parameter referenced with <key>.

Parameters:
  • key (str) – The reference key for the Parameter.

  • visible (bool) – The boolean setting for the visibility.

Raises:

KeyError – If no widget has been registered with this key.

update_param_widget_value(key: str, value: Any) None#

Update the value stored in a widget without changing the Parameter and without emitting signals.

Parameters:
  • key (str) – The Parameter reference key.

  • value (Any) – The value. The type depends on the Parameter’s value and will be converted to string for display purposes.