mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
AdditionalFiles: Add model, view and solver export.
This commit is contained in:
1 parent
db416d25de
commit
48e30125bb
16 files changed
+801
-23
No files matched your search
@@ -0,0 +1,80 @@
|
||||
# Window.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 Modules import Modules
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QLabel, QPlainTextEdit, QPushButton,
|
||||
QCheckBox,
|
||||
)
|
||||
|
||||
from View.AdditionalFiles.Translate import AddFileTranslate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class EditAddFileWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "AdditionalFile"
|
||||
_pamhyr_name = "Edit additional file"
|
||||
|
||||
def __init__(self, study=None, config=None, add_file=None,
|
||||
trad=None, parent=None):
|
||||
|
||||
name = trad[self._pamhyr_name] + " - " + study.name
|
||||
super(EditAddFileWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
options=[],
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._add_file = add_file
|
||||
self._hash_data.append(self._add_file)
|
||||
|
||||
self.setup_values()
|
||||
self.setup_connection()
|
||||
|
||||
def setup_values(self):
|
||||
self.set_check_box("checkBox", self._add_file.enabled)
|
||||
self.set_line_edit_text("lineEdit_name", self._add_file.name)
|
||||
self.set_line_edit_text("lineEdit_path", self._add_file.path)
|
||||
self.set_plaintext_edit_text("plainTextEdit", self._add_file.text)
|
||||
|
||||
def setup_connection(self):
|
||||
self.find(QPushButton, "pushButton_cancel")\
|
||||
.clicked.connect(self.close)
|
||||
self.find(QPushButton, "pushButton_ok")\
|
||||
.clicked.connect(self.accept)
|
||||
|
||||
def accept(self):
|
||||
is_enabled = self.get_check_box("checkBox")
|
||||
name = self.get_line_edit_text("lineEdit_name")
|
||||
path = self.get_line_edit_text("lineEdit_path")
|
||||
text = self.get_plaintext_edit_text("plainTextEdit")
|
||||
|
||||
self._add_file.enabled = is_enabled
|
||||
self._add_file.name = name
|
||||
self._add_file.path = path
|
||||
self._add_file.text = text
|
||||
|
||||
self._propagate_update(key=Modules.ADDITIONAL_FILES)
|
||||
self.close()
|
||||
@@ -0,0 +1,71 @@
|
||||
# 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 View.Tools.PamhyrList import PamhyrListModel
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class ListModel(PamhyrListModel):
|
||||
def data(self, index, role):
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
file = self._data.files[row]
|
||||
|
||||
if role == Qt.ForegroundRole:
|
||||
color = Qt.gray
|
||||
|
||||
if file.is_enabled():
|
||||
color = QColor("black")
|
||||
else:
|
||||
color = QColor("grey")
|
||||
|
||||
return QBrush(color)
|
||||
|
||||
if role == Qt.ItemDataRole.DisplayRole:
|
||||
text = f"{file.name}: '{file.path}'"
|
||||
|
||||
if not file.is_enabled():
|
||||
text += " (disabled)"
|
||||
|
||||
return text
|
||||
|
||||
return QVariant()
|
||||
|
||||
def add(self, row):
|
||||
self._data.new(row)
|
||||
self.update()
|
||||
|
||||
def delete(self, rows):
|
||||
logger.info(f"add_files: delete {rows}")
|
||||
self._data.delete_i(rows)
|
||||
self.update()
|
||||
@@ -0,0 +1,35 @@
|
||||
# Translate.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 -*-
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
from View.Translate import MainTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class AddFileTranslate(MainTranslate):
|
||||
def __init__(self):
|
||||
super(AddFileTranslate, self).__init__()
|
||||
|
||||
self._dict["Additional files"] = _translate(
|
||||
"AdditionalFiles", "Additional files"
|
||||
)
|
||||
|
||||
self._dict["Edit additional file"] = _translate(
|
||||
"AdditionalFiles", "Edit additional file"
|
||||
)
|
||||
@@ -0,0 +1,104 @@
|
||||
# Window.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 -*-
|
||||
|
||||
from tools import trace, timer
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QAction, QListView,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from View.AdditionalFiles.List import ListModel
|
||||
from View.AdditionalFiles.Translate import AddFileTranslate
|
||||
from View.AdditionalFiles.Edit.Window import EditAddFileWindow
|
||||
|
||||
|
||||
class AddFileListWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "AdditionalFileList"
|
||||
_pamhyr_name = "Additional files"
|
||||
|
||||
def __init__(self, study=None, config=None,
|
||||
parent=None):
|
||||
trad = AddFileTranslate()
|
||||
name = trad[self._pamhyr_name] + " - " + study.name
|
||||
|
||||
super(AddFileListWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
trad=trad,
|
||||
options=[],
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self.setup_list()
|
||||
self.setup_connections()
|
||||
|
||||
def setup_list(self):
|
||||
lst = self.find(QListView, f"listView")
|
||||
self._list = ListModel(
|
||||
list_view=lst,
|
||||
data=self._study.river.additional_files,
|
||||
)
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_delete").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_edit").triggered.connect(self.edit)
|
||||
|
||||
def update(self):
|
||||
self._list.update()
|
||||
|
||||
def selected_rows(self):
|
||||
lst = self.find(QListView, f"listView")
|
||||
return list(map(lambda i: i.row(), lst.selectedIndexes()))
|
||||
|
||||
def add(self):
|
||||
rows = self.selected_rows()
|
||||
if len(rows) > 0:
|
||||
row = rows[0]
|
||||
else:
|
||||
row = 0
|
||||
|
||||
self._list.add(row)
|
||||
|
||||
def delete(self):
|
||||
rows = self.selected_rows()
|
||||
self._list.delete(rows)
|
||||
|
||||
def edit(self):
|
||||
rows = self.selected_rows()
|
||||
|
||||
for row in rows:
|
||||
add_file = self._study.river.additional_files.files[row]
|
||||
|
||||
if self.sub_window_exists(
|
||||
EditAddFileWindow,
|
||||
data=[self._study, self._config, add_file]
|
||||
):
|
||||
continue
|
||||
|
||||
win = EditAddFileWindow(
|
||||
study=self._study,
|
||||
config=self._config,
|
||||
add_file=add_file,
|
||||
trad=self._trad,
|
||||
parent=self,
|
||||
)
|
||||
win.show()
|
||||
Reference in new issue
Block a user