mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-08-07 18:52:39 +02:00
refactor: remove main, individual gui_ids for DockArea
This commit is contained in:
@@ -27,7 +27,9 @@ def gui_id():
|
||||
@contextmanager
|
||||
def plot_server(gui_id, klass, client_lib):
|
||||
dispatcher = BECDispatcher(client=client_lib) # Has to init singleton with fixture client
|
||||
process, _ = _start_plot_process(gui_id, klass, client_lib._client._service_config.config_path)
|
||||
process, _ = _start_plot_process(
|
||||
gui_id, klass, gui_class_id="bec", config=client_lib._client._service_config.config_path
|
||||
)
|
||||
try:
|
||||
while client_lib._client.connector.get(MessageEndpoints.gui_heartbeat(gui_id)) is None:
|
||||
time.sleep(0.3)
|
||||
@@ -52,7 +54,7 @@ def connected_client_gui_obj(gui_id, bec_client_lib):
|
||||
gui._start_server(wait=True)
|
||||
yield gui
|
||||
finally:
|
||||
gui.close()
|
||||
gui._close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -61,9 +63,10 @@ def connected_client_dock(gui_id, bec_client_lib):
|
||||
gui._auto_updates_enabled = False
|
||||
try:
|
||||
gui._start_server(wait=True)
|
||||
yield gui.main
|
||||
gui.window_list[0]
|
||||
yield gui.window_list[0]
|
||||
finally:
|
||||
gui.close()
|
||||
gui._close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -71,6 +74,6 @@ def connected_client_dock_w_auto_updates(gui_id, bec_client_lib):
|
||||
gui = BECGuiClient(gui_id=gui_id)
|
||||
try:
|
||||
gui._start_server(wait=True)
|
||||
yield gui, gui.main
|
||||
yield gui, gui.window_list[0]
|
||||
finally:
|
||||
gui.close()
|
||||
gui._close()
|
||||
|
||||
@@ -315,8 +315,8 @@ 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"] is gui.main
|
||||
mw = gui.main
|
||||
assert gui.windows["bec"] is gui.bec
|
||||
mw = gui.bec
|
||||
assert mw.__class__.__name__ == "BECDockArea"
|
||||
|
||||
xw = gui.new("X")
|
||||
@@ -325,10 +325,10 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
|
||||
gui_info = gui._dump()
|
||||
mw_info = gui_info[mw._gui_id]
|
||||
assert mw_info["title"] == "BEC Widgets"
|
||||
assert mw_info["title"] == "BEC"
|
||||
assert mw_info["visible"]
|
||||
xw_info = gui_info[xw._gui_id]
|
||||
assert xw_info["title"] == "X"
|
||||
assert xw_info["title"] == "BEC - X"
|
||||
assert xw_info["visible"]
|
||||
|
||||
gui.hide()
|
||||
@@ -339,23 +339,23 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
gui_info = gui._dump()
|
||||
assert all(windows["visible"] for windows in gui_info.values())
|
||||
|
||||
assert gui.gui_is_alive()
|
||||
gui.close()
|
||||
assert not gui.gui_is_alive()
|
||||
assert gui._gui_is_alive()
|
||||
gui._close()
|
||||
assert not gui._gui_is_alive()
|
||||
gui._start_server(wait=True)
|
||||
assert gui.gui_is_alive()
|
||||
assert gui._gui_is_alive()
|
||||
# calling start multiple times should not change anything
|
||||
gui._start_server(wait=True)
|
||||
gui.start()
|
||||
# gui.windows should have main, and main dock area should have same gui_id as before
|
||||
gui._start()
|
||||
# gui.windows should have bec with gui_id 'bec'
|
||||
assert len(gui.windows) == 1
|
||||
assert gui.windows["main"]._gui_id == mw._gui_id
|
||||
assert gui.windows["bec"]._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"]
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
gui.main.delete()
|
||||
gui.bec.delete()
|
||||
|
||||
yw = gui.new("Y")
|
||||
assert len(gui.windows) == 2
|
||||
@@ -373,5 +373,5 @@ def test_rpc_call_with_exception_in_safeslot_error_popup(connected_client_gui_ob
|
||||
qtbot.waitUntil(lambda: len(gui.main.panels) == 2) # default_figure + test
|
||||
qtbot.wait(500)
|
||||
with pytest.raises(ValueError):
|
||||
gui.main.add_dock("test")
|
||||
gui.bec.add_dock("test")
|
||||
# time.sleep(0.1)
|
||||
|
||||
@@ -66,13 +66,13 @@ def test_client_utils_passes_client_config_to_server(bec_dispatcher):
|
||||
mixin = BECGuiClient()
|
||||
mixin._client = bec_dispatcher.client
|
||||
mixin._gui_id = "gui_id"
|
||||
mixin.gui_is_alive = mock.MagicMock()
|
||||
mixin.gui_is_alive.side_effect = [True]
|
||||
mixin._gui_is_alive = mock.MagicMock()
|
||||
mixin._gui_is_alive.side_effect = [True]
|
||||
|
||||
try:
|
||||
yield mixin
|
||||
finally:
|
||||
mixin.close()
|
||||
mixin._close()
|
||||
|
||||
with bec_client_mixin() as mixin:
|
||||
with mock.patch("bec_widgets.cli.client_utils._start_plot_process") as mock_start_plot:
|
||||
|
||||
Reference in New Issue
Block a user