The widgets sub-package#
Package with modified widgets required for creating the pydidas graphical user interface.
- class pydidas.widgets.CreateWidgetsMixIn#
Bases:
object
A mixin class to allow easy widget creation in their host classes.
The CreateWidgetsMixIn class includes methods for easy adding of widgets to the layout. The create_something methods from the factories are called and in addition, the layout and positions can be set.
Use the “gridPos” keyword to define the widget position in the parent’s layout.
- add_any_widget(ref: str | None, widget_instance: QWidget, **kwargs: dict)#
Add any existing widget to the layout and apply settings to it.
- Parameters:
ref (Union[str, None]) – The widget reference key.
widget_instance (QWidget) – The widget instance.
**kwargs (dict) – Any attributes supported by the specific QWidget with a setAttribute method are valid kwargs. In addition, ‘layout_kwargs’ is a valid key to pass a dictionary with attributes for the widget’s layout.
- create_any_widget(ref: str | None, widget_class: type, *args: Tuple, **kwargs: Dict)#
Create any widget with any settings and add it to the layout.
Note
Widgets must support generic args and kwargs arguments. This means that generic PyQt widgets cannot be created using this method. They can be added, however, using the
add_any_widget
method.- Parameters:
ref (Union[str, None]) – The reference name in the _widgets dictionary.
widget_class (type) – The class type of the widget.
*args (args) – Any arguments for the widget creation.
**kwargs (dict) – Keyword arguments for the widget creation.
- Raises:
TypeError – If the reference “ref” is not of type string.
- create_button(ref: str | None, text: str, **kwargs: Dict)#
Create a QPushButton and store the widget.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
**kwargs (dict) – Any attributes supported by QPushButton with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the button’s position in its parent’s layout. The ‘fontsize_offset’, ‘bold’, ‘italic’, ‘underline’ keywords can be used to control the font properties. The button’s clicked method can be connected directly, by specifing the slot through the ‘clicked’ kwarg.
- create_check_box(ref: str | None, text, **kwargs: Dict)#
Create a PydidasCheckBox and store the widget.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
text (str) – The CheckBox’s descriptive text.
**kwargs (dict) – Any attributes supported by QCheckBox with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the QProgressBar’s position in its parent’s layout. The ‘fontsize_offset’, ‘bold’, ‘italic’, ‘underline’ can be used to control the font properties or generic Qt properties.
- create_combo_box(ref: str | None, **kwargs: Dict)#
Create a PydidasComboBox and store the widget.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
**kwargs (dict) – Any attributes supported by QComboBox with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the QComboBox’s position in its parent’s layout. The ‘fontsize_offset’, ‘bold’, ‘italic’, ‘underline’ can be used to control the font properties or generic Qt properties.
- create_empty_widget(ref: str | None, **kwargs: Dict)#
Create an ampty QWidget with a agrid layout.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
**kwargs (dict) – Any attributes supported by the generic QWidget with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the QWidget’s position in its parent’s layout.
- create_label(ref: str | None, text: str, **kwargs: dict)#
Create a PydidasLabel and store the widget.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
text (str) – The label’s displayed text.
**kwargs (dict) – Any attributes supported by QLabel with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the label’s position in its parent’s layout. The ‘fontsize_offset’, ‘bold’, ‘italic’, ‘underline’ keywords can be used to control the font properties.
- create_line(ref: str | None, **kwargs: Dict)#
Create a line widget.
This method creates a line widget (implemented as flat QFrame) as separator and adds it to the parent widget.
- Parameters:
**kwargs (dict) – Any additional keyword arguments. All QFrame attributes with setAttribute implementation are valid kwargs.
- create_lineedit(ref: str | None, **kwargs: Dict)#
Create a PydidasLineEdit and store the widget.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
**kwargs (dict) – Any attributes supported by QLineEdit with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the LineEdit’s position in its parent’s layout. The ‘fontsize_offset’, ‘bold’, ‘italic’, ‘underline’ keywords can be used to control the font properties.
- create_progress_bar(ref: str | None, **kwargs: Dict)#
Create a QProgressBar and store the widget.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
**kwargs (dict) – Any attributes supported by QProgressBar with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the QProgressBar’s position in its parent’s layout.
- create_radio_button_group(ref: str | None, entries: List, **kwargs: Dict)#
Create a RadioButtonGroup widget and set its properties.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
text (str) – The CheckBox’s descriptive text.
**kwargs (dict) – Any attributes supported by the generic QWidget with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the RadioButtonGroup’s position in its parent’s layout. The ‘fontsize_offset’, ‘bold’, ‘italic’, ‘underline’ can be used to control the font properties or generic Qt properties. The ‘entries’ keyword takes a list of entries for the buttons and the number of rows and columns can be specified with the ‘rows’ and ‘columns’ keywords, respectively.
- create_spacer(ref: str | None, **kwargs: Dict)#
Create a QSpacerItem and set its properties.
- Parameters:
ref (Union[str, None]) – The widget reference string. If None, an internal reference will be used.
**kwargs (dict) – Any attributes supported by QSpacerItem with a setAttribute method are valid kwargs. In addition, the gridPos key allows to specify the spacer’s position in its parent’s layout.
- create_spin_box(ref: str | None, **kwargs: Dict)#
Create a QSpinBox and store the widget.
- Parameters:
ref (Union[str, None]) – The reference string for storing the widget.
**kwargs (dict) – Any attributes supported by QSpinBox with a setAttribute method are valid kwargs. In addition, the ‘gridPos’ keyword can be used to specify the SpinBox’s position in its parent’s layout. The default range is set to (0, 1), if it is not overridden with the ‘range’ keyword.
- class pydidas.widgets.ScrollArea(parent=None, **kwargs)#
Bases:
QScrollArea
Convenience class to simplify the setup of a QScrollArea.
- Parameters:
parent (QWidget, optional) – The parent widget. The default is None.
**kwargs (dict) – Any additional keyword arguments. All Qt attributes with a setAttribute method are valid keywords.
- force_width_from_size_hint()#
Enforce a fixed width based on the own sizeHint.
- sizeHint()#
Get the size hint.
If a widget has been set, the ScrollArea will use the widget’s sizeHint to determine the required size. If no widget is set, it will default to the QScrollArea sizeHint.
- Returns:
The size hint for the ScrollArea.
- Return type:
QtCore.QSize
- class pydidas.widgets.WidgetWithParameterCollection(**kwargs: dict)#
Bases:
QWidget
,PydidasQsettingsMixin
,CreateWidgetsMixIn
,ParameterCollectionMixIn
,ParameterWidgetsMixIn
A widget which has full access to Pydidas’s ParameterCollection and widget creation methods.
- pydidas.widgets.create_default_grid_layout() QGridLayout #
Create a QGridLayout with default parameters.
The default parameters are
vertical spacing : 5
horizontal spacing : 5
alignment : left | top
- Returns:
layout – The layout.
- Return type:
QGridLayout
- pydidas.widgets.delete_all_items_in_layout(layout: QLayout)#
Recursively delete items in a QLayout.
- Parameters:
layout (QLayout) – The layout to be cleared.
- pydidas.widgets.get_max_pixel_width_of_entries(entries: str | tuple | list) int #
Get the maximum width from a number of entries.
This function calculates the width (in pixels) of a list of given strings.
- Parameters:
entries (Union[str, tuple, list]) – The entries.
- Returns:
width – The maximum width of the entries in pixels.
- Return type:
int
- pydidas.widgets.get_pyqt_icon_from_str(ref_string: str) QIcon #
Get a QIcon from the reference string.
- Four types of strings can be processed:
A reference number of a QStandardIcon, preceded by a ‘qt-std::’.
A reference to an image file in the file system. This must be preceded by ‘path::’.
A reference to an icon in pydidas.core.icons with the filename preceded by a ‘pydidas::’
A reference to a mdi icon with the filename preceded by a ‘mdi::’ Note that this only works for those mdi icons which have been included in pydidas.
- Parameters:
ref_string (str) – The reference string for the icon.
- Raises:
TypeError – If no correct preceding type has been found.
- Returns:
The icon
- Return type:
QtGui.QIcon
- pydidas.widgets.update_param_and_widget_choices(param_widget: QWidget, new_choices: list)#
Update the choices for the given Parameter and in its widget.
This function will update the choices and also set the combo box widget to an allowed choice.
- Parameters:
param_widget (pydidas.widgets.parameter_config.ParameterWidget) – The pydidas ParameterWidget instance.
new_choices (list) – The list of new choices.