bec_widgets.utils.widget_state_manager#

Attributes#

Classes#

ExampleApp

WidgetStateManager

Manage saving and loading widget state to/from an INI file.

Module Contents#

class ExampleApp#

Bases: qtpy.QtWidgets.QWidget

check_box#
check_box_skip#
line_edit#
load_button#
panel_checkbox#
panel_edit#
panel_label#
save_button#
side_panel#
spin_box#
state_manager#
class WidgetStateManager(widget, *, serialize_from_root: bool = False, root_id: str | None = None)#

Manage saving and loading widget state to/from an INI file.

Parameters:
  • widget (QWidget) – Root widget whose subtree will be serialized.

  • serialize_from_root (bool) – When True, build group names relative to this root and ignore parents above it. This keeps profiles portable between different host window hierarchies.

  • root_id (str | None) – Optional stable label to use for the root in the settings key path. When omitted and serialize_from_root is True, the class name of widget is used, falling back to its objectName and finally to “root”.

_get_full_widget_name(widget: qtpy.QtWidgets.QWidget) str#

Build a group key for widget.

When serialize_from_root is False (default), this preserves the original behavior and walks all parents up to the top-level widget.

When serialize_from_root is True, the key is built relative to self.widget and parents above the managed root are ignored. The first path segment is either root_id (when provided) or a stable label derived from the root widget (class name, then objectName, then “root”).

Parameters:

widget (QWidget) – The widget to build the key for.

_load_widget_state_qsettings(widget: qtpy.QtWidgets.QWidget, settings: qtpy.QtCore.QSettings, recursive: bool = True)#

Load the state of the widget from QSettings.

Parameters:
  • widget (QWidget) – The widget to load the state for.

  • settings (QSettings) – The QSettings object to load the state from.

  • recursive (bool) – Whether to recursively load the state of child widgets.

_save_widget_state_qsettings(widget: qtpy.QtWidgets.QWidget, settings: qtpy.QtCore.QSettings, recursive: bool = True)#

Save the state of the widget to QSettings.

Parameters:
  • widget (QWidget) – The widget to save the state for.

  • settings (QSettings) – The QSettings object to save the state to.

  • recursive (bool) – Whether to recursively save the state of child widgets.

load_state(filename: str | None = None, settings: qtpy.QtCore.QSettings | None = None)#

Load the state of the widget from an INI file.

Parameters:
  • filename (str) – The filename to load the state from.

  • settings (QSettings) – Optional QSettings object to load the state from.

save_state(filename: str | None = None, settings: qtpy.QtCore.QSettings | None = None)#

Save the state of the widget to an INI file.

Parameters:
  • filename (str) – The filename to save the state to.

  • settings (QSettings) – Optional QSettings object to save the state to.

widget#
PROPERTY_TO_SKIP = ['palette', 'font', 'windowIcon', 'windowIconText', 'locale', 'styleSheet', 'updatesEnabled',...#