mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Debug: Add debug python repl.
This commit is contained in:
1 parent
29986079f3
commit
0aeb2f2530
4 files changed
+181
-1
No files matched your search
@@ -0,0 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tools import trace, timer
|
||||
|
||||
from View.ASubWindow import ASubMainWindow
|
||||
from View.ListedSubWindow import ListedSubWindow
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, QRect, QThread,
|
||||
pyqtSlot, pyqtSignal,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
QProgressBar, QLabel, QTextEdit,
|
||||
)
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
class ReplWindow(ASubMainWindow, ListedSubWindow):
|
||||
def __init__(self, title="Debug REPL",
|
||||
study=None, config=None,
|
||||
solver=None, parent=None):
|
||||
self._title = title
|
||||
|
||||
self._study = study
|
||||
self._config = config
|
||||
self._parent = parent
|
||||
|
||||
super(ReplWindow, self).__init__(
|
||||
name=self._title, ui="DebugRepl", parent=parent
|
||||
)
|
||||
self.ui.setWindowTitle(self._title)
|
||||
|
||||
self.__debug_exec_result__ = None
|
||||
self._history = []
|
||||
self._history_ind = 0
|
||||
|
||||
self.setup_connections()
|
||||
|
||||
def setup_connections(self):
|
||||
self._hup_sc = QShortcut(QKeySequence("Up"), self)
|
||||
self._hdown_sc = QShortcut(QKeySequence("Down"), self)
|
||||
self._hup_sc.activated.connect(self.history_up)
|
||||
self._hdown_sc.activated.connect(self.history_down)
|
||||
|
||||
self.find(QPushButton, "pushButton").clicked.connect(self.eval_python)
|
||||
|
||||
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])
|
||||
|
||||
def history_down(self):
|
||||
if self._history_ind > 0:
|
||||
self._history_ind -= 1
|
||||
self.set_line_edit_text("lineEdit", self._history[-self._history_ind])
|
||||
|
||||
def eval_python(self):
|
||||
code = self.get_line_edit_text("lineEdit")
|
||||
self._history.append(code)
|
||||
self.set_line_edit_text("lineEdit", "")
|
||||
self._history_ind = 0
|
||||
|
||||
code = "self.__debug_exec_result__ = " + code
|
||||
print(f"[DEBUG] ! {code}")
|
||||
value = exec(code)
|
||||
value = self.__debug_exec_result__
|
||||
|
||||
msg = f"<font color=\"grey\"> # " + code + " #</font>"
|
||||
self.find(QTextEdit, "textEdit").append(msg)
|
||||
|
||||
self.find(QTextEdit, "textEdit").append(str(value))
|
||||
Reference in new issue
Block a user