diff --git a/src/View/Configure/Window.py b/src/View/Configure/Window.py index 8d941180dd4b4b8670ad07ed23e2876a6830fe85..69d64a69d5284dc8aaf9fae85012779df885013c 100644 --- a/src/View/Configure/Window.py +++ b/src/View/Configure/Window.py @@ -216,6 +216,7 @@ class ConfigureWindow(ASubWindow, ListedSubWindow): def set_debug(self): self.conf.debug = not self.conf.debug print(f"[DEBUG] Debug mode set : {self.conf.debug}") + self.parent.setup_debug_mode() # Solvers diff --git a/src/View/Debug/Window.py b/src/View/Debug/Window.py new file mode 100644 index 0000000000000000000000000000000000000000..dd26d91efef59a16fc8d9e84ca0c3dec349e8ab0 --- /dev/null +++ b/src/View/Debug/Window.py @@ -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)) diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 5150409cbd293c7d51361812e379162d57cddb9f..7953f3e308df53823814bf41a77cd188a317898b 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -13,7 +13,7 @@ from PyQt5.QtCore import ( ) from PyQt5.QtWidgets import ( QMainWindow, QApplication, QAction, - QFileDialog, QShortcut, + QFileDialog, QShortcut, QMenu, QToolBar, ) from PyQt5.uic import loadUi @@ -34,6 +34,7 @@ from View.Sections.Window import SectionsWindow from View.SolverParameters.Window import SolverParametersWindow from View.RunSolver.Window import SelectSolverWindow, SolverLogWindow from View.CheckList.Window import CheckListWindow +from View.Debug.Window import ReplWindow from Model.Study import Study @@ -91,6 +92,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self.setup_sc() self.setup_connection() self.default_style() + self.setup_debug_mode(init = True) self.trans = QTranslator(self) #self.ui.retranslateUi() @@ -183,6 +185,22 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): # Maximise window 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 # ######### @@ -423,6 +441,18 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ) sol.show() + ######### + # DEBUG # + ######### + + def open_debug(self): + repl = ReplWindow( + study = self.model, + config = self.conf, + parent = self + ) + repl.show() + # TODO: Delete me ! ############### # DUMMY STUFF # diff --git a/src/View/ui/DebugRepl.ui b/src/View/ui/DebugRepl.ui new file mode 100644 index 0000000000000000000000000000000000000000..f889061d8f7ce2be570e174c6d57859a9b908831 --- /dev/null +++ b/src/View/ui/DebugRepl.ui @@ -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>