Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions bec_widgets/utils/bec_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bec_widgets/utils/busy_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions bec_widgets/utils/forms_from_types/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bec_widgets/utils/help_inspector/help_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bec_widgets/utils/palette_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion bec_widgets/widgets/containers/main_window/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions bec_widgets/widgets/editors/monaco/monaco_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bec_widgets/widgets/plots/heatmap/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion bec_widgets/widgets/plots/plot_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ def __init__(

self._init_ui()

self._connect_to_theme_change()
self._update_theme(None)

def apply_theme(self, theme: str):
Expand Down
2 changes: 0 additions & 2 deletions bec_widgets/widgets/plots/waveform/waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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): ...
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
"""
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(
client=None,
config: ConnectionConfig = None,
gui_id: str | None = None,
theme_update: bool = False,
**kwargs,
):
"""
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions tests/unit_tests/test_busy_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading