From 98ee3ee6eca0b845320238d29766cb11e926dc9c Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Mon, 16 Oct 2023 17:25:08 +0200 Subject: [PATCH] CustomPlot: Add translation. --- .../CustomPlotValuesSelectionDialog.py | 36 +++++++---- src/View/Results/CustomPlot/Translate.py | 61 +++++++++++++++++++ 2 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 src/View/Results/CustomPlot/Translate.py diff --git a/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py b/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py index d2e3a3e8..1ffd6732 100644 --- a/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py +++ b/src/View/Results/CustomPlot/CustomPlotValuesSelectionDialog.py @@ -1,4 +1,4 @@ -# CustomPlotValueSelectionDialog.py -- Pamhyr +# CustomPlotValuesSelectionDialog.py -- Pamhyr # Copyright (C) 2023 INRAE # # This program is free software: you can redistribute it and/or modify @@ -22,6 +22,9 @@ from PyQt5.QtWidgets import ( QRadioButton, QCheckBox, QVBoxLayout, ) +from View.Results.CustomPlot.Translate import CustomPlotTranslate + + class CustomPlotValuesSelectionDialog(PamhyrDialog): _pamhyr_ui = "CustomPlotValuesSelectionDialog" _pamhyr_name = "Custom Plot Selection" @@ -30,11 +33,12 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog): super(CustomPlotValuesSelectionDialog, self).__init__( title=self._pamhyr_name, options=[], + trad=CustomPlotTranslate(), parent=parent ) - self._available_values_x = ['foo', 'bar'] - self._available_values_y = ['bar', 'baz'] + self._available_values_x = self._trad.get_dict("values_x") + self._available_values_y = self._trad.get_dict("values_y") self.setup_radio_buttons() self.setup_check_boxs() @@ -46,11 +50,14 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog): layout = self.find(QVBoxLayout, "verticalLayout_x") for value in self._available_values_x: - btn = QRadioButton(value, parent=self) - self._radio.append(btn) + btn = QRadioButton( + self._available_values_x[value], + parent=self + ) + self._radio.append((value, btn)) layout.addWidget(btn) - self._radio[0].setChecked(True) + self._radio[0][1].setChecked(True) layout.addStretch() def setup_check_boxs(self): @@ -58,26 +65,29 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog): layout = self.find(QVBoxLayout, "verticalLayout_y") for value in self._available_values_y: - btn = QCheckBox(value, parent=self) - self._check.append(btn) + btn = QCheckBox( + self._available_values_y[value], + parent=self + ) + self._check.append((value, btn)) layout.addWidget(btn) - self._check[0].setChecked(True) + self._check[0][1].setChecked(True) layout.addStretch() def accept(self): x = next( filter( - lambda r: r.isChecked(), + lambda r: r[1].isChecked(), self._radio ) - ).text() + )[0] y = list( map( - lambda b: b.text(), + lambda b: b[0], filter( - lambda b: b.isChecked(), + lambda b: b[1].isChecked(), self._check ) ) diff --git a/src/View/Results/CustomPlot/Translate.py b/src/View/Results/CustomPlot/Translate.py new file mode 100644 index 00000000..11c3187e --- /dev/null +++ b/src/View/Results/CustomPlot/Translate.py @@ -0,0 +1,61 @@ +# Translate.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 <https://www.gnu.org/licenses/>. + +# -*- coding: utf-8 -*- + +from PyQt5.QtCore import QCoreApplication + +from View.Results.translate import ResultsTranslate + +_translate = QCoreApplication.translate + + +class CustomPlotTranslate(ResultsTranslate): + def __init__(self): + super(CustomPlotTranslate, self).__init__() + + self._dict['time'] = _translate( + "CustomPlot", "Time (sec)" + ) + + self._dict['kp'] = _translate( + "CustomPlot", "Kp (m)" + ) + + self._dict['elevation'] = _translate( + "CustomPlot", "Elevation (m)" + ) + + self._dict['water_elevation'] = _translate( + "CustomPlot", "Water elevation (m)" + ) + + self._dict['discharge'] = _translate( + "CustomPlot", "Discharge (m³/s)" + ) + + # SubDict + + self._sub_dict["values_x"] = { + "kp": self._dict["kp"], + "time": self._dict["time"], + } + + self._sub_dict["values_y"] = { + "elevation": self._dict["elevation"], + "water_elevation": self._dict["water_elevation"], + "discharge": self._dict["discharge"], + } -- GitLab