mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
refactor: cleanup MR
This commit is contained in:
@ -9,11 +9,9 @@ import os
|
||||
import select
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from bec_lib.endpoints import MessageEndpoints
|
||||
from bec_lib.logger import bec_logger
|
||||
from bec_lib.utils.import_utils import lazy_import, lazy_import_from
|
||||
from rich.console import Console
|
||||
@ -30,7 +28,6 @@ if TYPE_CHECKING:
|
||||
from bec_lib.redis_connector import StreamMessage
|
||||
else:
|
||||
messages = lazy_import("bec_lib.messages")
|
||||
# from bec_lib.connector import MessageObject
|
||||
MessageObject = lazy_import_from("bec_lib.connector", ("MessageObject",))
|
||||
StreamMessage = lazy_import_from("bec_lib.redis_connector", ("StreamMessage",))
|
||||
|
||||
@ -74,7 +71,7 @@ def _get_output(process, logger) -> None:
|
||||
|
||||
def _start_plot_process(
|
||||
gui_id: str, gui_class: type, gui_class_id: str, config: dict | str, logger=None
|
||||
) -> None:
|
||||
) -> tuple[subprocess.Popen[str], threading.Thread | None]:
|
||||
"""
|
||||
Start the plot in a new process.
|
||||
|
||||
@ -207,7 +204,7 @@ class BECDockArea(client.BECDockArea):
|
||||
class BECGuiClient(RPCBase):
|
||||
"""BEC GUI client class. Container for GUI applications within Python."""
|
||||
|
||||
_top_level = {}
|
||||
_top_level: dict[str, BECDockArea] = {}
|
||||
|
||||
def __init__(self, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
@ -223,7 +220,7 @@ class BECGuiClient(RPCBase):
|
||||
|
||||
@property
|
||||
def windows(self) -> dict:
|
||||
"""Dictionary with dock ares in the GUI."""
|
||||
"""Dictionary with dock areas in the GUI."""
|
||||
return self._top_level
|
||||
|
||||
@property
|
||||
@ -457,7 +454,7 @@ class BECGuiClient(RPCBase):
|
||||
self._process = None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
from bec_lib.client import BECClient
|
||||
from bec_lib.service_config import ServiceConfig
|
||||
|
||||
|
@ -8,7 +8,7 @@ from weakref import WeakValueDictionary
|
||||
from bec_lib.logger import bec_logger
|
||||
from qtpy.QtCore import QObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from bec_widgets.utils.bec_connector import BECConnector
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
from bec_widgets.widgets.containers.dock.dock import BECDock
|
||||
@ -73,20 +73,6 @@ class RPCRegister:
|
||||
rpc_object = self._rpc_register.get(gui_id, None)
|
||||
return rpc_object
|
||||
|
||||
def get_rpc_by_name(self, name: str) -> QObject | None:
|
||||
"""
|
||||
Get an RPC object by its name.
|
||||
|
||||
Args:
|
||||
name(str): The name of the RPC object to be retrieved.
|
||||
|
||||
Returns:
|
||||
QObject | None: The RPC object with the given name.
|
||||
"""
|
||||
rpc_object = [rpc for rpc in self._rpc_register if rpc._name == name]
|
||||
rpc_object = rpc_object[0] if len(rpc_object) > 0 else None
|
||||
return rpc_object
|
||||
|
||||
def list_all_connections(self) -> dict:
|
||||
"""
|
||||
List all the registered RPC objects.
|
||||
|
@ -13,7 +13,7 @@ class RPCWidgetHandler:
|
||||
self._widget_classes = None
|
||||
|
||||
@property
|
||||
def widget_classes(self) -> dict[str, Any]:
|
||||
def widget_classes(self) -> dict[str, type[BECWidget]]:
|
||||
"""
|
||||
Get the available widget classes.
|
||||
|
||||
@ -50,9 +50,7 @@ class RPCWidgetHandler:
|
||||
Returns:
|
||||
widget(BECWidget): The created widget.
|
||||
"""
|
||||
if self._widget_classes is None:
|
||||
self.update_available_widgets()
|
||||
widget_class = self._widget_classes.get(widget_type) # type: ignore
|
||||
widget_class = self.widget_classes.get(widget_type) # type: ignore
|
||||
if widget_class:
|
||||
return widget_class(name=name, **kwargs)
|
||||
raise ValueError(f"Unknown widget type: {widget_type}")
|
||||
|
@ -11,7 +11,7 @@ from bec_widgets.utils.bec_connector import BECConnector, ConnectionConfig
|
||||
from bec_widgets.utils.colors import set_theme
|
||||
from bec_widgets.utils.container_utils import WidgetContainerUtils
|
||||
|
||||
if TYPE_CHECKING:
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from bec_widgets.widgets.containers.dock import BECDock
|
||||
|
||||
logger = bec_logger.logger
|
||||
@ -55,13 +55,7 @@ class BECWidget(BECConnector):
|
||||
"""
|
||||
if not isinstance(self, QWidget):
|
||||
raise RuntimeError(f"{repr(self)} is not a subclass of QWidget")
|
||||
# Create a default name if None is provided
|
||||
if name is None:
|
||||
name = "bec_widget_init_without_name"
|
||||
# name = self.__class__.__name__
|
||||
# Check for invalid chars in the name
|
||||
if not WidgetContainerUtils.has_name_valid_chars(name):
|
||||
raise ValueError(f"Name {name} contains invalid characters.")
|
||||
|
||||
super().__init__(client=client, config=config, gui_id=gui_id, name=name)
|
||||
self._parent_dock = parent_dock
|
||||
app = QApplication.instance()
|
||||
@ -104,8 +98,7 @@ class BECWidget(BECConnector):
|
||||
|
||||
def cleanup(self):
|
||||
"""Cleanup the widget."""
|
||||
# needed here instead of closeEvent, to be checked why
|
||||
# However, all widgets need to call super().cleanup() in their cleanup method
|
||||
# All widgets need to call super().cleanup() in their cleanup method
|
||||
self.rpc_register.remove_rpc(self)
|
||||
|
||||
def closeEvent(self, event):
|
||||
|
@ -434,7 +434,7 @@ class BECDock(BECWidget, Dock):
|
||||
super().close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
import sys
|
||||
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
@ -71,5 +71,4 @@ class BECMainWindow(BECWidget, QMainWindow):
|
||||
return dock_area
|
||||
|
||||
def cleanup(self):
|
||||
# TODO
|
||||
super().close()
|
||||
|
@ -18,7 +18,6 @@ def connected_figure(connected_client_gui_obj):
|
||||
|
||||
def test_rpc_waveform1d_custom_curve(connected_figure):
|
||||
fig = connected_figure
|
||||
# fig = BECFigure(connected_client_figure)
|
||||
|
||||
ax = fig.plot()
|
||||
curve = ax.plot(x=[1, 2, 3], y=[1, 2, 3])
|
||||
@ -32,7 +31,6 @@ def test_rpc_waveform1d_custom_curve(connected_figure):
|
||||
|
||||
def test_rpc_plotting_shortcuts_init_configs(connected_figure, qtbot):
|
||||
fig = connected_figure
|
||||
# fig = BECFigure(connected_client_figure)
|
||||
|
||||
plt = fig.plot(x_name="samx", y_name="bpm4i")
|
||||
im = fig.image("eiger")
|
||||
@ -90,7 +88,6 @@ def test_rpc_plotting_shortcuts_init_configs(connected_figure, qtbot):
|
||||
|
||||
|
||||
def test_rpc_waveform_scan(qtbot, connected_figure, bec_client_lib):
|
||||
# fig = BECFigure(connected_client_figure)
|
||||
fig = connected_figure
|
||||
# add 3 different curves to track
|
||||
plt = fig.plot(x_name="samx", y_name="bpm4i")
|
||||
@ -126,7 +123,6 @@ def test_rpc_waveform_scan(qtbot, connected_figure, bec_client_lib):
|
||||
|
||||
|
||||
def test_rpc_image(connected_figure, bec_client_lib):
|
||||
# fig = BECFigure(connected_client_figure)
|
||||
fig = connected_figure
|
||||
|
||||
im = fig.image("eiger")
|
||||
@ -148,7 +144,6 @@ def test_rpc_image(connected_figure, bec_client_lib):
|
||||
|
||||
|
||||
def test_rpc_motor_map(connected_figure, bec_client_lib):
|
||||
# fig = BECFigure(connected_client_figure)
|
||||
fig = connected_figure
|
||||
|
||||
motor_map = fig.motor_map("samx", "samy")
|
||||
@ -180,7 +175,6 @@ def test_rpc_motor_map(connected_figure, bec_client_lib):
|
||||
def test_dap_rpc(connected_figure, bec_client_lib, qtbot):
|
||||
|
||||
fig = connected_figure
|
||||
# fig = BECFigure(connected_client_figure)
|
||||
plt = fig.plot(x_name="samx", y_name="bpm4i", dap="GaussianModel")
|
||||
|
||||
client = bec_client_lib
|
||||
@ -219,7 +213,6 @@ def test_dap_rpc(connected_figure, bec_client_lib, qtbot):
|
||||
|
||||
|
||||
def test_removing_subplots(connected_figure, bec_client_lib):
|
||||
# fig = BECFigure(connected_client_figure)
|
||||
fig = connected_figure
|
||||
plt = fig.plot(x_name="samx", y_name="bpm4i", dap="GaussianModel")
|
||||
im = fig.image(monitor="eiger")
|
||||
|
Reference in New Issue
Block a user