diff --git a/src/View/Debug/Window.py b/src/View/Debug/Window.py index 4d60a396e3eca310909b06aec84533503339d7b4..a7c5b7afc0581a6dac16ec28dba6641c98eadcd6 100644 --- a/src/View/Debug/Window.py +++ b/src/View/Debug/Window.py @@ -21,6 +21,7 @@ import logging from tools import trace, timer from View.Tools.PamhyrWindow import PamhyrWindow +from View.Tools.PamhyrPythonEditor import PamhyrPythonEditor from PyQt5.QtGui import ( QKeySequence, @@ -37,9 +38,11 @@ from PyQt5.QtWidgets import ( QFileDialog, QTableView, QAbstractItemView, QUndoStack, QShortcut, QAction, QItemDelegate, QComboBox, QVBoxLayout, QHeaderView, QTabWidget, - QProgressBar, QLabel, QTextEdit, + QProgressBar, QLabel, QTextEdit, QHBoxLayout, ) +from PyQt5.Qsci import QsciScintilla, QsciLexerPython + logger = logging.getLogger() _translate = QCoreApplication.translate @@ -63,8 +66,14 @@ class ReplWindow(PamhyrWindow): self._history = [] self._history_ind = 0 + self.setup_editor() self.setup_connections() + def setup_editor(self): + layout = self.find(QHBoxLayout, "horizontalLayout") + self._editor = PamhyrPythonEditor() + layout.insertWidget(0, self._editor) + def setup_connections(self): self._hup_sc = QShortcut(QKeySequence("ctrl+Up"), self) self._hdown_sc = QShortcut(QKeySequence("ctrl+Down"), self) @@ -76,21 +85,19 @@ class ReplWindow(PamhyrWindow): def history_up(self): if self._history_ind < len(self._history): self._history_ind += 1 - self.set_plaintext_edit_text( - "plainTextEdit", self._history[-self._history_ind]) + self._editor.setText(self._history[-self._history_ind]) def history_down(self): if self._history_ind > 0: self._history_ind -= 1 - self.set_plaintext_edit_text( - "plainTextEdit", self._history[-self._history_ind]) + self._editor.setText(self._history[-self._history_ind]) else: - self.set_plaintext_edit_text("plainTextEdit", "") + self._editor.setText("") def eval_python(self): - code = self.get_plaintext_edit_text("plainTextEdit") + code = self._editor.text() self._history.append(code) - self.set_plaintext_edit_text("plainTextEdit", "") + self._editor.setText("") self._history_ind = 0 # Code to rich_code @@ -98,7 +105,7 @@ class ReplWindow(PamhyrWindow): # Add return variable for results display at last row rich_code[-1] = "self.__debug_exec_result__ = " + rich_code[-1] rich_code = "\n".join(rich_code) - logger.debug(f"User debug command : {rich_code}") + logger.debug(f"User debug command : \n{rich_code}") try: value = exec(rich_code) value = self.__debug_exec_result__ diff --git a/src/View/Tools/PamhyrPythonEditor.py b/src/View/Tools/PamhyrPythonEditor.py new file mode 100644 index 0000000000000000000000000000000000000000..b162bb9cb75f1b6568718e9c84e14f609ec2f3ec --- /dev/null +++ b/src/View/Tools/PamhyrPythonEditor.py @@ -0,0 +1,41 @@ +# PamhyrPythonEditor.py -- Pamhyr +# Copyright (C) 2023 INRAE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# -*- coding: utf-8 -*- + +import logging + +from PyQt5.QtGui import QFont, QFontMetrics, QColor +from PyQt5.Qsci import QsciScintilla, QsciLexerPython + +logger = logging.getLogger() + +class PamhyrPythonEditor(QsciScintilla): + def __init__(self, parent=None): + super(PamhyrPythonEditor, self).__init__(parent) + + # Set the default font + font = QFont() + font.setFamily('Monospace') + font.setFixedPitch(True) + font.setPointSize(10) + self.setFont(font) + self.setMarginsFont(font) + + # Set Python lexer + lexer = QsciLexerPython() + lexer.setDefaultFont(font) + self.setLexer(lexer) diff --git a/src/View/ui/DebugRepl.ui b/src/View/ui/DebugRepl.ui index c0fc844ecad8d9a62c0468d98e84991ff15559eb..c060c1c0b9898b15fd2a8deeb5bffc291649a21f 100644 --- a/src/View/ui/DebugRepl.ui +++ b/src/View/ui/DebugRepl.ui @@ -20,15 +20,6 @@ <layout class="QGridLayout" name="gridLayout"> <item row="1" column="0"> <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QPlainTextEdit" name="plainTextEdit"> - <property name="font"> - <font> - <family>Monospace</family> - </font> - </property> - </widget> - </item> <item> <widget class="QPushButton" name="pushButton"> <property name="text">