diff --git a/bec_widgets/utils/bec_widget.py b/bec_widgets/utils/bec_widget.py index 0a132ad67..eaa1efaeb 100644 --- a/bec_widgets/utils/bec_widget.py +++ b/bec_widgets/utils/bec_widget.py @@ -40,7 +40,6 @@ def __init__( client=None, config: ConnectionConfig = None, gui_id: str | None = None, - theme_update: bool = False, start_busy: bool = False, **kwargs, ): @@ -53,19 +52,17 @@ def __init__( >>> super().__init__(parent=parent, client=client, config=config, gui_id=gui_id) + Every BECWidget follows application theme changes; override ``apply_theme`` to react. + Args: client(BECClient, optional): The BEC client. config(ConnectionConfig, optional): The connection configuration. gui_id(str, optional): The GUI ID. - theme_update(bool, optional): Whether to subscribe to theme updates. Defaults to False. When set to True, the - widget's apply_theme method will be called when the theme changes. """ super().__init__(client=client, config=config, gui_id=gui_id, **kwargs) if not isinstance(self, QObject): raise RuntimeError(f"{repr(self)} is not a subclass of QWidget") - if theme_update: - logger.debug(f"Subscribing to theme updates for {self.__class__.__name__}") - self._connect_to_theme_change() + self._connect_to_theme_change() # Initialize optional busy loader overlay utility (lazy by default) self._busy_overlay: "BusyLoaderOverlay" | None = None diff --git a/bec_widgets/utils/busy_loader.py b/bec_widgets/utils/busy_loader.py index 9784c6cea..07567074e 100644 --- a/bec_widgets/utils/busy_loader.py +++ b/bec_widgets/utils/busy_loader.py @@ -269,7 +269,7 @@ def install_busy_loader( class DemoWidget(BECWidget, QWidget): # pragma: no cover def __init__(self, parent=None, start_busy: bool = False): - super().__init__(parent=parent, theme_update=True, start_busy=start_busy) + super().__init__(parent=parent, start_busy=start_busy) self._title = QLabel("Demo Content", self) self._title.setAlignment(Qt.AlignCenter) diff --git a/bec_widgets/utils/forms_from_types/forms.py b/bec_widgets/utils/forms_from_types/forms.py index 1f364a018..f8a37df25 100644 --- a/bec_widgets/utils/forms_from_types/forms.py +++ b/bec_widgets/utils/forms_from_types/forms.py @@ -215,7 +215,7 @@ def __init__( self._layout.addWidget(self._validity) self.value_changed.connect(self.validate_form) - self._connect_to_theme_change() + self._connect_pretty_display_theme() @SafeSlot() def clear(self): ... @@ -224,8 +224,8 @@ def set_pretty_display_theme(self, theme: str = "dark"): if self._pretty_display: self.setStyleSheet(styles.pretty_display_theme(theme)) - def _connect_to_theme_change(self): - """Connect to the theme change signal.""" + def _connect_pretty_display_theme(self): + """Connect the pretty-display styling to the theme-updated signal.""" qapp = QApplication.instance() if hasattr(qapp, "theme_signal"): qapp.theme_signal.theme_updated.connect(self.set_pretty_display_theme) # type: ignore diff --git a/bec_widgets/utils/help_inspector/help_inspector.py b/bec_widgets/utils/help_inspector/help_inspector.py index 95a99a2ee..94839da13 100644 --- a/bec_widgets/utils/help_inspector/help_inspector.py +++ b/bec_widgets/utils/help_inspector/help_inspector.py @@ -36,7 +36,7 @@ class HelpInspector(BECWidget, QtWidgets.QWidget): bec_widget_help = QtCore.Signal(str) # Emits md formatted help string from BECWidget class def __init__(self, parent=None, client=None): - super().__init__(client=client, parent=parent, theme_update=True) + super().__init__(client=client, parent=parent) self._app = QtWidgets.QApplication.instance() layout = QtWidgets.QHBoxLayout(self) # type: ignore layout.setContentsMargins(0, 0, 0, 0) diff --git a/bec_widgets/utils/palette_viewer.py b/bec_widgets/utils/palette_viewer.py index 766cf96a8..6398cea95 100644 --- a/bec_widgets/utils/palette_viewer.py +++ b/bec_widgets/utils/palette_viewer.py @@ -25,7 +25,7 @@ class PaletteViewer(BECWidget, QWidget): RPC = False def __init__(self, *args, parent=None, **kwargs): - super().__init__(parent=parent, theme_update=True, **kwargs) + super().__init__(parent=parent, **kwargs) self.setFixedSize(400, 600) layout = QVBoxLayout(self) dark_mode_button = DarkModeButton(self) diff --git a/bec_widgets/widgets/containers/main_window/main_window.py b/bec_widgets/widgets/containers/main_window/main_window.py index 3b99340e7..6753c8458 100644 --- a/bec_widgets/widgets/containers/main_window/main_window.py +++ b/bec_widgets/widgets/containers/main_window/main_window.py @@ -73,7 +73,6 @@ def __init__(self, parent=None, window_title: str = "BEC", **kwargs): # Init ui self._init_ui() - self._connect_to_theme_change() # Connections to BEC Notifications self.bec_dispatcher.connect_slot( diff --git a/bec_widgets/widgets/control/device_input/device_combobox/device_combobox.py b/bec_widgets/widgets/control/device_input/device_combobox/device_combobox.py index c10807a21..cc304a69e 100644 --- a/bec_widgets/widgets/control/device_input/device_combobox/device_combobox.py +++ b/bec_widgets/widgets/control/device_input/device_combobox/device_combobox.py @@ -155,14 +155,7 @@ def __init__( **kwargs, ): self.config = self._process_config(config) - super().__init__( - parent=parent, - client=client, - config=self.config, - gui_id=gui_id, - theme_update=True, - **kwargs, - ) + super().__init__(parent=parent, client=client, config=self.config, gui_id=gui_id, **kwargs) self.get_bec_shortcuts() self._device_filter: list[BECDeviceFilter] = [] diff --git a/bec_widgets/widgets/control/device_manager/components/ophyd_validation/ophyd_validation.py b/bec_widgets/widgets/control/device_manager/components/ophyd_validation/ophyd_validation.py index a2cae41a0..7d788d743 100644 --- a/bec_widgets/widgets/control/device_manager/components/ophyd_validation/ophyd_validation.py +++ b/bec_widgets/widgets/control/device_manager/components/ophyd_validation/ophyd_validation.py @@ -309,7 +309,7 @@ class OphydValidation(BECWidget, QtWidgets.QWidget): multiple_validations_completed = QtCore.Signal(list) def __init__(self, parent=None, client=None, hide_legend: bool = False): - super().__init__(parent=parent, client=client, theme_update=True) + super().__init__(parent=parent, client=client) self._running_ophyd_tests = False self._keep_visible_after_validation: list[str] = [] if not READY_TO_TEST: diff --git a/bec_widgets/widgets/editors/monaco/monaco_widget.py b/bec_widgets/widgets/editors/monaco/monaco_widget.py index 6d70244a7..f2cbe2c5b 100644 --- a/bec_widgets/widgets/editors/monaco/monaco_widget.py +++ b/bec_widgets/widgets/editors/monaco/monaco_widget.py @@ -55,9 +55,7 @@ class MonacoWidget(BECWidget, QWidget): def __init__( self, parent=None, config=None, client=None, gui_id=None, init_lsp: bool = True, **kwargs ): - super().__init__( - parent=parent, client=client, gui_id=gui_id, config=config, theme_update=True, **kwargs - ) + super().__init__(parent=parent, client=client, gui_id=gui_id, config=config, **kwargs) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.editor = qtmonaco.Monaco(self) diff --git a/bec_widgets/widgets/plots/heatmap/heatmap.py b/bec_widgets/widgets/plots/heatmap/heatmap.py index 8fe6e146b..432a89cb0 100644 --- a/bec_widgets/widgets/plots/heatmap/heatmap.py +++ b/bec_widgets/widgets/plots/heatmap/heatmap.py @@ -257,7 +257,7 @@ def __init__(self, parent=None, config: HeatmapConfig | None = None, **kwargs): device_y=None, device_z=None, ) - super().__init__(parent=parent, config=config, theme_update=True, **kwargs) + super().__init__(parent=parent, config=config, **kwargs) self._image_config = config self.scan_id = None self.old_scan_id = None diff --git a/bec_widgets/widgets/plots/plot_base.py b/bec_widgets/widgets/plots/plot_base.py index c6f2c56cb..02bbc7c28 100644 --- a/bec_widgets/widgets/plots/plot_base.py +++ b/bec_widgets/widgets/plots/plot_base.py @@ -191,7 +191,6 @@ def __init__( self._init_ui() - self._connect_to_theme_change() self._update_theme(None) def apply_theme(self, theme: str): diff --git a/bec_widgets/widgets/plots/waveform/waveform.py b/bec_widgets/widgets/plots/waveform/waveform.py index 50fd897c1..afc4398b2 100644 --- a/bec_widgets/widgets/plots/waveform/waveform.py +++ b/bec_widgets/widgets/plots/waveform/waveform.py @@ -208,8 +208,6 @@ def __init__( self.update_with_scan_history(-1) - # for updating a color scheme of curves - self._connect_to_theme_change() # To fix the ViewAll action with clipToView activated self._connect_viewbox_menu_actions() diff --git a/bec_widgets/widgets/progress/bec_progressbar/bec_progressbar.py b/bec_widgets/widgets/progress/bec_progressbar/bec_progressbar.py index 4f75c4d16..ba77877ac 100644 --- a/bec_widgets/widgets/progress/bec_progressbar/bec_progressbar.py +++ b/bec_widgets/widgets/progress/bec_progressbar/bec_progressbar.py @@ -61,9 +61,7 @@ def __init__( enable_dynamic_stylesheet: bool = True, **kwargs, ): - super().__init__( - parent=parent, client=client, gui_id=gui_id, config=config, theme_update=True, **kwargs - ) + super().__init__(parent=parent, client=client, gui_id=gui_id, config=config, **kwargs) accent_colors = get_accent_colors() diff --git a/bec_widgets/widgets/progress/ring_progress_bar/ring_progress_bar.py b/bec_widgets/widgets/progress/ring_progress_bar/ring_progress_bar.py index 3d1849699..7d1cf0187 100644 --- a/bec_widgets/widgets/progress/ring_progress_bar/ring_progress_bar.py +++ b/bec_widgets/widgets/progress/ring_progress_bar/ring_progress_bar.py @@ -397,7 +397,7 @@ class RingProgressBar(BECWidget, QWidget): ] def __init__(self, parent: QWidget | None = None, client=None, **kwargs): - super().__init__(parent=parent, client=client, theme_update=True, **kwargs) + super().__init__(parent=parent, client=client, **kwargs) self.setWindowTitle("Ring Progress Bar") diff --git a/bec_widgets/widgets/services/beamline_states/beamline_state_manager.py b/bec_widgets/widgets/services/beamline_states/beamline_state_manager.py index cf10ca27f..7aebd6a57 100644 --- a/bec_widgets/widgets/services/beamline_states/beamline_state_manager.py +++ b/bec_widgets/widgets/services/beamline_states/beamline_state_manager.py @@ -323,9 +323,7 @@ def __init__( gui_id: str | None = None, **kwargs, ) -> None: - super().__init__( - parent=parent, client=client, config=config, gui_id=gui_id, theme_update=True, **kwargs - ) + super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs) self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) self._state_pills: dict[str, BeamlineStatePill] = {} self._section_headers: dict[str, _BeamlineStateSectionHeader] = {} diff --git a/bec_widgets/widgets/services/beamline_states/beamline_state_pill.py b/bec_widgets/widgets/services/beamline_states/beamline_state_pill.py index 5df19d7c0..679750191 100644 --- a/bec_widgets/widgets/services/beamline_states/beamline_state_pill.py +++ b/bec_widgets/widgets/services/beamline_states/beamline_state_pill.py @@ -85,9 +85,7 @@ def __init__( gui_id: str | None = None, **kwargs, ) -> None: - super().__init__( - parent=parent, client=client, config=config, gui_id=gui_id, theme_update=True, **kwargs - ) + super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs) self.setObjectName("BeamlineStatePill") self.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, True) self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum) diff --git a/bec_widgets/widgets/services/bec_atlas_admin_view/experiment_selection/experiment_mat_card.py b/bec_widgets/widgets/services/bec_atlas_admin_view/experiment_selection/experiment_mat_card.py index df6f04d08..86494ce04 100644 --- a/bec_widgets/widgets/services/bec_atlas_admin_view/experiment_selection/experiment_mat_card.py +++ b/bec_widgets/widgets/services/bec_atlas_admin_view/experiment_selection/experiment_mat_card.py @@ -48,7 +48,7 @@ def __init__( title: str = "Next Experiment", **kwargs, ): - super().__init__(parent=parent, theme_update=True, **kwargs) + super().__init__(parent=parent, **kwargs) layout = QVBoxLayout(self) layout.setContentsMargins(12, 8, 12, 8) diff --git a/bec_widgets/widgets/services/device_browser/device_item/device_config_form.py b/bec_widgets/widgets/services/device_browser/device_item/device_config_form.py index a783d9883..a6585f5f8 100644 --- a/bec_widgets/widgets/services/device_browser/device_item/device_config_form.py +++ b/bec_widgets/widgets/services/device_browser/device_item/device_config_form.py @@ -4,7 +4,6 @@ from bec_lib.atlas_models import Device as DeviceConfigModel from pydantic import BaseModel -from qtpy.QtWidgets import QApplication from bec_widgets.utils.colors import get_theme_name from bec_widgets.utils.forms_from_types import styles @@ -47,7 +46,6 @@ def __init__( pred, _ = self._widget_types["dict"] self._widget_types["dict"] = pred, self._custom_device_config_item self._validity.setVisible(True) - self._connect_to_theme_change() self.populate() def _post_init(self): ... @@ -69,12 +67,6 @@ def get_form_data(self): """Get the entered metadata as a dict.""" return self._md_schema.model_validate(super().get_form_data()).model_dump() - def _connect_to_theme_change(self): - """Connect to the theme change signal.""" - qapp = QApplication.instance() - if hasattr(qapp, "theme_signal"): - qapp.theme_signal.theme_updated.connect(self.set_pretty_display_theme) # type: ignore - def set_schema(self, schema: type[BaseModel]): if not issubclass(schema, DeviceConfigModel): raise TypeError("This class doesn't support changing the schema") diff --git a/bec_widgets/widgets/services/device_browser/device_item/device_signal_display.py b/bec_widgets/widgets/services/device_browser/device_item/device_signal_display.py index 56a92e04b..c16305e0a 100644 --- a/bec_widgets/widgets/services/device_browser/device_item/device_signal_display.py +++ b/bec_widgets/widgets/services/device_browser/device_item/device_signal_display.py @@ -20,19 +20,11 @@ def __init__( device: str = "", config: ConnectionConfig = None, gui_id: str | None = None, - theme_update: bool = False, **kwargs, ): """A widget to display all the signals from a given device, and allow getting a fresh reading.""" - super().__init__( - parent=parent, - client=client, - config=config, - gui_id=gui_id, - theme_update=theme_update, - **kwargs, - ) + super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs) self.get_bec_shortcuts() self._layout = QVBoxLayout() self.setLayout(self._layout) diff --git a/bec_widgets/widgets/services/scan_history_browser/components/scan_history_device_viewer.py b/bec_widgets/widgets/services/scan_history_browser/components/scan_history_device_viewer.py index 659d7c3f5..7bf0cb08b 100644 --- a/bec_widgets/widgets/services/scan_history_browser/components/scan_history_device_viewer.py +++ b/bec_widgets/widgets/services/scan_history_browser/components/scan_history_device_viewer.py @@ -94,17 +94,9 @@ def __init__( client=None, config: ConnectionConfig = None, gui_id: str = None, - theme_update: bool = True, **kwargs, ): - super().__init__( - parent=parent, - client=client, - config=config, - gui_id=gui_id, - theme_update=theme_update, - **kwargs, - ) + super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs) # Current scan history message self.scan_history_msg: ScanHistoryMessage | None = None self._last_device_name: str | None = None diff --git a/bec_widgets/widgets/services/scan_history_browser/components/scan_history_metadata_viewer.py b/bec_widgets/widgets/services/scan_history_browser/components/scan_history_metadata_viewer.py index 5f2455171..14b86470a 100644 --- a/bec_widgets/widgets/services/scan_history_browser/components/scan_history_metadata_viewer.py +++ b/bec_widgets/widgets/services/scan_history_browser/components/scan_history_metadata_viewer.py @@ -26,7 +26,6 @@ def __init__( client=None, config: ConnectionConfig | None = None, gui_id: str | None = None, - theme_update: bool = True, scan_history_msg: ScanHistoryMessage | None = None, ): """ @@ -37,12 +36,9 @@ def __init__( client: The BEC client. config (ConnectionConfig, optional): The connection configuration. gui_id (str, optional): The GUI ID. - theme_update (bool, optional): Whether to subscribe to theme updates. Defaults to True. scan_history_msg (ScanHistoryMessage, optional): The scan history message to display. Defaults """ - super().__init__( - parent=parent, client=client, config=config, gui_id=gui_id, theme_update=theme_update - ) + super().__init__(parent=parent, client=client, config=config, gui_id=gui_id) self._scan_history_msg_labels = { "scan_id": "Scan ID", "dataset_number": "Dataset Nr", diff --git a/bec_widgets/widgets/services/scan_history_browser/components/scan_history_view.py b/bec_widgets/widgets/services/scan_history_browser/components/scan_history_view.py index 330242126..cd8ef9deb 100644 --- a/bec_widgets/widgets/services/scan_history_browser/components/scan_history_view.py +++ b/bec_widgets/widgets/services/scan_history_browser/components/scan_history_view.py @@ -89,17 +89,9 @@ def __init__( config: ConnectionConfig = None, gui_id: str = None, max_length: int = 100, - theme_update: bool = True, **kwargs, ): - super().__init__( - parent=parent, - client=client, - config=config, - gui_id=gui_id, - theme_update=theme_update, - **kwargs, - ) + super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs) self.status_icons = self._create_status_icons() self.column_header = ["Scan Nr", "Scan Name", "Status"] self.scan_history: list[ScanHistoryMessage] = [] # newest at index 0 diff --git a/bec_widgets/widgets/services/scan_history_browser/scan_history_browser.py b/bec_widgets/widgets/services/scan_history_browser/scan_history_browser.py index c60a92584..a282c0c11 100644 --- a/bec_widgets/widgets/services/scan_history_browser/scan_history_browser.py +++ b/bec_widgets/widgets/services/scan_history_browser/scan_history_browser.py @@ -24,7 +24,6 @@ def __init__( client=None, config: ConnectionConfig = None, gui_id: str | None = None, - theme_update: bool = False, **kwargs, ): """ @@ -35,27 +34,19 @@ def __init__( client: The BEC client. config (ConnectionConfig, optional): The connection configuration. gui_id (str, optional): The GUI ID. - theme_update (bool, optional): Whether to subscribe to theme updates. Defaults to False. """ - super().__init__( - parent=parent, - client=client, - config=config, - gui_id=gui_id, - theme_update=theme_update, - **kwargs, - ) + super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs) layout = QtWidgets.QHBoxLayout() self.setLayout(layout) self.scan_history_view = ScanHistoryView( - parent=self, client=client, config=config, gui_id=gui_id, theme_update=theme_update + parent=self, client=client, config=config, gui_id=gui_id ) self.scan_history_metadata_viewer = ScanHistoryMetadataViewer( - parent=self, client=client, config=config, gui_id=gui_id, theme_update=theme_update + parent=self, client=client, config=config, gui_id=gui_id ) self.scan_history_device_viewer = ScanHistoryDeviceViewer( - parent=self, client=client, config=config, gui_id=gui_id, theme_update=theme_update + parent=self, client=client, config=config, gui_id=gui_id ) self.init_layout() diff --git a/bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button.py b/bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button.py index d37ee51ae..006724eb9 100644 --- a/bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button.py +++ b/bec_widgets/widgets/utility/visual/dark_mode_button/dark_mode_button.py @@ -22,7 +22,7 @@ def __init__( toolbar: bool = False, **kwargs, ) -> None: - super().__init__(parent=parent, client=client, gui_id=gui_id, theme_update=True, **kwargs) + super().__init__(parent=parent, client=client, gui_id=gui_id, **kwargs) self.setProperty("skip_settings", True) self._dark_mode_enabled = False diff --git a/tests/unit_tests/test_busy_loader.py b/tests/unit_tests/test_busy_loader.py index 0425c78bb..ae1a4e620 100644 --- a/tests/unit_tests/test_busy_loader.py +++ b/tests/unit_tests/test_busy_loader.py @@ -9,10 +9,8 @@ class _TestBusyWidget(BECWidget, QWidget): - def __init__( - self, parent=None, *, start_busy: bool = False, theme_update: bool = False, **kwargs - ): - super().__init__(parent=parent, theme_update=theme_update, start_busy=start_busy, **kwargs) + def __init__(self, parent=None, *, start_busy: bool = False, **kwargs): + super().__init__(parent=parent, start_busy=start_busy, **kwargs) lay = QVBoxLayout(self) lay.setContentsMargins(0, 0, 0, 0) lay.addWidget(QLabel("content", self))