Failed to fetch fork details. Try again later.
-
Delaigue Olivier authored60219b28
Forked from
HYCAR-Hydro / airGR
Source project has a limited visibility.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Window.py -- Pamhyr
# Copyright (C) 2023-2024 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 tools import trace, timer
from View.Tools.PamhyrWindow import PamhyrWindow
from View.Tools.PamhyrPythonEditor import PamhyrPythonEditor
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, QHBoxLayout,
)
from PyQt5.Qsci import QsciScintilla, QsciLexerPython
logger = logging.getLogger()
_translate = QCoreApplication.translate
class ReplWindow(PamhyrWindow):
_pamhyr_ui = "DebugRepl"
_pamhyr_name = "Debug REPL"
def __init__(self, study=None, config=None,
solver=None, parent=None):
title = _translate("Debug", "Debug REPL")
super(ReplWindow, self).__init__(
title=title,
study=study,
config=config,
options=[],
parent=parent
)
self.__debug_exec_result__ = None
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.find(QPushButton, "pushButton").clicked.connect(self.eval_python)
def eval_python(self):
code = self._editor.text()
# Code to rich_code
rich_code = code.strip().split("\n")
# 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 : \n{rich_code}")
try:
value = exec(rich_code)
value = self.__debug_exec_result__
except Exception as e:
value = f"<font color=\"red\">" + str(e) + "</font>"
# Display code
msg = f"<font color=\"grey\"> # " + code + " #</font>"
self.find(QTextEdit, "textEdit").append(msg)
# Display results
self.find(QTextEdit, "textEdit").append(str(value))