0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

fix: BECWidget checks if it is a widget, and implements closeEvent and cleanup

This commit is contained in:
2024-07-16 15:56:39 +02:00
parent 6202d224fe
commit d64758f268
2 changed files with 19 additions and 5 deletions

View File

@ -15,7 +15,6 @@ from qtpy.QtWidgets import QApplication
from bec_widgets.cli.rpc_register import RPCRegister
from bec_widgets.qt_utils.error_popups import ErrorPopupUtility
from bec_widgets.utils.bec_widget import BECWidget
from bec_widgets.utils.yaml_dialog import load_yaml, load_yaml_gui, save_yaml, save_yaml_gui
BECDispatcher = lazy_import_from("bec_widgets.utils.bec_dispatcher", ("BECDispatcher",))

View File

@ -1,8 +1,23 @@
class BECWidget:
"""Base class for all BEC widgets."""
from qtpy.QtWidgets import QWidget
from bec_widgets.utils.bec_connector import BECConnector, ConnectionConfig
class BECWidget(BECConnector):
"""Mixin class for all BEC widgets, to handle cleanup"""
def __init__(self, client=None, config: ConnectionConfig = None, gui_id: str = None):
if not isinstance(self, QWidget):
raise RuntimeError(f"{repr(self)} is not a subclass of QWidget")
super().__init__(client, config, gui_id)
def cleanup(self):
"""Cleanup the widget."""
pass
def closeEvent(self, event):
if hasattr(self, "cleanup"):
self.rpc_register.remove_rpc(self)
try:
self.cleanup()
if hasattr(super(), "closeEvent"):
finally:
super().closeEvent(event)