0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

refactor(image): disconnect when layer is removed

This commit is contained in:
2025-06-02 21:06:03 +02:00
committed by Klaus Wakonig
parent 99ecf6a18f
commit 8a299a8268

View File

@ -145,7 +145,7 @@ class Image(ImageBase):
popups=popups, popups=popups,
**kwargs, **kwargs,
) )
self.layer_removed.connect(self._on_layer_removed)
self.scan_id = None self.scan_id = None
# Default Color map to plasma # Default Color map to plasma
@ -479,14 +479,31 @@ class Image(ImageBase):
# Clean up # Clean up
################################################################################ ################################################################################
@SafeSlot(str)
def _on_layer_removed(self, layer_name: str):
"""
Handle the removal of a layer by disconnecting the monitor.
Args:
layer_name(str): The name of the layer that was removed.
"""
if layer_name not in self.subscriptions:
return
config = self.subscriptions[layer_name]
if config.monitor is not None:
self.disconnect_monitor(config.monitor)
config.monitor = None
def cleanup(self): def cleanup(self):
""" """
Disconnect the image update signals and clean up the image. Disconnect the image update signals and clean up the image.
""" """
# Main Image cleanup for layer_name in list(self.subscriptions.keys()):
if self.subscriptions["main"].monitor is not None: config = self.subscriptions[layer_name]
self.disconnect_monitor(self.subscriptions["main"].monitor) if config.monitor is not None:
self.subscriptions["main"].monitor = None self.disconnect_monitor(config.monitor)
del self.subscriptions[layer_name]
self.subscriptions.clear()
# Toolbar cleanup # Toolbar cleanup
self.toolbar.widgets["monitor"].widget.close() self.toolbar.widgets["monitor"].widget.close()