1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-03-04 16:02:51 +01:00

feat(developer_widget): add signal connection for focused editor changes to disable run button for macro files

This commit is contained in:
2025-11-26 10:56:14 +01:00
committed by Klaus Wakonig
parent 2ffe269727
commit 4a2bc9fcd9
2 changed files with 69 additions and 0 deletions

View File

@@ -124,6 +124,7 @@ class DeveloperWidget(DockAreaWidget):
# Connect editor signals
self.explorer.file_open_requested.connect(self._open_new_file)
self.monaco.macro_file_updated.connect(self.explorer.refresh_macro_file)
self.monaco.focused_editor.connect(self._on_focused_editor_changed)
self.toolbar.show_bundles(["save", "execution", "settings"])
@@ -336,6 +337,28 @@ class DeveloperWidget(DockAreaWidget):
self.on_script_execution_info, MessageEndpoints.script_execution_info(new_script_id)
)
@SafeSlot(CDockWidget)
def _on_focused_editor_changed(self, tab_widget: CDockWidget):
"""
Disable the run / stop buttons if the focused editor is a macro file.
Args:
tab_widget: The currently focused tab widget in the Monaco editor.
"""
if not isinstance(tab_widget, CDockWidget):
return
widget = tab_widget.widget()
if not isinstance(widget, MonacoWidget):
return
file_scope = widget.metadata.get("scope", "")
run_action = self.toolbar.components.get_action("run")
stop_action = self.toolbar.components.get_action("stop")
if "macro" in file_scope:
run_action.action.setEnabled(False)
stop_action.action.setEnabled(False)
else:
run_action.action.setEnabled(True)
stop_action.action.setEnabled(True)
@SafeSlot(dict, dict)
def on_script_execution_info(self, content: dict, metadata: dict):
"""

View File

@@ -322,6 +322,52 @@ class TestToolbarIntegration:
# Check that state changed
assert vim_action.action.isChecked() != initial_state
def test_run_stop_buttons_disabled_for_macros(self, developer_view, temp_python_file, qtbot):
"""Test that run and stop buttons are disabled when a macro file is focused."""
# Open a file with macro scope
developer_view._open_new_file(temp_python_file, "macros/local")
qtbot.waitUntil(
lambda: temp_python_file in developer_view.monaco._get_open_files(), timeout=2000
)
# Get the editor dock for the macro file
dock = developer_view.monaco._get_editor_dock(temp_python_file)
assert dock is not None
# Simulate focusing on the macro file
developer_view._on_focused_editor_changed(dock)
# Check that run and stop buttons are disabled
run_action = developer_view.toolbar.components.get_action("run")
stop_action = developer_view.toolbar.components.get_action("stop")
assert not run_action.action.isEnabled()
assert not stop_action.action.isEnabled()
def test_run_stop_buttons_enabled_for_scripts(self, developer_view, temp_python_file, qtbot):
"""Test that run and stop buttons are enabled when a script file is focused."""
# Open a file with script scope
developer_view._open_new_file(temp_python_file, "scripts/local")
qtbot.waitUntil(
lambda: temp_python_file in developer_view.monaco._get_open_files(), timeout=2000
)
# Get the editor dock for the script file
dock = developer_view.monaco._get_editor_dock(temp_python_file)
assert dock is not None
# Simulate focusing on the script file
developer_view._on_focused_editor_changed(dock)
# Check that run and stop buttons are enabled
run_action = developer_view.toolbar.components.get_action("run")
stop_action = developer_view.toolbar.components.get_action("stop")
assert run_action.action.isEnabled()
assert stop_action.action.isEnabled()
class TestErrorHandling:
"""Test error handling in various scenarios."""