mirror of https://gitlab.com/pamhyr/pamhyr2
debug: Switch from QPlainTextEdit to PamhyrPythonEditor.
parent
bcc2d2f4d4
commit
2e926c9ece
|
|
@ -21,6 +21,7 @@ import logging
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||||
|
from View.Tools.PamhyrPythonEditor import PamhyrPythonEditor
|
||||||
|
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QKeySequence,
|
QKeySequence,
|
||||||
|
|
@ -37,9 +38,11 @@ from PyQt5.QtWidgets import (
|
||||||
QFileDialog, QTableView, QAbstractItemView,
|
QFileDialog, QTableView, QAbstractItemView,
|
||||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||||
QProgressBar, QLabel, QTextEdit,
|
QProgressBar, QLabel, QTextEdit, QHBoxLayout,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from PyQt5.Qsci import QsciScintilla, QsciLexerPython
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
@ -63,8 +66,14 @@ class ReplWindow(PamhyrWindow):
|
||||||
self._history = []
|
self._history = []
|
||||||
self._history_ind = 0
|
self._history_ind = 0
|
||||||
|
|
||||||
|
self.setup_editor()
|
||||||
self.setup_connections()
|
self.setup_connections()
|
||||||
|
|
||||||
|
def setup_editor(self):
|
||||||
|
layout = self.find(QHBoxLayout, "horizontalLayout")
|
||||||
|
self._editor = PamhyrPythonEditor()
|
||||||
|
layout.insertWidget(0, self._editor)
|
||||||
|
|
||||||
def setup_connections(self):
|
def setup_connections(self):
|
||||||
self._hup_sc = QShortcut(QKeySequence("ctrl+Up"), self)
|
self._hup_sc = QShortcut(QKeySequence("ctrl+Up"), self)
|
||||||
self._hdown_sc = QShortcut(QKeySequence("ctrl+Down"), self)
|
self._hdown_sc = QShortcut(QKeySequence("ctrl+Down"), self)
|
||||||
|
|
@ -76,21 +85,19 @@ class ReplWindow(PamhyrWindow):
|
||||||
def history_up(self):
|
def history_up(self):
|
||||||
if self._history_ind < len(self._history):
|
if self._history_ind < len(self._history):
|
||||||
self._history_ind += 1
|
self._history_ind += 1
|
||||||
self.set_plaintext_edit_text(
|
self._editor.setText(self._history[-self._history_ind])
|
||||||
"plainTextEdit", self._history[-self._history_ind])
|
|
||||||
|
|
||||||
def history_down(self):
|
def history_down(self):
|
||||||
if self._history_ind > 0:
|
if self._history_ind > 0:
|
||||||
self._history_ind -= 1
|
self._history_ind -= 1
|
||||||
self.set_plaintext_edit_text(
|
self._editor.setText(self._history[-self._history_ind])
|
||||||
"plainTextEdit", self._history[-self._history_ind])
|
|
||||||
else:
|
else:
|
||||||
self.set_plaintext_edit_text("plainTextEdit", "")
|
self._editor.setText("")
|
||||||
|
|
||||||
def eval_python(self):
|
def eval_python(self):
|
||||||
code = self.get_plaintext_edit_text("plainTextEdit")
|
code = self._editor.text()
|
||||||
self._history.append(code)
|
self._history.append(code)
|
||||||
self.set_plaintext_edit_text("plainTextEdit", "")
|
self._editor.setText("")
|
||||||
self._history_ind = 0
|
self._history_ind = 0
|
||||||
|
|
||||||
# Code to rich_code
|
# Code to rich_code
|
||||||
|
|
@ -98,7 +105,7 @@ class ReplWindow(PamhyrWindow):
|
||||||
# Add return variable for results display at last row
|
# Add return variable for results display at last row
|
||||||
rich_code[-1] = "self.__debug_exec_result__ = " + rich_code[-1]
|
rich_code[-1] = "self.__debug_exec_result__ = " + rich_code[-1]
|
||||||
rich_code = "\n".join(rich_code)
|
rich_code = "\n".join(rich_code)
|
||||||
logger.debug(f"User debug command : {rich_code}")
|
logger.debug(f"User debug command : \n{rich_code}")
|
||||||
try:
|
try:
|
||||||
value = exec(rich_code)
|
value = exec(rich_code)
|
||||||
value = self.__debug_exec_result__
|
value = self.__debug_exec_result__
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -20,15 +20,6 @@
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
|
||||||
<widget class="QPlainTextEdit" name="plainTextEdit">
|
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<family>Monospace</family>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue