mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
fix(plots): cleanup policy reviewed for children items
This commit is contained in:
@ -766,8 +766,8 @@ class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
|
||||
|
||||
def clear_all(self):
|
||||
"""Clear all widgets from the figure and reset to default state"""
|
||||
# for widget in self._widgets.values():
|
||||
# widget.cleanup()
|
||||
for widget in self._widgets.values():
|
||||
widget.cleanup()
|
||||
self.clear()
|
||||
self._widgets = defaultdict(dict)
|
||||
self.grid = []
|
||||
|
@ -288,6 +288,10 @@ class BECImageItem(BECConnector, pg.ImageItem):
|
||||
else:
|
||||
raise ValueError("style should be 'simple' or 'full'")
|
||||
|
||||
def cleanup(self):
|
||||
"""Clean up widget."""
|
||||
self.rpc_register.remove_rpc(self)
|
||||
|
||||
|
||||
class BECImageShow(BECPlotBase):
|
||||
USER_ACCESS = [
|
||||
@ -795,13 +799,14 @@ class BECImageShow(BECPlotBase):
|
||||
"""
|
||||
Clean up the widget.
|
||||
"""
|
||||
# for monitor in self._images["device_monitor"]:
|
||||
# self.bec_dispatcher.disconnect_slot(
|
||||
# self.on_image_update, MessageEndpoints.device_monitor(monitor)
|
||||
# )
|
||||
# if self.thread is not None and self.thread.isRunning():
|
||||
# self.thread.quit()
|
||||
# self.thread.wait()
|
||||
for monitor in self._images["device_monitor"]:
|
||||
self.bec_dispatcher.disconnect_slot(
|
||||
self.on_image_update, MessageEndpoints.device_monitor(monitor)
|
||||
)
|
||||
for image in self.images:
|
||||
image.cleanup()
|
||||
|
||||
self.rpc_register.remove_rpc(self)
|
||||
|
||||
|
||||
class ImageProcessor:
|
||||
|
@ -182,14 +182,18 @@ class BECMotorMap(BECPlotBase):
|
||||
"""
|
||||
self.config.scatter_size = scatter_size
|
||||
|
||||
def _connect_motor_to_slots(self):
|
||||
"""Connect motors to slots."""
|
||||
def _disconnect_current_motors(self):
|
||||
"""Disconnect the current motors from the slots."""
|
||||
if self.motor_x is not None and self.motor_y is not None:
|
||||
old_endpoints = [
|
||||
endpoints = [
|
||||
MessageEndpoints.device_readback(self.motor_x),
|
||||
MessageEndpoints.device_readback(self.motor_y),
|
||||
]
|
||||
self.bec_dispatcher.disconnect_slot(self.on_device_readback, old_endpoints)
|
||||
self.bec_dispatcher.disconnect_slot(self.on_device_readback, endpoints)
|
||||
|
||||
def _connect_motor_to_slots(self):
|
||||
"""Connect motors to slots."""
|
||||
self._disconnect_current_motors()
|
||||
|
||||
self.motor_x = self.config.signals.x.name
|
||||
self.motor_y = self.config.signals.y.name
|
||||
@ -418,18 +422,7 @@ class BECMotorMap(BECPlotBase):
|
||||
|
||||
self.update_signal.emit()
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
import sys
|
||||
|
||||
import pyqtgraph as pg
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
glw = pg.GraphicsLayoutWidget()
|
||||
motor_map = BECMotorMap()
|
||||
motor_map.change_motors("samx", "samy")
|
||||
glw.addItem(motor_map)
|
||||
widget = glw
|
||||
widget.show()
|
||||
sys.exit(app.exec_())
|
||||
def cleanup(self):
|
||||
"""Cleanup the widget."""
|
||||
self._disconnect_current_motors()
|
||||
self.rpc_register.remove_rpc(self)
|
||||
|
Reference in New Issue
Block a user