From 47351bbde73e4ed3bb0b30db1cb8736bb486844b Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Wed, 20 May 2026 19:19:17 +0200 Subject: [PATCH] fix(device_inputs): on_device_update additional _destroyed safeguard --- .../device_combobox/device_combobox.py | 18 ++++++++++++------ .../signal_combobox/signal_combobox.py | 5 +++++ 2 files changed, 17 insertions(+), 6 deletions(-) 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 fb09e607..805a8af0 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 @@ -191,6 +191,13 @@ class DeviceComboBox(BECWidget, QComboBox): if self.config.autocomplete: self.autocomplete = True + self._callback_id = self.bec_dispatcher.client.callbacks.register( + EventType.DEVICE_UPDATE, self.on_device_update + ) + self.device_config_update.connect( + self.update_devices_from_filters, Qt.ConnectionType.QueuedConnection + ) + if available_devices is not None: self.set_available_devices(available_devices) @@ -216,12 +223,6 @@ class DeviceComboBox(BECWidget, QComboBox): else: self.setCurrentText("") - self._callback_id = self.bec_dispatcher.client.callbacks.register( - EventType.DEVICE_UPDATE, self.on_device_update - ) - self.device_config_update.connect( - self.update_devices_from_filters, Qt.ConnectionType.QueuedConnection - ) self.currentTextChanged.connect(self.check_validity) self.check_validity(self.currentText()) @@ -257,6 +258,9 @@ class DeviceComboBox(BECWidget, QComboBox): @SafeSlot() def update_devices_from_filters(self): """Refresh the available device list from current device/readout/signal filters.""" + if self._callback_id is None or getattr(self, "_destroyed", False): + return + self.config.device_filter = [entry.value for entry in self.device_filter] self.config.readout_filter = [entry.value for entry in self.readout_filter] self.config.signal_class_filter = self.signal_class_filter @@ -491,6 +495,8 @@ class DeviceComboBox(BECWidget, QComboBox): action: Device update action emitted by BEC. content: Device update payload. Currently unused. """ + if self._callback_id is None or getattr(self, "_destroyed", False): + return if action in ["add", "remove", "reload"]: self.device_config_update.emit() diff --git a/bec_widgets/widgets/control/device_input/signal_combobox/signal_combobox.py b/bec_widgets/widgets/control/device_input/signal_combobox/signal_combobox.py index 94fe3ed9..815f522a 100644 --- a/bec_widgets/widgets/control/device_input/signal_combobox/signal_combobox.py +++ b/bec_widgets/widgets/control/device_input/signal_combobox/signal_combobox.py @@ -211,6 +211,9 @@ class SignalComboBox(BECWidget, QComboBox): content: Optional callback payload from BEC device updates. Currently unused. metadata: Optional callback metadata from BEC device updates. Currently unused. """ + if self._device_update_register is None or getattr(self, "_destroyed", False): + return + self.config.signal_filter = [kind.name for kind in self.signal_filter] if self._signal_class_filter: @@ -253,6 +256,8 @@ class SignalComboBox(BECWidget, QComboBox): def on_device_update(self, action: str, content: dict) -> None: """Refresh filters when BEC reports device configuration changes.""" + if self._device_update_register is None or getattr(self, "_destroyed", False): + return if action in ["add", "remove", "reload"]: self.device_config_update.emit()