mirror of https://gitlab.com/pamhyr/pamhyr2
136 lines
3.7 KiB
Python
136 lines
3.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import time
|
|
import threading
|
|
|
|
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, pyqtSlot,
|
|
QRect,
|
|
)
|
|
|
|
from PyQt5.QtWidgets import (
|
|
QDialogButtonBox, QPushButton, QLineEdit,
|
|
QFileDialog, QTableView, QAbstractItemView,
|
|
QUndoStack, QShortcut, QAction, QItemDelegate,
|
|
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
|
QProgressBar,
|
|
)
|
|
|
|
from View.CheckList.Table import TableModel
|
|
|
|
_translate = QCoreApplication.translate
|
|
|
|
def _run_checker_list(study, checker_list, parent):
|
|
parent.start_compute()
|
|
for checker in checker_list:
|
|
time.sleep(1)
|
|
checker.run(study)
|
|
parent.progress()
|
|
parent.end_compute()
|
|
|
|
class CheckListWindow(ASubMainWindow, ListedSubWindow):
|
|
def __init__(self, title="Check list",
|
|
study=None, config=None,
|
|
solver=None, parent=None):
|
|
self._title = title + " - " + study.name
|
|
|
|
self._study = study
|
|
self._config = config
|
|
self._solver = solver
|
|
|
|
super(CheckListWindow, self).__init__(
|
|
name=self._title, ui="CheckList", parent=parent
|
|
)
|
|
self.ui.setWindowTitle(self._title)
|
|
|
|
self._checker_list = (
|
|
self._study.checkers() + self._solver.checkers()
|
|
)
|
|
|
|
self.setup_table()
|
|
self.setup_progress_bar()
|
|
self.setup_connections()
|
|
self.setup_thread()
|
|
|
|
def setup_table(self):
|
|
table = self.find(QTableView, f"tableView")
|
|
|
|
self._table = TableModel(
|
|
data = self._checker_list,
|
|
)
|
|
|
|
table.setModel(self._table)
|
|
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
|
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|
table.setAlternatingRowColors(True)
|
|
|
|
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._t1 = threading.Thread(
|
|
target=_run_checker_list,
|
|
args=(self._study, self._checker_list, self,)
|
|
)
|
|
self._t1.start()
|
|
|
|
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 end_compute(self):
|
|
self._table.layoutChanged.emit()
|
|
self.find(QPushButton, "pushButton_retry").setEnabled(True)
|
|
|
|
errors = list(filter(lambda c: c.is_error(), self._checker_list))
|
|
if len(errors) == 0:
|
|
self.find(QPushButton, "pushButton_ok").setEnabled(True)
|
|
|
|
def end(self):
|
|
# self._t1.join()
|
|
self.close()
|
|
|
|
def retry(self):
|
|
self._t1.join()
|
|
self._t1 = threading.Thread(
|
|
target=_run_checker_list,
|
|
args=(self._study, self._checker_list, self,)
|
|
)
|
|
|
|
self.find(QPushButton, "pushButton_retry").setEnabled(False)
|
|
self.find(QPushButton, "pushButton_ok").setEnabled(False)
|
|
|
|
self._t1.start()
|
|
|
|
def reject(self):
|
|
print("cancel")
|
|
self.end()
|
|
|
|
def accept(self):
|
|
print("ok")
|
|
self.end()
|