From b77aed23952d5bc0f8634d6d5a3f086c5ca1da67 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Mon, 16 Oct 2023 15:52:29 +0200 Subject: [PATCH] results: Add custom plot dialog scheme. --- .../CustomPlotValuesSelectionDialog.py | 87 +++++++++++++++++ src/View/Results/Window.py | 21 +++++ .../ui/CustomPlotValuesSelectionDialog.ui | 93 +++++++++++++++++++ src/View/ui/Results.ui | 24 +++++ 4 files changed, 225 insertions(+) create mode 100644 src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py create mode 100644 src/View/ui/CustomPlotValuesSelectionDialog.ui diff --git a/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py b/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py new file mode 100644 index 00000000..d2e3a3e8 --- /dev/null +++ b/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py @@ -0,0 +1,87 @@ +# CustomPlotValueSelectionDialog.py -- Pamhyr +# Copyright (C) 2023 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.QtWidgets import ( + QRadioButton, QCheckBox, QVBoxLayout, +) + +class CustomPlotValuesSelectionDialog(PamhyrDialog): + _pamhyr_ui = "CustomPlotValuesSelectionDialog" + _pamhyr_name = "Custom Plot Selection" + + def __init__(self, parent=None): + super(CustomPlotValuesSelectionDialog, self).__init__( + title=self._pamhyr_name, + options=[], + parent=parent + ) + + self._available_values_x = ['foo', 'bar'] + self._available_values_y = ['bar', 'baz'] + + self.setup_radio_buttons() + self.setup_check_boxs() + + self.value = None + + def setup_radio_buttons(self): + self._radio = [] + layout = self.find(QVBoxLayout, "verticalLayout_x") + + for value in self._available_values_x: + btn = QRadioButton(value, parent=self) + self._radio.append(btn) + layout.addWidget(btn) + + self._radio[0].setChecked(True) + layout.addStretch() + + def setup_check_boxs(self): + self._check = [] + layout = self.find(QVBoxLayout, "verticalLayout_y") + + for value in self._available_values_y: + btn = QCheckBox(value, parent=self) + self._check.append(btn) + layout.addWidget(btn) + + self._check[0].setChecked(True) + layout.addStretch() + + def accept(self): + x = next( + filter( + lambda r: r.isChecked(), + self._radio + ) + ).text() + + y = list( + map( + lambda b: b.text(), + filter( + lambda b: b.isChecked(), + self._check + ) + ) + ) + + self.value = x, y + super().accept() diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py index 15167fd3..353a036c 100644 --- a/src/View/Results/Window.py +++ b/src/View/Results/Window.py @@ -51,6 +51,10 @@ from View.Results.PlotH import PlotH from View.Results.PlotSedReach import PlotSedReach from View.Results.PlotSedProfile import PlotSedProfile +from View.Results.CustomPlot.CustomPlotValuesSelectionDialog import ( + CustomPlotValuesSelectionDialog, +) + from View.Results.Table import TableModel from View.Results.translate import ResultsTranslate from View.Stricklers.Window import StricklersWindow @@ -272,6 +276,17 @@ class ResultsWindow(PamhyrWindow): self._status_label.setText(txt) def setup_connections(self): + # Action + actions = { + "action_add": self._add_custom_plot + } + + for action in actions: + self.find(QAction, action).triggered.connect( + actions[action] + ) + + # Table and Plot fun = { "reach": self._set_current_reach, "profile": self._set_current_profile, @@ -390,6 +405,12 @@ class ResultsWindow(PamhyrWindow): timestamp = self._timestamps[self._slider_time.value()] self.update(timestamp=timestamp) + def _add_custom_plot(self): + dlg = CustomPlotValuesSelectionDialog(parent=self) + if dlg.exec(): + value = dlg.value + logger.info(value) + def _copy(self): logger.info("TODO: copy") diff --git a/src/View/ui/CustomPlotValuesSelectionDialog.ui b/src/View/ui/CustomPlotValuesSelectionDialog.ui new file mode 100644 index 00000000..88ca363c --- /dev/null +++ b/src/View/ui/CustomPlotValuesSelectionDialog.ui @@ -0,0 +1,93 @@ + + + Dialog + + + + 0 + 0 + 414 + 482 + + + + Dialog + + + + + + Qt::Horizontal + + + + + + + X axis: + + + + + + + + + + + Y axis: + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/View/ui/Results.ui b/src/View/ui/Results.ui index 5b797724..08920821 100644 --- a/src/View/ui/Results.ui +++ b/src/View/ui/Results.ui @@ -140,6 +140,30 @@ + + + toolBar + + + TopToolBarArea + + + false + + + + + + + ressources/gtk-add.pngressources/gtk-add.png + + + Add + + + Add custom visualization + +