From 23674ccf592a2caa0b57ae64ad1499c270b7d469 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Thu, 17 Jul 2025 12:38:49 +0200 Subject: [PATCH] fix(performance_bundle): fix performance bundle cleanup --- bec_widgets/utils/toolbars/performance.py | 10 ++++++++-- bec_widgets/widgets/plots/image/image_base.py | 1 + bec_widgets/widgets/plots/plot_base.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bec_widgets/utils/toolbars/performance.py b/bec_widgets/utils/toolbars/performance.py index e24ce121..dcec0a9b 100644 --- a/bec_widgets/utils/toolbars/performance.py +++ b/bec_widgets/utils/toolbars/performance.py @@ -2,6 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING +from bec_widgets.utils.error_popups import SafeSlot from bec_widgets.utils.toolbars.actions import MaterialIconAction from bec_widgets.utils.toolbars.bundles import ToolbarBundle from bec_widgets.utils.toolbars.connections import BundleConnection @@ -42,11 +43,15 @@ class PerformanceConnection(BundleConnection): super().__init__() self._connected = False + @SafeSlot(bool) + def set_fps_monitor(self, enabled: bool): + setattr(self.target_widget, "enable_fps_monitor", enabled) + def connect(self): self._connected = True # Connect the action to the target widget's method self.components.get_action_reference("fps_monitor")().action.toggled.connect( - lambda checked: setattr(self.target_widget, "enable_fps_monitor", checked) + self.set_fps_monitor ) def disconnect(self): @@ -54,5 +59,6 @@ class PerformanceConnection(BundleConnection): return # Disconnect the action from the target widget's method self.components.get_action_reference("fps_monitor")().action.toggled.disconnect( - lambda checked: setattr(self.target_widget, "enable_fps_monitor", checked) + self.set_fps_monitor ) + self._connected = False diff --git a/bec_widgets/widgets/plots/image/image_base.py b/bec_widgets/widgets/plots/image/image_base.py index 23d24bed..ca2ef731 100644 --- a/bec_widgets/widgets/plots/image/image_base.py +++ b/bec_widgets/widgets/plots/image/image_base.py @@ -1007,6 +1007,7 @@ class ImageBase(PlotBase): """ Cleanup the widget. """ + self.toolbar.cleanup() # Remove all ROIs rois = self.rois diff --git a/bec_widgets/widgets/plots/plot_base.py b/bec_widgets/widgets/plots/plot_base.py index 42acd12a..d03f55d0 100644 --- a/bec_widgets/widgets/plots/plot_base.py +++ b/bec_widgets/widgets/plots/plot_base.py @@ -1040,6 +1040,7 @@ class PlotBase(BECWidget, QWidget): self.crosshair.update_markers() def cleanup(self): + self.toolbar.cleanup() self.unhook_crosshair() self.unhook_fps_monitor(delete_label=True) self.tick_item.cleanup() @@ -1049,7 +1050,6 @@ class PlotBase(BECWidget, QWidget): self.axis_settings_dialog = None self.cleanup_pyqtgraph() self.round_plot_widget.close() - self.toolbar.cleanup() super().cleanup() def cleanup_pyqtgraph(self, item: pg.PlotItem | None = None):