From 14b5b5e3df7c736fb7df727a581e9d29243d77c8 Mon Sep 17 00:00:00 2001 From: Theophile Terraz Date: Tue, 21 May 2024 17:01:54 +0200 Subject: [PATCH] add purge dialog --- src/View/Geometry/Profile/Table.py | 4 +- src/View/Geometry/Profile/Window.py | 20 ++++++- src/View/Geometry/PurgeDialog.py | 60 ++++++++++++++++++++ src/View/Geometry/Table.py | 4 +- src/View/Geometry/UpdateKPDialog.py | 2 +- src/View/Geometry/Window.py | 13 +++++ src/View/ui/PurgeOptions.ui | 86 +++++++++++++++++++++++++++++ 7 files changed, 182 insertions(+), 7 deletions(-) create mode 100644 src/View/Geometry/PurgeDialog.py create mode 100644 src/View/ui/PurgeOptions.ui diff --git a/src/View/Geometry/Profile/Table.py b/src/View/Geometry/Profile/Table.py index 5974eb7c..141545fa 100644 --- a/src/View/Geometry/Profile/Table.py +++ b/src/View/Geometry/Profile/Table.py @@ -230,11 +230,11 @@ class GeometryProfileTableModel(PamhyrTableModel): self.endMoveRows() self.layoutChanged.emit() - def purge(self): + def purge(self, np_purge): self._undo.push( PurgeCommand( - self._data, 24 + self._data, np_purge ) ) diff --git a/src/View/Geometry/Profile/Window.py b/src/View/Geometry/Profile/Window.py index 655096d7..e93eccff 100644 --- a/src/View/Geometry/Profile/Window.py +++ b/src/View/Geometry/Profile/Window.py @@ -20,8 +20,9 @@ import copy import sys import csv from time import time +import logging -from tools import trace, timer +from tools import trace, timer, logger_exception from Modules import Modules from PyQt5.QtGui import ( @@ -46,9 +47,12 @@ from View.Tools.Plot.PamhyrCanvas import MplCanvas from View.Geometry.Profile.Plot import Plot from View.Geometry.Profile.Table import GeometryProfileTableModel from View.Geometry.Profile.Translate import GeometryProfileTranslate +from View.Geometry.PurgeDialog import PurgeDialog _translate = QCoreApplication.translate +logger = logging.getLogger() + class ProfileWindow(PamhyrWindow): _pamhyr_ui = "GeometryCrossSection" @@ -165,7 +169,6 @@ class ProfileWindow(PamhyrWindow): if Modules.GEOMETRY not in key: return - logger.debug("TOTO") self._tablemodel.layoutChanged.emit() self._update(redraw=True, propagate=False) @@ -258,6 +261,19 @@ class ProfileWindow(PamhyrWindow): self._tablemodel.purge() self.update() + def purge(self): + try: + dlg = PurgeDialog( + trad=self._trad, + parent=self + ) + if dlg.exec(): + self._tablemodel.purge(dlg.np_purge) + self._plot.draw() + except Exception as e: + logger_exception(e) + return + def reverse(self): self._tablemodel.reverse() self.update() diff --git a/src/View/Geometry/PurgeDialog.py b/src/View/Geometry/PurgeDialog.py new file mode 100644 index 00000000..af4fcc34 --- /dev/null +++ b/src/View/Geometry/PurgeDialog.py @@ -0,0 +1,60 @@ +# PurgeDialog.py -- Pamhyr +# Copyright (C) 2023-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 . + +# -*- coding: utf-8 -*- + +from View.Tools.PamhyrWindow import PamhyrDialog + +from PyQt5.QtGui import ( + QKeySequence, +) + +from PyQt5.QtCore import ( + Qt, QVariant, QAbstractTableModel, +) + +from PyQt5.QtWidgets import ( + QUndoStack, QShortcut, QSpinBox, +) + + +class PurgeDialog(PamhyrDialog): + _pamhyr_ui = "PurgeOptions" + _pamhyr_name = "Purge" + + def __init__(self, trad=None, parent=None): + super(PurgeDialog, self).__init__( + title=trad[self._pamhyr_name], + trad=trad, + options=[], + parent=parent + ) + + self._init_default_values() + + def _init_default_values(self): + self._np_purge = 24 + + @property + def np_purge(self): + return self._np_purge + + def accept(self): + self._np_purge = self.get_spin_box("spinBox_np_purge") + super().accept() + + def reject(self): + self.close() diff --git a/src/View/Geometry/Table.py b/src/View/Geometry/Table.py index 3c5db448..4009af87 100644 --- a/src/View/Geometry/Table.py +++ b/src/View/Geometry/Table.py @@ -259,11 +259,11 @@ class GeometryReachTableModel(PamhyrTableModel): self.layoutAboutToBeChanged.emit() self.layoutChanged.emit() - def purge(self): + def purge(self, np_purge): self._undo.push( PurgeCommand( - self._data, 24 + self._data, np_purge ) ) self.layoutChanged.emit() diff --git a/src/View/Geometry/UpdateKPDialog.py b/src/View/Geometry/UpdateKPDialog.py index 87afc977..b1b0b307 100644 --- a/src/View/Geometry/UpdateKPDialog.py +++ b/src/View/Geometry/UpdateKPDialog.py @@ -1,4 +1,4 @@ -# MeshingDialog.py -- Pamhyr +# UpdateKPDialog.py -- Pamhyr # Copyright (C) 2023-2024 INRAE # # This program is free software: you can redistribute it and/or modify diff --git a/src/View/Geometry/Window.py b/src/View/Geometry/Window.py index b92ae373..055ea8c3 100644 --- a/src/View/Geometry/Window.py +++ b/src/View/Geometry/Window.py @@ -57,6 +57,7 @@ from View.Geometry.PlotAC import PlotAC from View.Geometry.PlotKPZ import PlotKPZ from View.Geometry.MeshingDialog import MeshingDialog from View.Geometry.UpdateKPDialog import UpdateKPDialog +from View.Geometry.PurgeDialog import PurgeDialog from View.Geometry.Translate import GeometryTranslate from View.Geometry.Profile.Window import ProfileWindow @@ -550,6 +551,18 @@ class GeometryWindow(PamhyrWindow): self._table.purge() self.update_redraw() + def purge(self): + try: + dlg = PurgeDialog( + trad=self._trad, + parent=self + ) + if dlg.exec(): + self._table.purge(dlg.np_purge) + except Exception as e: + logger_exception(e) + return + def duplicate(self): rows = [ row.row() for row in diff --git a/src/View/ui/PurgeOptions.ui b/src/View/ui/PurgeOptions.ui new file mode 100644 index 00000000..9b027f97 --- /dev/null +++ b/src/View/ui/PurgeOptions.ui @@ -0,0 +1,86 @@ + + + Dialog + + + + 0 + 0 + 194 + 114 + + + + Dialog + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Number of points to keep + + + + + + 3 + + + 999999999 + + + 24 + + + + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +