From 17b11b34a72b042639cc63d6be06ed70e2c1f6d8 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 7 Jul 2023 11:36:21 +0200 Subject: [PATCH] Debug: Switch to multiline debug command. --- src/View/ASubWindow.py | 25 ++++++++++++++++++++++++- src/View/Debug/Window.py | 20 ++++++++++++-------- src/View/ui/DebugRepl.ui | 2 +- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/View/ASubWindow.py b/src/View/ASubWindow.py index 13719d77..478993cf 100644 --- a/src/View/ASubWindow.py +++ b/src/View/ASubWindow.py @@ -18,7 +18,7 @@ from PyQt5.QtWidgets import ( QTimeEdit, QSpinBox, QTextEdit, QRadioButton, QComboBox, QFileDialog, QMessageBox, QTableView, QAction, - QDateTimeEdit, QWidget, + QDateTimeEdit, QWidget, QPlainTextEdit, ) from PyQt5.QtCore import ( QTime, QDateTime, @@ -179,6 +179,29 @@ class ASubWindowFeatures(object): """ return self.find(QTextEdit, name).toHtml() + def set_plaintext_edit_text(self, name:str, text:str): + """Set text of text edit component + + Args: + text_edit: The text edit component name + text: The text + + Returns: + Nothing + """ + self.find(QPlainTextEdit, name).setPlainText(text) + + def get_plaintext_edit_text(self, name:str): + """Get text of text edit component + + Args: + text_edit: The text edit component name + + Returns: + Text + """ + return self.find(QPlainTextEdit, name).toPlainText() + def set_check_box(self, name:str, checked:bool): """Set status of checkbox component diff --git a/src/View/Debug/Window.py b/src/View/Debug/Window.py index c02075a7..974eace3 100644 --- a/src/View/Debug/Window.py +++ b/src/View/Debug/Window.py @@ -51,8 +51,8 @@ class ReplWindow(ASubMainWindow, ListedSubWindow): self.setup_connections() def setup_connections(self): - self._hup_sc = QShortcut(QKeySequence("Up"), self) - self._hdown_sc = QShortcut(QKeySequence("Down"), self) + self._hup_sc = QShortcut(QKeySequence("ctrl+Up"), self) + self._hdown_sc = QShortcut(QKeySequence("ctrl+Down"), self) self._hup_sc.activated.connect(self.history_up) self._hdown_sc.activated.connect(self.history_down) @@ -61,21 +61,25 @@ class ReplWindow(ASubMainWindow, ListedSubWindow): def history_up(self): if self._history_ind < len(self._history): self._history_ind += 1 - self.set_line_edit_text("lineEdit", self._history[-self._history_ind]) + self.set_plaintext_edit_text("plainTextEdit", self._history[-self._history_ind]) def history_down(self): if self._history_ind > 0: self._history_ind -= 1 - self.set_line_edit_text("lineEdit", self._history[-self._history_ind]) + self.set_plaintext_edit_text("plainTextEdit", self._history[-self._history_ind]) + else: + self.set_plaintext_edit_text("plainTextEdit", "") def eval_python(self): - code = self.get_line_edit_text("lineEdit") + code = self.get_plaintext_edit_text("plainTextEdit") self._history.append(code) - self.set_line_edit_text("lineEdit", "") + self.set_plaintext_edit_text("plainTextEdit", "") self._history_ind = 0 - rich_code = "self.__debug_exec_result__ = " + code - logger.debug(f"{code}") + rich_code = code.strip().split("\n") + rich_code[-1] = "self.__debug_exec_result__ = " + rich_code[-1] + rich_code = "\n".join(rich_code) + logger.debug(f"User debug command : {rich_code}") try: value = exec(rich_code) value = self.__debug_exec_result__ diff --git a/src/View/ui/DebugRepl.ui b/src/View/ui/DebugRepl.ui index f889061d..03494a0c 100644 --- a/src/View/ui/DebugRepl.ui +++ b/src/View/ui/DebugRepl.ui @@ -21,7 +21,7 @@ <item row="1" column="0"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QLineEdit" name="lineEdit"/> + <widget class="QPlainTextEdit" name="plainTextEdit"/> </item> <item> <widget class="QPushButton" name="pushButton"> -- GitLab