mirror of https://gitlab.com/pamhyr/pamhyr2
Debug: Add debug python repl.
parent
29986079f3
commit
0aeb2f2530
|
|
@ -216,6 +216,7 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
|
||||||
def set_debug(self):
|
def set_debug(self):
|
||||||
self.conf.debug = not self.conf.debug
|
self.conf.debug = not self.conf.debug
|
||||||
print(f"[DEBUG] Debug mode set : {self.conf.debug}")
|
print(f"[DEBUG] Debug mode set : {self.conf.debug}")
|
||||||
|
self.parent.setup_debug_mode()
|
||||||
|
|
||||||
# Solvers
|
# Solvers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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))
|
||||||
|
|
@ -13,7 +13,7 @@ from PyQt5.QtCore import (
|
||||||
)
|
)
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QMainWindow, QApplication, QAction,
|
QMainWindow, QApplication, QAction,
|
||||||
QFileDialog, QShortcut,
|
QFileDialog, QShortcut, QMenu, QToolBar,
|
||||||
)
|
)
|
||||||
from PyQt5.uic import loadUi
|
from PyQt5.uic import loadUi
|
||||||
|
|
||||||
|
|
@ -34,6 +34,7 @@ from View.Sections.Window import SectionsWindow
|
||||||
from View.SolverParameters.Window import SolverParametersWindow
|
from View.SolverParameters.Window import SolverParametersWindow
|
||||||
from View.RunSolver.Window import SelectSolverWindow, SolverLogWindow
|
from View.RunSolver.Window import SelectSolverWindow, SolverLogWindow
|
||||||
from View.CheckList.Window import CheckListWindow
|
from View.CheckList.Window import CheckListWindow
|
||||||
|
from View.Debug.Window import ReplWindow
|
||||||
|
|
||||||
from Model.Study import Study
|
from Model.Study import Study
|
||||||
|
|
||||||
|
|
@ -91,6 +92,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
self.setup_sc()
|
self.setup_sc()
|
||||||
self.setup_connection()
|
self.setup_connection()
|
||||||
self.default_style()
|
self.default_style()
|
||||||
|
self.setup_debug_mode(init = True)
|
||||||
|
|
||||||
self.trans = QTranslator(self)
|
self.trans = QTranslator(self)
|
||||||
#self.ui.retranslateUi()
|
#self.ui.retranslateUi()
|
||||||
|
|
@ -183,6 +185,22 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
# Maximise window
|
# Maximise window
|
||||||
self.showMaximized()
|
self.showMaximized()
|
||||||
|
|
||||||
|
def setup_debug_mode(self, init = False):
|
||||||
|
menu = self.findChild(QMenu, "menu_help")
|
||||||
|
|
||||||
|
if init:
|
||||||
|
self.debug_action = QAction("Debug", self)
|
||||||
|
self.debug_action.setStatusTip("Debug")
|
||||||
|
self.debug_action.triggered.connect(self.open_debug)
|
||||||
|
|
||||||
|
if self.conf.debug:
|
||||||
|
menu.addAction(self.debug_action)
|
||||||
|
else:
|
||||||
|
if self.conf.debug:
|
||||||
|
menu.addAction(self.debug_action)
|
||||||
|
else:
|
||||||
|
menu.removeAction(self.debug_action)
|
||||||
|
|
||||||
#########
|
#########
|
||||||
# MODEL #
|
# MODEL #
|
||||||
#########
|
#########
|
||||||
|
|
@ -423,6 +441,18 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
)
|
)
|
||||||
sol.show()
|
sol.show()
|
||||||
|
|
||||||
|
#########
|
||||||
|
# DEBUG #
|
||||||
|
#########
|
||||||
|
|
||||||
|
def open_debug(self):
|
||||||
|
repl = ReplWindow(
|
||||||
|
study = self.model,
|
||||||
|
config = self.conf,
|
||||||
|
parent = self
|
||||||
|
)
|
||||||
|
repl.show()
|
||||||
|
|
||||||
# TODO: Delete me !
|
# TODO: Delete me !
|
||||||
###############
|
###############
|
||||||
# DUMMY STUFF #
|
# DUMMY STUFF #
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>640</width>
|
||||||
|
<height>480</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<property name="locale">
|
||||||
|
<locale language="English" country="Europe"/>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="1" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Eval</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>ressources/player_play.png</normaloff>ressources/player_play.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+Return</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTextEdit" name="textEdit">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>640</width>
|
||||||
|
<height>22</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Loading…
Reference in New Issue