1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-03-06 17:02:50 +01:00

refactor: remove WidgetDesc and move _gui_is_alive to private

This commit is contained in:
2025-02-19 14:25:43 +01:00
committed by wyzula-jan
parent 1f4e740dca
commit f2a69e5c52
2 changed files with 9 additions and 18 deletions

View File

@@ -147,7 +147,7 @@ def wait_for_server(client):
### is created, and client module is patched.
class BECDockArea(client.BECDockArea):
def delete(self):
if self is BECGuiClient._top_level["main"].widget:
if self is BECGuiClient._top_level["main"]:
raise RuntimeError("Cannot delete main window")
super().delete()
try:
@@ -161,12 +161,6 @@ client.BECDockArea = BECDockArea
### ----------------------------
@dataclass
class WidgetDesc:
title: str
widget: BECDockArea
class BECGuiClient(RPCBase):
_top_level = {}
@@ -200,7 +194,7 @@ class BECGuiClient(RPCBase):
# if the module is not found, we skip it
if spec is None:
continue
return ep.load()(gui=self._top_level["main"].widget)
return ep.load()(gui=self._top_level["main"])
except Exception as e:
logger.error(f"Error loading auto update script from plugin: {str(e)}")
return None
@@ -247,16 +241,14 @@ class BECGuiClient(RPCBase):
return self.auto_updates.do_update(msg)
def _gui_post_startup(self):
self._top_level["main"] = WidgetDesc(
title="BEC Widgets", widget=BECDockArea(gui_id=self._gui_id)
)
self._top_level["main"] = BECDockArea(gui_id=self._gui_id)
if self._auto_updates_enabled:
if self._auto_updates is None:
auto_updates = self._get_update_script()
if auto_updates is None:
AutoUpdates.create_default_dock = True
AutoUpdates.enabled = True
auto_updates = AutoUpdates(self._top_level["main"].widget)
auto_updates = AutoUpdates(self._top_level["main"])
if auto_updates.create_default_dock:
auto_updates.start_default_dock()
self._start_update_script()
@@ -302,7 +294,7 @@ class BECGuiClient(RPCBase):
rpc_client = RPCBase(gui_id=f"{self._gui_id}:window", parent=self)
rpc_client._run_rpc("show")
for window in self._top_level.values():
window.widget.show()
window.show()
def show_all(self):
with wait_for_server(self):
@@ -313,7 +305,7 @@ class BECGuiClient(RPCBase):
rpc_client = RPCBase(gui_id=f"{self._gui_id}:window", parent=self)
rpc_client._run_rpc("hide")
for window in self._top_level.values():
window.widget.hide()
window.hide()
def show(self):
if self._process is not None:
@@ -328,7 +320,7 @@ class BECGuiClient(RPCBase):
def main(self):
"""Return client to main dock area (in main window)"""
with wait_for_server(self):
return self._top_level["main"].widget
return self._top_level["main"]
def new(self, title: str = None) -> BECDockArea:
"""Ask main window to create a new top-level dock area"""

View File

@@ -315,8 +315,7 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
assert gui.selected_device is None
assert len(gui.windows) == 1
assert gui.windows["main"].widget is gui.main
assert gui.windows["main"].title == "BEC Widgets"
assert gui.windows["main"] is gui.main
mw = gui.main
assert mw.__class__.__name__ == "BECDockArea"
@@ -350,7 +349,7 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
gui.start()
# gui.windows should have main, and main dock area should have same gui_id as before
assert len(gui.windows) == 1
assert gui.windows["main"].widget._gui_id == mw._gui_id
assert gui.windows["main"]._gui_id == mw._gui_id
# communication should work, main dock area should have same id and be visible
gui_info = gui._dump()
assert gui_info[mw._gui_id]["visible"]