From c9d05e42f73db3906f29d5b9a28b719e1e08471a Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Wed, 1 Jul 2026 18:55:34 +0200 Subject: [PATCH] fix: update ctrl c for qtermwidget --- .../views/developer_view/developer_widget.py | 3 ++- .../editors/bec_console/bec_console.py | 8 ++++---- .../widgets/utility/bec_term/protocol.py | 6 ++++++ .../utility/bec_term/qtermwidget_wrapper.py | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/bec_widgets/applications/views/developer_view/developer_widget.py b/bec_widgets/applications/views/developer_view/developer_widget.py index d3eecd48..2c573a57 100644 --- a/bec_widgets/applications/views/developer_view/developer_widget.py +++ b/bec_widgets/applications/views/developer_view/developer_widget.py @@ -329,7 +329,8 @@ class DeveloperWidget(DockAreaWidget): """Stop the execution of the currently running script""" if not self.current_script_id: return - self.console.send_ctrl_c() + if self.console.term is not None: + self.console.term.send_ctrl_c() @property def current_script_id(self): diff --git a/bec_widgets/widgets/editors/bec_console/bec_console.py b/bec_widgets/widgets/editors/bec_console/bec_console.py index 87f3ff81..9199e22f 100644 --- a/bec_widgets/widgets/editors/bec_console/bec_console.py +++ b/bec_widgets/widgets/editors/bec_console/bec_console.py @@ -397,7 +397,7 @@ class BecConsole(BECWidget, QWidget): def _set_up_instance(self): """ - Set up the web instance and UI elements. + Set up the console instance. """ self._stacked_layout = QStackedLayout() # self._stacked_layout.setStackingMode(QStackedLayout.StackingMode.StackAll) @@ -434,7 +434,7 @@ class BecConsole(BECWidget, QWidget): def _set_mode(self, mode: ConsoleMode): """ - Set the mode of the web console. + Set the mode of the console. Args: mode (ConsoleMode): The mode to set. @@ -508,7 +508,7 @@ class BecConsole(BECWidget, QWidget): def take_terminal_ownership(self): """ - Take ownership of a web instance from the registry. This will transfer the instance + Take ownership of a console instance from the registry. This will transfer the instance from its current owner (if any) to this widget. """ # Get the instance from registry @@ -520,7 +520,7 @@ class BecConsole(BECWidget, QWidget): def yield_ownership(self): """ - Yield ownership of the instance. The instance remains in the registry with no owner, + Yield ownership of the console instance. The instance remains in the registry with no owner, available for another widget to claim. This is automatically called when the widget becomes hidden. """ diff --git a/bec_widgets/widgets/utility/bec_term/protocol.py b/bec_widgets/widgets/utility/bec_term/protocol.py index 4300009c..2e0236f0 100644 --- a/bec_widgets/widgets/utility/bec_term/protocol.py +++ b/bec_widgets/widgets/utility/bec_term/protocol.py @@ -6,3 +6,9 @@ class BecTerminal(Protocol): """Implementors of this protocol must also be subclasses of QWidget""" def write(self, text: str, add_newline: bool = True): ... + + def zoom_in(self): ... + + def zoom_out(self): ... + + def send_ctrl_c(self): ... diff --git a/bec_widgets/widgets/utility/bec_term/qtermwidget_wrapper.py b/bec_widgets/widgets/utility/bec_term/qtermwidget_wrapper.py index 26af35a7..d3dafaee 100644 --- a/bec_widgets/widgets/utility/bec_term/qtermwidget_wrapper.py +++ b/bec_widgets/widgets/utility/bec_term/qtermwidget_wrapper.py @@ -74,10 +74,29 @@ class BecQTerm(QWidget): self._layout.addWidget(self._main_widget) def write(self, text: str, add_newline: bool = True): + """ + Write text to the terminal. + + Args: + text (str): The text to write. + add_newline (bool): Whether to add a newline at the end. + """ if add_newline: text += "\n" self._sendText(text) + def zoom_in(self): + """Zoom in the terminal font size.""" + self._zoomIn() + + def zoom_out(self): + """Zoom out the terminal font size.""" + self._zoomOut() + + def send_ctrl_c(self): + """Send Ctrl+C to the terminal.""" + self.write("\x03", add_newline=False) # Send Ctrl+C character to the terminal + # automatically forwarded to the widget only if it exists @_forward def _addCustomColorSchemeDir(self, custom_dir: str, /) -> None: ...