From 44f7acaeda3963316a11cd1c3c6ecdb71eccac29 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Tue, 27 Jan 2026 14:34:14 +0100 Subject: [PATCH] fix(launch_window): logic for showing launcher --- bec_widgets/applications/launch_window.py | 17 +++- tests/unit_tests/test_launch_window.py | 94 +++++++++-------------- 2 files changed, 49 insertions(+), 62 deletions(-) diff --git a/bec_widgets/applications/launch_window.py b/bec_widgets/applications/launch_window.py index 25b2c0d4..cb53555d 100644 --- a/bec_widgets/applications/launch_window.py +++ b/bec_widgets/applications/launch_window.py @@ -662,10 +662,19 @@ class LaunchWindow(BECMainWindow): Check if the launcher is the last widget in the application. """ - remaining_connections = [ - connection for connection in connections.values() if connection.parent_id != self.gui_id - ] - return len(remaining_connections) <= 4 + # get all parents of connections + for connection in connections.values(): + try: + parent = connection.parent() + if parent is None and connection.objectName() != self.objectName(): + logger.info( + f"Found non-launcher connection without parent: {connection.objectName()}" + ) + return False + except Exception as e: + logger.error(f"Error getting parent of connection: {e}") + return False + return True def _turn_off_the_lights(self, connections: dict): """ diff --git a/tests/unit_tests/test_launch_window.py b/tests/unit_tests/test_launch_window.py index f23e5165..7967df65 100644 --- a/tests/unit_tests/test_launch_window.py +++ b/tests/unit_tests/test_launch_window.py @@ -85,41 +85,30 @@ def test_launch_window_launch_plugin_auto_update(bec_launch_window): @pytest.mark.parametrize( - "connections, hide", + "connection_names, hide", [ - ({}, False), - ({"launcher": mock.MagicMock()}, False), - ({"launcher": mock.MagicMock(), "dock_area": mock.MagicMock()}, False), + ([], False), + (["launcher"], False), + (["launcher", "dock_area"], False), + (["launcher", "dock_area", "scan_progress"], False), + (["launcher", "dock_area", "scan_progress_simple", "scan_progress_full"], False), ( - { - "launcher": mock.MagicMock(), - "dock_area": mock.MagicMock(), - "scan_progress": mock.MagicMock(), - }, - False, - ), - ( - { - "launcher": mock.MagicMock(), - "dock_area": mock.MagicMock(), - "scan_progress_simple": mock.MagicMock(), - "scan_progress_full": mock.MagicMock(), - }, - False, - ), - ( - { - "launcher": mock.MagicMock(), - "dock_area": mock.MagicMock(), - "scan_progress_simple": mock.MagicMock(), - "scan_progress_full": mock.MagicMock(), - "hover_widget": mock.MagicMock(), - }, + ["launcher", "dock_area", "scan_progress_simple", "scan_progress_full", "hover_widget"], True, ), ], ) -def test_gui_server_turns_off_the_lights(bec_launch_window, connections, hide): +def test_gui_server_turns_off_the_lights(bec_launch_window, connection_names, hide): + connections = {} + for name in connection_names: + conn = mock.MagicMock() + if name == "hover_widget": + conn.parent.return_value = None + conn.objectName.return_value = "HoverWidget" + else: + conn.parent.return_value = mock.MagicMock() + conn.objectName.return_value = bec_launch_window.objectName() + connections[name] = conn with ( mock.patch.object(bec_launch_window, "show") as mock_show, mock.patch.object(bec_launch_window, "activateWindow") as mock_activate_window, @@ -142,46 +131,35 @@ def test_gui_server_turns_off_the_lights(bec_launch_window, connections, hide): @pytest.mark.parametrize( - "connections, close_called", + "connection_names, close_called", [ - ({}, True), - ({"launcher": mock.MagicMock()}, True), - ({"launcher": mock.MagicMock(), "dock_area": mock.MagicMock()}, True), + ([], True), + (["launcher"], True), + (["launcher", "dock_area"], True), + (["launcher", "dock_area", "scan_progress"], True), + (["launcher", "dock_area", "scan_progress_simple", "scan_progress_full"], True), ( - { - "launcher": mock.MagicMock(), - "dock_area": mock.MagicMock(), - "scan_progress": mock.MagicMock(), - }, - True, - ), - ( - { - "launcher": mock.MagicMock(), - "dock_area": mock.MagicMock(), - "scan_progress_simple": mock.MagicMock(), - "scan_progress_full": mock.MagicMock(), - }, - True, - ), - ( - { - "launcher": mock.MagicMock(), - "dock_area": mock.MagicMock(), - "scan_progress_simple": mock.MagicMock(), - "scan_progress_full": mock.MagicMock(), - "hover_widget": mock.MagicMock(), - }, + ["launcher", "dock_area", "scan_progress_simple", "scan_progress_full", "hover_widget"], False, ), ], ) -def test_launch_window_closes(bec_launch_window, connections, close_called): +def test_launch_window_closes(bec_launch_window, connection_names, close_called): """ Test that the close event is handled correctly based on the connections. If there are no connections or only the launcher connection, the window should close. If there are other connections, the window should hide instead of closing. """ + connections = {} + for name in connection_names: + conn = mock.MagicMock() + if name == "hover_widget": + conn.parent.return_value = None + conn.objectName.return_value = "HoverWidget" + else: + conn.parent.return_value = mock.MagicMock() + conn.objectName.return_value = bec_launch_window.objectName() + connections[name] = conn close_event = mock.MagicMock() with mock.patch.object( bec_launch_window.register, "list_all_connections", return_value=connections