Commit 98ee3ee6 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

CustomPlot: Add translation.

Showing with 84 additions and 13 deletions
+84 -13
# CustomPlotValueSelectionDialog.py -- Pamhyr # CustomPlotValuesSelectionDialog.py -- Pamhyr
# Copyright (C) 2023 INRAE # Copyright (C) 2023 INRAE
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
...@@ -22,6 +22,9 @@ from PyQt5.QtWidgets import ( ...@@ -22,6 +22,9 @@ from PyQt5.QtWidgets import (
QRadioButton, QCheckBox, QVBoxLayout, QRadioButton, QCheckBox, QVBoxLayout,
) )
from View.Results.CustomPlot.Translate import CustomPlotTranslate
class CustomPlotValuesSelectionDialog(PamhyrDialog): class CustomPlotValuesSelectionDialog(PamhyrDialog):
_pamhyr_ui = "CustomPlotValuesSelectionDialog" _pamhyr_ui = "CustomPlotValuesSelectionDialog"
_pamhyr_name = "Custom Plot Selection" _pamhyr_name = "Custom Plot Selection"
...@@ -30,11 +33,12 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog): ...@@ -30,11 +33,12 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog):
super(CustomPlotValuesSelectionDialog, self).__init__( super(CustomPlotValuesSelectionDialog, self).__init__(
title=self._pamhyr_name, title=self._pamhyr_name,
options=[], options=[],
trad=CustomPlotTranslate(),
parent=parent parent=parent
) )
self._available_values_x = ['foo', 'bar'] self._available_values_x = self._trad.get_dict("values_x")
self._available_values_y = ['bar', 'baz'] self._available_values_y = self._trad.get_dict("values_y")
self.setup_radio_buttons() self.setup_radio_buttons()
self.setup_check_boxs() self.setup_check_boxs()
...@@ -46,11 +50,14 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog): ...@@ -46,11 +50,14 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog):
layout = self.find(QVBoxLayout, "verticalLayout_x") layout = self.find(QVBoxLayout, "verticalLayout_x")
for value in self._available_values_x: for value in self._available_values_x:
btn = QRadioButton(value, parent=self) btn = QRadioButton(
self._radio.append(btn) self._available_values_x[value],
parent=self
)
self._radio.append((value, btn))
layout.addWidget(btn) layout.addWidget(btn)
self._radio[0].setChecked(True) self._radio[0][1].setChecked(True)
layout.addStretch() layout.addStretch()
def setup_check_boxs(self): def setup_check_boxs(self):
...@@ -58,26 +65,29 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog): ...@@ -58,26 +65,29 @@ class CustomPlotValuesSelectionDialog(PamhyrDialog):
layout = self.find(QVBoxLayout, "verticalLayout_y") layout = self.find(QVBoxLayout, "verticalLayout_y")
for value in self._available_values_y: for value in self._available_values_y:
btn = QCheckBox(value, parent=self) btn = QCheckBox(
self._check.append(btn) self._available_values_y[value],
parent=self
)
self._check.append((value, btn))
layout.addWidget(btn) layout.addWidget(btn)
self._check[0].setChecked(True) self._check[0][1].setChecked(True)
layout.addStretch() layout.addStretch()
def accept(self): def accept(self):
x = next( x = next(
filter( filter(
lambda r: r.isChecked(), lambda r: r[1].isChecked(),
self._radio self._radio
) )
).text() )[0]
y = list( y = list(
map( map(
lambda b: b.text(), lambda b: b[0],
filter( filter(
lambda b: b.isChecked(), lambda b: b[1].isChecked(),
self._check self._check
) )
) )
......
# 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"],
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment