mirror of https://gitlab.com/pamhyr/pamhyr2
MainWindow: Checker: Add lists.
parent
a23692a29c
commit
e343d284d9
|
|
@ -0,0 +1,67 @@
|
||||||
|
# List.py -- Pamhyr
|
||||||
|
# Copyright (C) 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 functools import reduce
|
||||||
|
from tools import trace, timer
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
Qt, QVariant,
|
||||||
|
)
|
||||||
|
|
||||||
|
from PyQt5.QtGui import (
|
||||||
|
QColor, QBrush,
|
||||||
|
)
|
||||||
|
|
||||||
|
from Modules import Modules
|
||||||
|
from Checker.Checker import STATUS
|
||||||
|
from View.Tools.PamhyrList import PamhyrListModel
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class TabListModel(PamhyrListModel):
|
||||||
|
def data(self, index, role):
|
||||||
|
row = index.row()
|
||||||
|
column = index.column()
|
||||||
|
|
||||||
|
checker = self._data[row]
|
||||||
|
|
||||||
|
if role == Qt.ForegroundRole:
|
||||||
|
color = Qt.gray
|
||||||
|
status = checker._status
|
||||||
|
|
||||||
|
if status is STATUS.OK:
|
||||||
|
color = Qt.green
|
||||||
|
elif status is STATUS.WARNING:
|
||||||
|
color = Qt.yellow
|
||||||
|
elif status is STATUS.ERROR:
|
||||||
|
color = Qt.red
|
||||||
|
|
||||||
|
return QBrush(color)
|
||||||
|
|
||||||
|
if role == Qt.ItemDataRole.DisplayRole:
|
||||||
|
msg = checker.name
|
||||||
|
|
||||||
|
if checker.is_error() or checker.is_warning():
|
||||||
|
msg += f": {checker.summary}"
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
|
return QVariant()
|
||||||
|
|
@ -78,7 +78,7 @@ class TabTableModel(PamhyrTableModel):
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = self._opt_data
|
self._lst = self._opt_data
|
||||||
|
|
||||||
def compute_status(self, row, column):
|
def get_checkers(self, row, column):
|
||||||
module = self._opt_data[row]
|
module = self._opt_data[row]
|
||||||
solver = self._headers[column]
|
solver = self._headers[column]
|
||||||
|
|
||||||
|
|
@ -89,6 +89,23 @@ class TabTableModel(PamhyrTableModel):
|
||||||
self._data
|
self._data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return checkers
|
||||||
|
|
||||||
|
def get_checkers_from_indexes(self, indexes):
|
||||||
|
lst = []
|
||||||
|
|
||||||
|
for index in indexes:
|
||||||
|
row = index.row()
|
||||||
|
column = index.column()
|
||||||
|
|
||||||
|
lst += list(self.get_checkers(row, column))
|
||||||
|
|
||||||
|
return lst
|
||||||
|
|
||||||
|
def compute_status(self, row, column):
|
||||||
|
checkers = self.get_checkers(row, column)
|
||||||
|
|
||||||
checkers_status = list(
|
checkers_status = list(
|
||||||
map(
|
map(
|
||||||
lambda c: c._status,
|
lambda c: c._status,
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ from PyQt5.QtCore import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QTableView,
|
QTableView, QListView,
|
||||||
)
|
)
|
||||||
|
|
||||||
from Modules import Modules
|
from Modules import Modules
|
||||||
|
|
@ -35,6 +35,7 @@ from Solver.Solvers import solver_type_list, solver_long_name
|
||||||
|
|
||||||
from View.Tools.PamhyrWidget import PamhyrWidget
|
from View.Tools.PamhyrWidget import PamhyrWidget
|
||||||
from View.CheckList.Table import TabTableModel
|
from View.CheckList.Table import TabTableModel
|
||||||
|
from View.CheckList.List import TabListModel
|
||||||
from View.CheckList.Worker import TabWorker
|
from View.CheckList.Worker import TabWorker
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
@ -56,6 +57,7 @@ class WidgetChecker(PamhyrWidget):
|
||||||
self.setup_checker_list()
|
self.setup_checker_list()
|
||||||
self.setup_table()
|
self.setup_table()
|
||||||
self.setup_list()
|
self.setup_list()
|
||||||
|
self.setup_connections()
|
||||||
|
|
||||||
def setup_worker(self):
|
def setup_worker(self):
|
||||||
self._worker_q = Queue()
|
self._worker_q = Queue()
|
||||||
|
|
@ -81,7 +83,7 @@ class WidgetChecker(PamhyrWidget):
|
||||||
self._checkers = flatten(
|
self._checkers = flatten(
|
||||||
map(
|
map(
|
||||||
lambda solver: solver.checkers(),
|
lambda solver: solver.checkers(),
|
||||||
self._solvers + [Study]
|
[Study] + self._solvers
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -96,11 +98,29 @@ class WidgetChecker(PamhyrWidget):
|
||||||
table_view=table,
|
table_view=table,
|
||||||
table_headers=header,
|
table_headers=header,
|
||||||
data=self._checkers,
|
data=self._checkers,
|
||||||
opt_data=Modules.modelling_list()
|
opt_data=Modules.modelling_list(),
|
||||||
|
options=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
def setup_list(self):
|
def setup_list(self):
|
||||||
return
|
lst = self.find(QListView, f"listView_current")
|
||||||
|
self._list = TabListModel(
|
||||||
|
list_view=lst,
|
||||||
|
data=[],
|
||||||
|
)
|
||||||
|
|
||||||
|
lst = self.find(QListView, f"listView_errors")
|
||||||
|
self._list_error = TabListModel(
|
||||||
|
list_view=lst,
|
||||||
|
data=[],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_connections(self):
|
||||||
|
table = self.find(QTableView, f"tableView_checker")
|
||||||
|
table.selectionModel()\
|
||||||
|
.selectionChanged\
|
||||||
|
.connect(self.update_selection)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def study(self):
|
def study(self):
|
||||||
|
|
@ -116,9 +136,29 @@ class WidgetChecker(PamhyrWidget):
|
||||||
self._checkers
|
self._checkers
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def update_selection(self):
|
||||||
|
table = self.find(QTableView, f"tableView_checker")
|
||||||
|
indexes = table.selectedIndexes()
|
||||||
|
|
||||||
|
checkers = self._table.get_checkers_from_indexes(indexes)
|
||||||
|
self._list._data = checkers
|
||||||
|
self._list.update()
|
||||||
|
|
||||||
def update_thread(self, key):
|
def update_thread(self, key):
|
||||||
if key == "progress":
|
if key == "progress":
|
||||||
self._table.update()
|
self._table.update()
|
||||||
|
self.update_errors()
|
||||||
|
|
||||||
|
def update_errors(self):
|
||||||
|
checkers = list(
|
||||||
|
filter(
|
||||||
|
lambda c: c.is_error() or c.is_warning(),
|
||||||
|
self._checkers
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self._list_error._data = checkers
|
||||||
|
self._list_error.update()
|
||||||
|
|
||||||
def update(self, modules=Modules.NONE):
|
def update(self, modules=Modules.NONE):
|
||||||
if modules is Modules.NONE:
|
if modules is Modules.NONE:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
# PamhyrList.py -- Pamhyr
|
||||||
|
# Copyright (C) 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
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from tools import trace, timer
|
||||||
|
|
||||||
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
Qt, QVariant,
|
||||||
|
QAbstractListModel,
|
||||||
|
QModelIndex,
|
||||||
|
)
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import (
|
||||||
|
QAbstractItemView,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
class PamhyrListModel(QAbstractListModel):
|
||||||
|
def __init__(self,
|
||||||
|
list_view=None,
|
||||||
|
trad=None,
|
||||||
|
data=None,
|
||||||
|
undo=None,
|
||||||
|
opt_data=None,
|
||||||
|
options=[],
|
||||||
|
parent=None):
|
||||||
|
super(PamhyrListModel, self).__init__()
|
||||||
|
|
||||||
|
self._list_view = list_view
|
||||||
|
|
||||||
|
self._trad = trad
|
||||||
|
self._parent = parent
|
||||||
|
|
||||||
|
self._data = data
|
||||||
|
self._opt_data = opt_data
|
||||||
|
self._options = options
|
||||||
|
self._undo = undo
|
||||||
|
|
||||||
|
self._list_view_configure()
|
||||||
|
|
||||||
|
def _list_view_configure(self):
|
||||||
|
self._list_view.setModel(self)
|
||||||
|
|
||||||
|
def rowCount(self, parent=QModelIndex()):
|
||||||
|
return len(self._data)
|
||||||
|
|
||||||
|
def columnCount(self, parent=QModelIndex()):
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def data(self, index, role):
|
||||||
|
raise NotImplementedMethodeError(self, self.data)
|
||||||
|
|
||||||
|
def undo(self):
|
||||||
|
self._undo.undo()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def redo(self):
|
||||||
|
self._undo.redo()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
@ -84,6 +84,7 @@ class PamhyrTableModel(QAbstractTableModel):
|
||||||
data=None,
|
data=None,
|
||||||
undo=None,
|
undo=None,
|
||||||
opt_data=None,
|
opt_data=None,
|
||||||
|
options=["rows_selection"],
|
||||||
parent=None):
|
parent=None):
|
||||||
super(PamhyrTableModel, self).__init__()
|
super(PamhyrTableModel, self).__init__()
|
||||||
|
|
||||||
|
|
@ -98,6 +99,7 @@ class PamhyrTableModel(QAbstractTableModel):
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._opt_data = opt_data
|
self._opt_data = opt_data
|
||||||
|
self._options = options
|
||||||
self._undo = undo
|
self._undo = undo
|
||||||
self._lst = []
|
self._lst = []
|
||||||
|
|
||||||
|
|
@ -110,6 +112,7 @@ class PamhyrTableModel(QAbstractTableModel):
|
||||||
|
|
||||||
def _table_view_configure(self):
|
def _table_view_configure(self):
|
||||||
self._table_view.setModel(self)
|
self._table_view.setModel(self)
|
||||||
|
if "rows_selection" in self._options:
|
||||||
self._table_view.setSelectionBehavior(QAbstractItemView.SelectRows)
|
self._table_view.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
self._table_view.horizontalHeader()\
|
self._table_view.horizontalHeader()\
|
||||||
.setSectionResizeMode(QHeaderView.Stretch)
|
.setSectionResizeMode(QHeaderView.Stretch)
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QListView" name="listView_message"/>
|
<widget class="QListView" name="listView_errors"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue