From a2e0f6a517d5de2a30a7b910f835451b991d0050 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Thu, 17 Sep 2026 16:07:46 +0200 Subject: [PATCH] Ensemble: Add base of edit dialog. --- src/View/Ensembles/Edit/Window.py | 94 ++++++++++++++++ src/View/Ensembles/Translate.py | 2 +- src/View/Ensembles/Window.py | 21 ++-- src/View/ui/Ensemble1ParamsWidget.ui | 35 ++++++ src/View/ui/Ensemble2ParamsWidget.ui | 41 +++++++ src/View/ui/EnsembleEditDialog.ui | 157 +++++++++++++++++++++++++++ 6 files changed, 335 insertions(+), 15 deletions(-) create mode 100644 src/View/Ensembles/Edit/Window.py create mode 100644 src/View/ui/Ensemble1ParamsWidget.ui create mode 100644 src/View/ui/Ensemble2ParamsWidget.ui create mode 100644 src/View/ui/EnsembleEditDialog.ui diff --git a/src/View/Ensembles/Edit/Window.py b/src/View/Ensembles/Edit/Window.py new file mode 100644 index 00000000..39712c7a --- /dev/null +++ b/src/View/Ensembles/Edit/Window.py @@ -0,0 +1,94 @@ +# Window.py -- Pamhyr +# Copyright (C) 2023-2026 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 . + +# -*- coding: utf-8 -*- + +import logging + +from tools import trace, timer, logger_exception + +from View.Tools.PamhyrWindow import PamhyrWindow, PamhyrDialog +from View.Tools.PamhyrWidget import PamhyrWidget + +from PyQt5.QtGui import ( + QKeySequence, +) + +from PyQt5 import QtWidgets +from PyQt5.QtCore import ( + Qt, QVariant, QAbstractTableModel, + QCoreApplication, QModelIndex, pyqtSlot, + QRect, QSettings, +) + +from PyQt5.QtWidgets import ( + QDialogButtonBox, QPushButton, QLineEdit, + QFileDialog, QTableView, QAbstractItemView, + QUndoStack, QShortcut, QAction, QItemDelegate, + QComboBox, QVBoxLayout, QHeaderView, QTabWidget, +) + +logger = logging.getLogger() + + +class EnsembleEditDialog(PamhyrDialog): + _pamhyr_ui = "EnsembleEditDialog" + _pamhyr_name = "Parameters" + + def __init__(self, study=None, ensemble=None, + trad=None, parent=None): + super(EnsembleEditDialog, self).__init__( + title=trad[self._pamhyr_name], + trad=trad, + options=[], + parent=parent + ) + + self._study = study + self._ensemble = ensemble + + self._init_default_parameters_widget() + self._init_default_values() + + def _init_default_parameters_widget(self): + pass + + def _init_default_values(self): + self.set_line_edit_text("lineEdit_name", self._ensemble.name) + + self.combobox_add_items( + "comboBox_distribution", + list( + map( + lambda f: f.name, + self._study._ens_distributions.lst + ) + ) + ) + if self._ensemble.distribution is not None: + self.set_combobox_text("comboBox_distribution", + self._ensemble.distribution.name) + + @property + def values(self): + return self._values + + def accept(self): + self._values = [] + super().accept() + + def reject(self): + self.close() diff --git a/src/View/Ensembles/Translate.py b/src/View/Ensembles/Translate.py index 7ff43f98..801983b2 100644 --- a/src/View/Ensembles/Translate.py +++ b/src/View/Ensembles/Translate.py @@ -1,4 +1,4 @@ -# translate.py -- Pamhyr +# Translate.py -- Pamhyr # Copyright (C) 2023-2026 INRAE # # This program is free software: you can redistribute it and/or modify diff --git a/src/View/Ensembles/Window.py b/src/View/Ensembles/Window.py index 739af7cf..30a3fd3a 100644 --- a/src/View/Ensembles/Window.py +++ b/src/View/Ensembles/Window.py @@ -42,6 +42,7 @@ from PyQt5.QtWidgets import ( from Modules import Modules +from View.Ensembles.Edit.Window import EnsembleEditDialog from View.Ensembles.Table import ( EnsembleTableModel, ComboBoxDelegate ) @@ -185,20 +186,12 @@ class EnsemblesWindow(PamhyrWindow): for row in rows: try: ens = self._ensembles.get(row) - len_params = len(ens.distribution.labels) - - if len_params == 1: - dlg = Ensemble1ParamsDialog( - ensemble=ens, - trad=self._trad, - parent=self - ) - else: - dlg = Ensemble2ParamsDialog( - ensemble=ens, - trad=self._trad, - parent=self - ) + dlg = EnsembleEditDialog( + study=self._study, + ensemble=ens, + trad=self._trad, + parent=self + ) if dlg.exec(): self._ensembles.get(row).params = dlg._values diff --git a/src/View/ui/Ensemble1ParamsWidget.ui b/src/View/ui/Ensemble1ParamsWidget.ui new file mode 100644 index 00000000..f9c429a9 --- /dev/null +++ b/src/View/ui/Ensemble1ParamsWidget.ui @@ -0,0 +1,35 @@ + + + Form + + + + 0 + 0 + 482 + 48 + + + + Form + + + + + + + + Parameter 1 + + + + + + + + + + + + + diff --git a/src/View/ui/Ensemble2ParamsWidget.ui b/src/View/ui/Ensemble2ParamsWidget.ui new file mode 100644 index 00000000..55c879ce --- /dev/null +++ b/src/View/ui/Ensemble2ParamsWidget.ui @@ -0,0 +1,41 @@ + + + Form + + + + 0 + 0 + 416 + 80 + + + + Form + + + + + + Parameter 1 + + + + + + + + + + Parameter 2 + + + + + + + + + + + diff --git a/src/View/ui/EnsembleEditDialog.ui b/src/View/ui/EnsembleEditDialog.ui new file mode 100644 index 00000000..05975f3a --- /dev/null +++ b/src/View/ui/EnsembleEditDialog.ui @@ -0,0 +1,157 @@ + + + Dialog + + + + 0 + 0 + 875 + 415 + + + + Dialog + + + + + + Name + + + + + + + + + + Distribution + + + + + + + + + + Qt::Horizontal + + + + 313 + 20 + + + + + + + + Target data + + + + + + + 1 + + + + + + + + + + + Parameters + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +