diff --git a/src/View/CheckList/List.py b/src/View/CheckList/List.py new file mode 100644 index 0000000000000000000000000000000000000000..3afae091ee7b4eb4d55405f1f0892065682b721b --- /dev/null +++ b/src/View/CheckList/List.py @@ -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() diff --git a/src/View/CheckList/Table.py b/src/View/CheckList/Table.py index b882eda249f8c593d93dd0beb280c71433d3b682..e160eff50676c21e3e041fdfc4dc9cf41941b57e 100644 --- a/src/View/CheckList/Table.py +++ b/src/View/CheckList/Table.py @@ -78,7 +78,7 @@ class TabTableModel(PamhyrTableModel): def _setup_lst(self): self._lst = self._opt_data - def compute_status(self, row, column): + def get_checkers(self, row, column): module = self._opt_data[row] solver = self._headers[column] @@ -89,6 +89,23 @@ class TabTableModel(PamhyrTableModel): 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( map( lambda c: c._status, diff --git a/src/View/MainWindowTabChecker.py b/src/View/MainWindowTabChecker.py index 30cfb29f02980230337ed35815f93491b0530312..1cab46f90a117db5c7b0818e1a3879b588e09eec 100644 --- a/src/View/MainWindowTabChecker.py +++ b/src/View/MainWindowTabChecker.py @@ -26,7 +26,7 @@ from PyQt5.QtCore import ( ) from PyQt5.QtWidgets import ( - QTableView, + QTableView, QListView, ) 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.CheckList.Table import TabTableModel +from View.CheckList.List import TabListModel from View.CheckList.Worker import TabWorker logger = logging.getLogger() @@ -56,6 +57,7 @@ class WidgetChecker(PamhyrWidget): self.setup_checker_list() self.setup_table() self.setup_list() + self.setup_connections() def setup_worker(self): self._worker_q = Queue() @@ -81,7 +83,7 @@ class WidgetChecker(PamhyrWidget): self._checkers = flatten( map( lambda solver: solver.checkers(), - self._solvers + [Study] + [Study] + self._solvers ) ) @@ -96,11 +98,29 @@ class WidgetChecker(PamhyrWidget): table_view=table, table_headers=header, data=self._checkers, - opt_data=Modules.modelling_list() + opt_data=Modules.modelling_list(), + options=[], ) 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 def study(self): @@ -116,9 +136,29 @@ class WidgetChecker(PamhyrWidget): 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): if key == "progress": 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): if modules is Modules.NONE: diff --git a/src/View/Tools/PamhyrList.py b/src/View/Tools/PamhyrList.py new file mode 100644 index 0000000000000000000000000000000000000000..8ed8d15ce5d6ffddd0a989e78ef6f4f5aafa73f8 --- /dev/null +++ b/src/View/Tools/PamhyrList.py @@ -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() diff --git a/src/View/Tools/PamhyrTable.py b/src/View/Tools/PamhyrTable.py index e013652afcc78793db8d2f15e4197e5838040d26..64a433ee634c40eac0a5f7505142a15de8d46614 100644 --- a/src/View/Tools/PamhyrTable.py +++ b/src/View/Tools/PamhyrTable.py @@ -84,6 +84,7 @@ class PamhyrTableModel(QAbstractTableModel): data=None, undo=None, opt_data=None, + options=["rows_selection"], parent=None): super(PamhyrTableModel, self).__init__() @@ -98,6 +99,7 @@ class PamhyrTableModel(QAbstractTableModel): self._data = data self._opt_data = opt_data + self._options = options self._undo = undo self._lst = [] @@ -110,7 +112,8 @@ class PamhyrTableModel(QAbstractTableModel): def _table_view_configure(self): self._table_view.setModel(self) - self._table_view.setSelectionBehavior(QAbstractItemView.SelectRows) + if "rows_selection" in self._options: + self._table_view.setSelectionBehavior(QAbstractItemView.SelectRows) self._table_view.horizontalHeader()\ .setSectionResizeMode(QHeaderView.Stretch) self._table_view.setAlternatingRowColors(True) diff --git a/src/View/ui/Widgets/MainWindowTabCheckers.ui b/src/View/ui/Widgets/MainWindowTabCheckers.ui index 5a0a30231ef695622527d2adf6b263740d2e008a..89bb9767a58f29574e5e8a4d68aad37011e9cd95 100644 --- a/src/View/ui/Widgets/MainWindowTabCheckers.ui +++ b/src/View/ui/Widgets/MainWindowTabCheckers.ui @@ -64,7 +64,7 @@ </property> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> - <widget class="QListView" name="listView_message"/> + <widget class="QListView" name="listView_errors"/> </item> </layout> </widget>