-
Pierre-Antoine Rouby authored8760cd36
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# Window.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 -*-
from tools import trace, timer
from View.Tools.PamhyrWindow import PamhyrWindow
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,
)
from View.CheckList.Table import TableModel
from View.CheckList.Worker import Worker
from View.CheckList.Translate import CheckListTranslate
_translate = QCoreApplication.translate
class CheckListWindow(PamhyrWindow):
_pamhyr_ui = "CheckList"
_pamhyr_name = "Check list"
signalStatus = pyqtSignal(str)
def __init__(self, autorun: bool = True,
study=None, config=None,
solver=None, parent=None):
self._autorun = autorun
self._solver = solver
name = self._pamhyr_name + " - " + study.name
super(CheckListWindow, self).__init__(
title=name,
study=study,
config=config,
trad=CheckListTranslate(),
options=[],
parent=parent
)
# Add solver to hash computation data
self._hash_data.append(self._solver)
self._checker_list = (
self._study.checkers() +
self._solver.checkers()
)
self.setup_table()
self.setup_progress_bar()
self.setup_connections()
self.setup_thread()
self.setup_statusbar()
def setup_table(self):
table = self.find(QTableView, f"tableView")
self._table = TableModel(
table_view=table,
table_headers=self._trad.get_dict("table_headers"),
data=self._checker_list,
)
def setup_progress_bar(self):
self._progress = self.find(QProgressBar, f"progressBar")
self._p = 0 # Progress current step
self._progress.setRange(0, len(self._checker_list))
self._progress.setValue(self._p)
def setup_connections(self):
self.find(QPushButton, "pushButton_ok").clicked.connect(self.accept)
self.find(QPushButton, "pushButton_retry").clicked.connect(self.retry)
self.find(QPushButton, "pushButton_cancel")\
.clicked.connect(self.reject)
def setup_thread(self):
self._worker = Worker(self._study, self._checker_list)
self._worker_thread = QThread()
self._worker.moveToThread(self._worker_thread)
# Connect any worker signals
self._worker.signalStatus.connect(self.update)
self._worker_thread.started.connect(self._worker.process)
self._worker_thread.start()
def retry(self):
self._worker_thread.terminate()
self._worker_thread.wait()
self.find(QPushButton, "pushButton_retry").setEnabled(False)
self.find(QPushButton, "pushButton_ok").setEnabled(False)
self.setup_thread()
def _compute_status(self):
ok = len(list(filter(lambda c: c.is_ok(), self._checker_list)))
warning = len(
list(filter(lambda c: c.is_warning(), self._checker_list)))
error = len(list(filter(lambda c: c.is_error(), self._checker_list)))
return ok, warning, error
def _compute_status_label(self):
ok, warning, error = self._compute_status()
return (f"<font color=\"Green\">Ok: {ok} </font> |" +
f"<font color=\"Orange\">Warning: {warning} </font> |" +
f"<font color=\"Red\">Error: {error}</font>")
def setup_statusbar(self):
txt = self._compute_status_label()
self._status_label = QLabel(txt)
self.statusbar.addPermanentWidget(self._status_label)
def update_statusbar(self):
txt = self._compute_status_label()
self._status_label.setText(txt)
def progress(self):
self._p += 1
self._progress.setValue(self._p)
self._table.update()
def start_compute(self):
self._p = 0
self._progress.setValue(self._p)
def info_compute(self, str):
self.statusbar.showMessage(str, 3000)
def end_compute(self):
self._table.layoutChanged.emit()
self.find(QPushButton, "pushButton_retry").setEnabled(True)
errors = any(filter(lambda c: c.is_error(), self._checker_list))
if not errors:
self.find(QPushButton, "pushButton_ok").setEnabled(True)
if self._autorun:
self._parent.solver_log(self._solver)
self.update_statusbar()
def update(self, key: str):
if key == "start":
self.start_compute()
self.info_compute("Starting ...")
elif key == "end":
self.info_compute("Finish")
self.end_compute()
elif key == "progress":
self.progress()
else:
self.info_compute(key)
self.update_statusbar()
def end(self):
# self._worker.join()b
self.close()
def reject(self):
self.end()
def accept(self):
self._parent.solver_log(self._solver)
# self.end()