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

fix(cleanup): cleanup added to device_input widgets and scan_control

This commit is contained in:
2024-06-21 11:56:01 +02:00
parent 37682e7b8a
commit 8badb6adc1
5 changed files with 53 additions and 2 deletions

View File

@ -17,6 +17,7 @@ class Widgets(str, enum.Enum):
BECDock = "BECDock"
BECDockArea = "BECDockArea"
BECFigure = "BECFigure"
ScanControl = "ScanControl"
SpiralProgressBar = "SpiralProgressBar"
TextBox = "TextBox"
VSCodeEditor = "VSCodeEditor"
@ -1823,6 +1824,24 @@ class Ring(RPCBase):
"""
class ScanControl(RPCBase):
@property
@rpc_call
def config_dict(self) -> "dict":
"""
Get the configuration of the widget.
Returns:
dict: The configuration of the widget.
"""
@rpc_call
def get_all_rpc(self) -> "dict":
"""
Get all registered RPC objects.
"""
class SpiralProgressBar(RPCBase):
@rpc_call
def get_all_rpc(self) -> "dict":

View File

@ -82,3 +82,11 @@ class DeviceComboBox(DeviceInputBase, QComboBox):
if device_obj is None:
raise ValueError(f"Device {device_name} is not found.")
return device_obj
def cleanup(self):
"""Cleanup the widget."""
super().cleanup()
def closeEvent(self, event):
super().cleanup()
QComboBox().closeEvent(event)

View File

@ -118,3 +118,6 @@ class DeviceInputBase(BECConnector):
"""
if device not in self.get_device_list(self.config.device_filter):
raise ValueError(f"Device {device} is not valid.")
def cleanup(self):
super().cleanup()

View File

@ -94,3 +94,11 @@ class DeviceLineEdit(DeviceInputBase, QLineEdit):
if device_obj is None:
raise ValueError(f"Device {device_name} is not found.")
return device_obj
def cleanup(self):
"""Cleanup the widget."""
super().cleanup()
def closeEvent(self, event):
super().cleanup()
QLineEdit().closeEvent(event)

View File

@ -184,8 +184,21 @@ class ScanControl(BECConnector, QWidget):
if callable(scan_function):
scan_function(*args, **kwargs)
def close(self):
super().close()
def cleanup(self):
self.button_stop_scan.cleanup()
if self.arg_box:
for widget in self.arg_box.widgets:
if hasattr(widget, "cleanup"):
widget.cleanup()
for kwarg_box in self.kwarg_boxes:
for widget in kwarg_box.widgets:
if hasattr(widget, "cleanup"):
widget.cleanup()
super().cleanup()
def closeEvent(self, event):
self.cleanup()
QWidget().closeEvent(event)
# Application example