The widgets.framework sub-package#
Package with modified widgets required for creating the pydidas graphical user interface.
- class pydidas.widgets.framework.BaseFrame(**kwargs: dict)#
Bases:
QWidget
,ParameterCollectionMixIn
,PydidasQsettingsMixin
,CreateWidgetsMixIn
,ParameterWidgetsMixIn
The BaseFrame is a subclassed QWidget and the base class for all Frames in pydidas.
By default, a QGridLayout is applied with an alignment of left/top.
- Parameters:
**kwargs (dict) – Any additional keyword arguments which might be used by subclasses.
**init_layout (bool, optional) – Flag to initialize the frame layout with a QtWidgets.QGridLayout and left / top alignment. If False, no layout will be initialized and the subclass is responsible for setting up the layout. The default is True.
- build_frame()#
Build all widgets of the frame.
- closeEvent(event: QEvent)#
Reimplement the closeEvent to emit a signal about the closing.
- Parameters:
event (QtCore.QEvent) – The event which triggered the closeEvent.
- connect_signals()#
Connect all the required signals for the frame.
- export_state()#
Export the state of the Frame for saving.
- Returns:
frame_index (int) – The frame index which can be used as key for referencing the state.
information (dict) – A dictionary with all the information required to export the frame’s state.
- finalize_ui()#
finalize the UI initialization.
- frame_activated(index: int)#
Received signal that frame has been activated.
This method is called when this frame becomes activated by the central widget. By default, this method will perform no actions. If specific frames require any actions, they will need to overwrite this method.
- Parameters:
index (int) – The index of the activated frame.
- restore_state(state: dict)#
Restore the frame’s state from stored information.
The default implementation in the BaseFrame will update all Parameters (and associated widgets) and restore the visibility of all widgets. If the frame has not yet been built, the state information is only stored internally and not yet applied. It will be applied at the next frame activation.
- Parameters:
state (dict) – A dictionary with ‘params’ and ‘visibility’ keys and the respective information for both.
- set_status(text: str)#
Emit a status message to the main window.
- Parameters:
text (str) – The status message to be emitted.
- class pydidas.widgets.framework.BaseFrameWithApp(parent=None, **kwargs)#
Bases:
BaseFrame
The BaseFrameWithApp is a subclassed BaseFrame with an associated pydidas App.
It should be used as the base class for all Frames with an associated Application in the pydidas suite.
It adds (internal) methods required for running a pydidas app to the BaseFrame.
- Parameters:
parent (Union[QWidget, None], optional) – The parent widget. The default is None.
**kwargs (dict) – Any additional keyword arguments.
**init_layout (bool) – Flag to initialize the frame layout with a QtWidgets.QVBoxLayout. If False, no layout will be initialized and the subclass is responsible for setting up the layout. The default is True.
- export_state() Tuple[int, dict] #
Export the state of the Frame for saving.
This method adds an export for the frame’s app.
- Returns:
frame_index (int) – The frame index which can be used as key for referencing the state.
information (dict) – A dictionary with all the information required to export the frame’s state.
- restore_state(state: dict)#
Restore the frame’s state from stored information.
The BaseFrameWithApp implementation will update the associated App and then call the BaseFrame’s method.
- Parameters:
state (dict) – A dictionary with ‘params’, ‘app’ and ‘visibility’ keys and the respective information for all.
- class pydidas.widgets.framework.FontScalingToolbar(*args)#
Bases:
QToolBar
A subclassed toolbar with automatic scaling based on the font metrics.
- process_new_font_family()#
Redraw the toolbar with the new font family.
- process_new_font_metrics(font_width: float, font_height: float)#
Process the new font height and adjust the ToolBar accordingly.
- Parameters:
font_width (float) – The font width in pixels.
font_height (float) – The font height in pixels.
- class pydidas.widgets.framework.PydidasFrameStack(*args: Any, **kwargs: Any)#
Bases:
SingletonObject
,QStackedWidget
A QStackedWidget with references to all the possible top-level widgets.
Widgets are responsible for registering themselves with this class to allow a later reference. For the pydidas main application, the main window takes care of registration.
- Parameters:
parent (QWidget, optional) – The parent widget. The default is None.
- frames#
A list of all the registered widgets.
- Type:
list
- frame_indices#
A dictionary with (widget_name: index) entries to reference widgets with their names.
- Type:
dict
- activate_widget_by_name(ref_name: str)#
Set the widget referenced by name to the active widget.
- Parameters:
ref_name (str) – The reference name of the widget.
- Raises:
KeyError – If no widget with the name has been registered.
- property active_widget_name: str#
Return the name of the active widget.
- Returns:
The name of the active widget.
- Return type:
str
- addWidget(widget: QWidget | None = None, name: str = None)#
Overload the QStackedWidget.addWidget method to deactivate it.
Widgets should be added through the register_widget method, which also demands a reference name.
- Raises:
NotImplementedError – Reference to the register_widget method is given.
- change_reference_name(new_name: str, widget: BaseFrame)#
Change the reference name for a widget.
This method changes the internal reference name for the widget and stores the supplied new_name.
- Parameters:
new_name (str) – The new reference name.
widget (BaseFrame) – The widget of which the reference name shall be changed.
- Raises:
KeyError – If the widget is not registered at all.
- enterEvent(event: QEvent)#
Send a signal that the mouse entered the central widget.
- Parameters:
event (QtCore.QEvent) – The calling event.
- property frame_toolbar_entries: list[str]#
Get all menu entries based on the stored information in the Frames.
- Returns:
The list of the menu entries for all registered Frames.
- Return type:
list
- property frame_toolbar_metadata: dict#
Get all the metadata to create the frame toolbar menu from the frames.
- Returns:
A dictionary with all the required information to create the toolbar menu.
- Return type:
dict
- get_all_widget_names() list[str] #
Get the names of all registered widgets.
- Returns:
The names of all registered widgets as a list.
- Return type:
list
- get_name_from_index(index: int) str #
Get the widget reference name associated with the indexed widget.
This method searches the dictionary of (name: index) entries and returns the name key for the index value.
- Parameters:
index (int) – The widget index.
- Returns:
The reference name.
- Return type:
str
- get_widget_by_name(ref_name: str) BaseFrame #
Get a widget from its reference name.
This method will return the widget registered with the reference name, if it exists.
- Parameters:
ref_name (str) – The reference name of the widget.
- Raises:
KeyError – If no widget with the reference name has been registered.
- Returns:
widget – The widget referenced by the name.
- Return type:
- initialize(*args: Any, **kwargs: Any) None #
Initialize the singleton object.
This method should be overridden by subclasses which have additional mixin-classes to perform any necessary initialization. Using the initialize method instead of __init__ is required to avoid multiple initializations through the SingletonObject.
- Parameters:
args (Any) – Positional arguments for the initialization.
kwargs (Any) – Keyword arguments for the initialization.
- is_registered(widget: BaseFrame) bool #
Check if a widget is already registered.
This method checks if a widget is already registered and returns the bool result.
- Parameters:
widget (QWidget) – The widget which might already be registered.
- Returns:
This will be True if the widget has been registered, and False if not.
- Return type:
bool
- register_frame(frame: BaseFrame)#
Register a Frame with the stacked widget.
This method will register a Frame and hold a reference to the frame index by the Frame’s menu_entry.
- Parameters:
frame (pydidas.widgets.framework.BaseFrame) – The BaseFrame to be registered.
- Raises:
TypeError – If a widget is not of the type pydidas.widgets.framework.BaseFrame
KeyError – When a widget with the same name has already been registered to prevent duplicate entries in the index reference.
- removeWidget(widget: BaseFrame)#
Remove a widget from the QStackdWidget.
This overloaded method removes a widget from the QStackedWidget and also dereferences it from the metadata.
- Parameters:
widget (BaseFrame) – The widget to be removed from the QStackedWidget.
- Raises:
KeyError – If the widget is not registered.
- remove_widget_by_name(ref_name: str)#
Remove a widget by its reference name.
This method finds the widget associated with the reference name and deletes it from the QStackedWidget. Note: This does not delete the widget itself, only the reference in the QStackedWidget.
- Parameters:
ref_name (str) – The reference name of the widget
- Raises:
KeyError – If the reference name has not been used for registering a widget.
- reset()#
Reset the PydidasFrameStack and delete all widgets from itself.
- class pydidas.widgets.framework.PydidasStatusWidget(*args: Any, **kwargs: Any)#
Bases:
SingletonObject
,QDockWidget
The PydidasStatusWidget is used for managing global status messages.
- add_status(text: str)#
Add a status message to the PydidasStatusWidget.
This method will add a status message to the Info/Log widget together with a timestamp.
- Parameters:
text (str) – The text to add.
- initialize(*args: Any, **kwargs: Any) None #
Initialize the singleton object.
This method should be overridden by subclasses which have additional mixin-classes to perform any necessary initialization. Using the initialize method instead of __init__ is required to avoid multiple initializations through the SingletonObject.
- Parameters:
args (Any) – Positional arguments for the initialization.
kwargs (Any) – Keyword arguments for the initialization.
- sizeHint() QSize #
Give a sizeHint which corresponds to a wide and short field.
- Returns:
The desired size.
- Return type:
QtCore.QSize
- text() str #
Get the text of the widget.
- Returns:
The text of the widget.
- Return type:
str
- class pydidas.widgets.framework.PydidasWindow(**kwargs: dict)#
Bases:
BaseFrame
,PydidasWindowMixIn
The PydidasWindow is a standalone BaseFrame with a persistent geometry.
- open_help()#
Open the help in a browser.
This slot will check whether a helpfile exists for the current frame and open the respective helpfile if it exits or the main documentation if it does not.
- show()#
Overload the generic show method.
This makes sure that any show calls will have a fully built window.