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):
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
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,6 +112,7 @@ class PamhyrTableModel(QAbstractTableModel):
|
|||
|
||||
def _table_view_configure(self):
|
||||
self._table_view.setModel(self)
|
||||
if "rows_selection" in self._options:
|
||||
self._table_view.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
self._table_view.horizontalHeader()\
|
||||
.setSectionResizeMode(QHeaderView.Stretch)
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue