Pamhyr: Factorize some translate.

setup.py
Pierre-Antoine Rouby 2024-02-21 15:49:01 +01:00
parent b3a7e7f465
commit 2e158f4c1b
38 changed files with 274 additions and 239 deletions

View File

@ -18,7 +18,7 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
from View.BoundaryCondition.translate import BCTranslate from View.BoundaryCondition.translate import BCTranslate
@ -36,9 +36,9 @@ class BCETranslate(BCTranslate):
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"x": _translate("BoundaryCondition", "X"), "x": _translate("BoundaryCondition", "X"),
"y": _translate("BoundaryCondition", "Y"), "y": _translate("BoundaryCondition", "Y"),
"time": _translate("BoundaryCondition", "Time"), "time": self._dict["time"],
"date": _translate("BoundaryCondition", "Date"), "date": self._dict["date"],
"discharge": _translate("BoundaryCondition", "Discharge (m³/s)"), "discharge": self._dict["unit_discharge"],
"z": _translate("BoundaryCondition", "Z (m)"), "z": self._dict["unit_elevation"],
"solid": _translate("BoundaryCondition", "Solid (kg/s)"), "solid": _translate("BoundaryCondition", "Solid (kg/s)"),
} }

View File

@ -18,7 +18,7 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
from Model.BoundaryCondition.BoundaryConditionTypes import ( from Model.BoundaryCondition.BoundaryConditionTypes import (
NotDefined, PonctualContribution, NotDefined, PonctualContribution,
@ -38,7 +38,7 @@ BC_types = {
} }
class BCTranslate(PamhyrTranslate): class BCTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(BCTranslate, self).__init__() super(BCTranslate, self).__init__()
@ -56,7 +56,7 @@ class BCTranslate(PamhyrTranslate):
} }
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("BoundaryCondition", "Name"), "name": self._dict["name"],
"type": _translate("BoundaryCondition", "Type"), "type": self._dict["type"],
"node": _translate("BoundaryCondition", "Node") "node": _translate("BoundaryCondition", "Node")
} }

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class CheckListTranslate(PamhyrTranslate): class CheckListTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(CheckListTranslate, self).__init__() super(CheckListTranslate, self).__init__()
@ -32,6 +32,6 @@ class CheckListTranslate(PamhyrTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("CheckList", "Name"), "name": self._dict["name"],
"status": _translate("CheckList", "Status"), "status": _translate("CheckList", "Status"),
} }

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class ConfigureTranslate(PamhyrTranslate): class ConfigureTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(ConfigureTranslate, self).__init__() super(ConfigureTranslate, self).__init__()
@ -32,9 +32,9 @@ class ConfigureTranslate(PamhyrTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("Configure", "Name"), "name": self._dict["name"],
"type": _translate("Configure", "Type"), "type": self._dict["type"],
"description": _translate("Configure", "Description"), "description": self._dict["description"],
} }
# Solvers # Solvers

View File

@ -18,18 +18,16 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class FrictionsTranslate(PamhyrTranslate): class FrictionsTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(FrictionsTranslate, self).__init__() super(FrictionsTranslate, self).__init__()
self._dict["kp"] = _translate( self._dict["kp"] = self._dict["unit_kp"]
"Frictions", "Kp (m)"
)
self._dict["stricklers"] = _translate( self._dict["stricklers"] = _translate(
"Frictions", "Stricklers" "Frictions", "Stricklers"
) )
@ -39,8 +37,8 @@ class FrictionsTranslate(PamhyrTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
# "name": _translate("Frictions", "Name"), # "name": self._dict["name"],
# "edge": _translate("Frictions", "Reach"), # "edge": self._dict["reach"],
"begin_kp": _translate("Frictions", "Begin kp (m)"), "begin_kp": _translate("Frictions", "Begin kp (m)"),
"end_kp": _translate("Frictions", "End kp (m)"), "end_kp": _translate("Frictions", "End kp (m)"),
"begin_strickler": _translate("Frictions", "Begin strickler"), "begin_strickler": _translate("Frictions", "Begin strickler"),

View File

@ -21,12 +21,6 @@ import logging
from tools import timer from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot from View.Tools.PamhyrPlot import PamhyrPlot
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
logger = logging.getLogger() logger = logging.getLogger()
@ -46,20 +40,12 @@ class PlotAC(PamhyrPlot):
self._auto_relim_update = True self._auto_relim_update = True
self._autoscale_update = True self._autoscale_update = True
self.label_x = _translate( self.label_x = self._trad["transverse_abscissa"]
"Geometry", "Transverse abscissa (m)" self.label_y = self._trad["unit_height"]
)
self.label_y = _translate("Geometry", "Height (m)")
self.label_previous_plot_selected = _translate( self.label_previous_plot_selected = self._trad["prev_cs"]
"Geometry", "Previous cross-section" self.label_plot_selected = self._trad["cs"]
) self.label_next_plot_selected = self._trad["next_cs"]
self.label_plot_selected = _translate(
"Geometry", "Cross-section"
)
self.label_next_plot_selected = _translate(
"Geometry", "Next cross-section"
)
self.previous_plot_selected = None self.previous_plot_selected = None
self.plot_selected = None self.plot_selected = None

View File

@ -21,12 +21,6 @@ import logging
from tools import timer from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot from View.Tools.PamhyrPlot import PamhyrPlot
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
logger = logging.getLogger() logger = logging.getLogger()
@ -48,8 +42,8 @@ class PlotKPZ(PamhyrPlot):
self.line_kp_zmin_zmax = None self.line_kp_zmin_zmax = None
self.line_kp_zmin_zmax_highlight = None self.line_kp_zmin_zmax_highlight = None
self.label_x = _translate("MainWindow_reach", "Kp (m)") self.label_x = self._trad["unit_kp"]
self.label_y = _translate("MainWindow_reach", "Height (m)") self.label_y = self._trad["unit_height"]
self.before_plot_selected = None self.before_plot_selected = None
self.plot_selected = None self.plot_selected = None

View File

@ -40,8 +40,8 @@ class PlotXY(PamhyrPlot):
self.line_xy = [] self.line_xy = []
self.line_gl = [] self.line_gl = []
self.label_x = _translate("Geometry", "X (m)") self.label_x = self._trad["x"]
self.label_y = _translate("Geometry", "Y (m)") self.label_y = self._trad["y"]
self.before_plot_selected = None self.before_plot_selected = None
self.plot_selected = None self.plot_selected = None

View File

@ -47,16 +47,18 @@ class Plot(PamhyrPlot):
self.line_xy = [] self.line_xy = []
self.line_gl = [] self.line_gl = []
self.label_x = self._trad["unit_kp"]
self.label_y = self._trad["unit_height"]
self.before_plot_selected = None self.before_plot_selected = None
self.plot_selected = None self.plot_selected = None
self.after_plot_selected = None self.after_plot_selected = None
self._isometric_axis = False
@timer @timer
def draw(self): def draw(self):
self.canvas.axes.cla() self.init_axes()
self.canvas.axes.grid(
color='grey', linestyle='--', linewidth=0.5
)
x = self.data.get_station() x = self.data.get_station()
y = self.data.z() y = self.data.z()
@ -71,19 +73,10 @@ class Plot(PamhyrPlot):
gl = map(lambda p: p.name, self.data.points) gl = map(lambda p: p.name, self.data.points)
self.profile_line2D, = self.canvas.axes.plot( self.profile_line2D, = self.canvas.axes.plot(
x, y, color='r', lw=1.5, x, y, color=self.color_plot,
markersize=7, marker='+', lw=1.5, markersize=7, marker='+',
picker=30 picker=30
) )
self.canvas.axes.set_xlabel(
_translate("MainWindowProfile",
"Transverse abscissa (m)"),
color='black', fontsize=10
)
self.canvas.axes.set_ylabel(
_translate("MainWindowProfile", "Height (m)"),
color='black', fontsize=10
)
# Add label on graph # Add label on graph
self.annotation = [] self.annotation = []
@ -142,10 +135,8 @@ class Plot(PamhyrPlot):
self.onclick_event.onclick self.onclick_event.onclick
) )
self.canvas.figure.tight_layout() self.idle()
self.canvas.figure.canvas.draw_idle()
@timer @timer
def update(self, ind=None): def update(self):
logger.info("TODO: implemente update")
self.draw() self.draw()

View File

@ -18,7 +18,7 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
from View.Geometry.Translate import GeometryTranslate from View.Geometry.Translate import GeometryTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
@ -33,9 +33,9 @@ class GeometryProfileTranslate(GeometryTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"x": _translate("Geometry", "X (m)"), "x": self._dict["x"],
"y": _translate("Geometry", "Y (m)"), "y": self._dict["y"],
"z": _translate("Geometry", "Z (m)"), "z": self._dict["z"],
"name": _translate("Geometry", "Name"), "name": self._dict["name"],
"abs": _translate("Geometry", "Traversal abs (m)"), "abs": _translate("Geometry", "Traversal abs (m)"),
} }

View File

@ -108,6 +108,7 @@ class ProfileWindow(PamhyrWindow):
self._plot = Plot( self._plot = Plot(
canvas=self._canvas, canvas=self._canvas,
data=self._profile, data=self._profile,
trad=self._trad,
toolbar=self._toolbar, toolbar=self._toolbar,
table=self.find(QTableView, "tableView") table=self.find(QTableView, "tableView")
) )

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class GeometryTranslate(PamhyrTranslate): class GeometryTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(GeometryTranslate, self).__init__() super(GeometryTranslate, self).__init__()
@ -38,17 +38,28 @@ class GeometryTranslate(PamhyrTranslate):
"Geometry", "File mage meshed geometry (*.M *.m)") "Geometry", "File mage meshed geometry (*.M *.m)")
self._dict["file_all"] = _translate("Geometry", "All file (*)") self._dict["file_all"] = _translate("Geometry", "All file (*)")
self._dict["reach"] = _translate("Geometry", "reach")
self._dict["reachs"] = _translate("Geometry", "reachs")
self._dict["cross_section"] = _translate("Geometry", "cross-section") self._dict["cross_section"] = _translate("Geometry", "cross-section")
self._dict["cross_sections"] = _translate("Geometry", "cross-sections") self._dict["cross_sections"] = _translate("Geometry", "cross-sections")
self._dict["profile"] = _translate("Geometry", "cross-section") self._dict["profile"] = _translate("Geometry", "cross-section")
self._dict["profiles"] = _translate("Geometry", "cross-sections") self._dict["profiles"] = _translate("Geometry", "cross-sections")
self._dict["transverse_abscissa"] = _translate(
"Geometry", "Transverse abscissa (m)"
)
self._dict["prev_cs"] = _translate(
"Geometry", "Previous cross-section"
)
self._dict["cs"] = _translate("Geometry", "Cross-section")
self._dict["next_cs"] = _translate("Geometry", "Next cross-section")
self._dict["x"] = _translate("Geometry", "X (m)")
self._dict["y"] = _translate("Geometry", "Y (m)")
self._dict["z"] = _translate("Geometry", "Z (m)")
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("Geometry", "Name"), "name": self._dict["name"],
"kp": _translate("Geometry", "KP (m)"), "kp": self._dict["unit_kp"],
"poins": _translate("Geometry", "Points"), "poins": _translate("Geometry", "Points"),
} }

View File

@ -327,6 +327,7 @@ class GeometryWindow(PamhyrWindow):
self._plot_xy = PlotXY( self._plot_xy = PlotXY(
canvas=self._canvas_xy, canvas=self._canvas_xy,
data=self._reach, data=self._reach,
trad=self._trad,
toolbar=self._toolbar_xy toolbar=self._toolbar_xy
) )
self._plot_xy.draw() self._plot_xy.draw()
@ -344,6 +345,7 @@ class GeometryWindow(PamhyrWindow):
self._plot_kpc = PlotKPZ( self._plot_kpc = PlotKPZ(
canvas=self._canvas_kpc, canvas=self._canvas_kpc,
data=self._reach, data=self._reach,
trad=self._trad,
toolbar=self._toolbar_kpc toolbar=self._toolbar_kpc
) )
self._plot_kpc.draw() self._plot_kpc.draw()
@ -361,6 +363,7 @@ class GeometryWindow(PamhyrWindow):
self._plot_ac = PlotAC( self._plot_ac = PlotAC(
canvas=self._canvas_ac, canvas=self._canvas_ac,
data=self._reach, data=self._reach,
trad=self._trad,
toolbar=self._toolbar_ac, toolbar=self._toolbar_ac,
) )
self._plot_ac.draw() self._plot_ac.draw()

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class BasicHydraulicStructuresTranslate(PamhyrTranslate): class BasicHydraulicStructuresTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(BasicHydraulicStructuresTranslate, self).__init__() super(BasicHydraulicStructuresTranslate, self).__init__()
@ -44,18 +44,10 @@ hydraulic structure values?"
# BHSValues translation # BHSValues translation
self._dict['width'] = _translate( self._dict['width'] = self._dict["unit_width"]
"BasicHydraulicStructures", "Width (m)" self._dict['height'] = self._dict["unit_thickness"]
) self._dict['elevation'] = self._dict["unit_elevation"]
self._dict['height'] = _translate( self._dict['diameter'] = self._dict["unit_diameter"]
"BasicHydraulicStructures", "Thickness (m)"
)
self._dict['elevation'] = _translate(
"BasicHydraulicStructures", "Elevation (m)"
)
self._dict['diameter'] = _translate(
"BasicHydraulicStructures", "Diameter (m)"
)
self._dict['discharge_coefficient'] = _translate( self._dict['discharge_coefficient'] = _translate(
"BasicHydraulicStructures", "Discharge coefficient" "BasicHydraulicStructures", "Discharge coefficient"
) )
@ -155,11 +147,11 @@ hydraulic structure values?"
# Tables # Tables
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("BasicHydraulicStructures", "Name"), "name": self._dict["name"],
"type": _translate("BasicHydraulicStructures", "Type"), "type": self._dict["type"],
} }
self._sub_dict["table_headers_parameters"] = { self._sub_dict["table_headers_parameters"] = {
"name": _translate("BasicHydraulicStructures", "Name"), "name": self._dict["name"],
"value": _translate("BasicHydraulicStructures", "Value"), "value": self._dict["value"],
} }

View File

@ -20,12 +20,6 @@ from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot from View.Tools.PamhyrPlot import PamhyrPlot
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
class PlotAC(PamhyrPlot): class PlotAC(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None, def __init__(self, canvas=None, trad=None, toolbar=None,
@ -42,8 +36,8 @@ class PlotAC(PamhyrPlot):
self._current_reach = reach self._current_reach = reach
self._current_profile = profile self._current_profile = profile
self.label_x = _translate("MainWindow_reach", "X (m)") self.label_x = self._trad["x"]
self.label_y = _translate("MainWindow_reach", "Elevation (m)") self.label_y = self._trad["unit_elevation"]
self._isometric_axis = False self._isometric_axis = False

View File

@ -43,8 +43,8 @@ class PlotKPC(PamhyrPlot):
self._current_reach = reach self._current_reach = reach
self._current_profile = profile self._current_profile = profile
self.label_x = _translate("MainWindow_reach", "KP (m)") self.label_x = self._trad["unit_kp"]
self.label_y = _translate("MainWindow_reach", "Elevation (m)") self.label_y = self._trad["unit_elevation"]
self._isometric_axis = False self._isometric_axis = False

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class HydraulicStructuresTranslate(PamhyrTranslate): class HydraulicStructuresTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(HydraulicStructuresTranslate, self).__init__() super(HydraulicStructuresTranslate, self).__init__()
@ -31,8 +31,10 @@ class HydraulicStructuresTranslate(PamhyrTranslate):
"HydraulicStructures", "Hydraulic Structures" "HydraulicStructures", "Hydraulic Structures"
) )
self._dict["x"] = _translate("HydraulicStructures", "X (m)")
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("HydraulicStructures", "Name"), "name": self._dict["name"],
"reach": _translate("HydraulicStructures", "Reach"), "reach": self._dict["reach"],
"kp": _translate("HydraulicStructures", "Kp (m)"), "kp": self._dict["unit_kp"],
} }

View File

@ -52,8 +52,6 @@ from View.HydraulicStructures.BasicHydraulicStructures.Window import (
BasicHydraulicStructuresWindow BasicHydraulicStructuresWindow
) )
_translate = QCoreApplication.translate
logger = logging.getLogger() logger = logging.getLogger()
@ -142,6 +140,7 @@ class HydraulicStructuresWindow(PamhyrWindow):
river=self._study.river, river=self._study.river,
reach=None, reach=None,
profile=None, profile=None,
trad=self._trad,
toolbar=self.toolbar toolbar=self.toolbar
) )
self.plot_kpc.draw() self.plot_kpc.draw()
@ -160,6 +159,7 @@ class HydraulicStructuresWindow(PamhyrWindow):
river=self._study.river, river=self._study.river,
reach=None, reach=None,
profile=None, profile=None,
trad=self._trad,
toolbar=self.toolbar_2 toolbar=self.toolbar_2
) )
self.plot_ac.draw() self.plot_ac.draw()

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class ICTranslate(PamhyrTranslate): class ICTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(ICTranslate, self).__init__() super(ICTranslate, self).__init__()
@ -34,18 +34,16 @@ class ICTranslate(PamhyrTranslate):
self._dict["Height"] = _translate( self._dict["Height"] = _translate(
"InitialCondition", "Height") "InitialCondition", "Height")
self._dict["elevation"] = _translate( self._dict["elevation"] = self._dict["unit_elevation"]
"InitialCondition", "Elevation (m)") self._dict["discharge"] = self._dict["unit_discharge"]
self._dict["discharge"] = _translate( self._dict["kp"] = self._dict["unit_kp"]
"InitialCondition", "Discharge (m³/s)")
self._dict["kp"] = _translate("InitialCondition", "KP (m)")
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
# "name": _translate("InitialCondition", "Name"), # "name": _translate("InitialCondition", "Name"),
"kp": _translate("InitialCondition", "KP (m)"), "kp": self._dict["unit_kp"],
# "speed": _translate("InitialCondition", "Speed (m/s)"), # "speed": _translate("InitialCondition", "Speed (m/s)"),
"discharge": _translate("InitialCondition", "Discharge (m³/s)"), "discharge": self._dict["unit_discharge"],
"elevation": _translate("InitialCondition", "Elevation (m)"), "elevation": self._dict["unit_elevation"],
"height": _translate("InitialCondition", "Height (m)"), "height": self._dict["unit_height"],
# "comment": _translate("InitialCondition", "Comment"), # "comment": _translate("InitialCondition", "Comment"),
} }

View File

@ -18,7 +18,7 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
from View.LateralContribution.translate import LCTranslate from View.LateralContribution.translate import LCTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
@ -34,8 +34,8 @@ class LCETranslate(LCTranslate):
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"x": _translate("LateralContribution", "X"), "x": _translate("LateralContribution", "X"),
"y": _translate("LateralContribution", "Y"), "y": _translate("LateralContribution", "Y"),
"time": _translate("LateralContribution", "Time"), "time": self._dict["time"],
"date": _translate("LateralContribution", "Date"), "date": self._dict["date"],
"discharge": _translate("LateralContribution", "Discharge (m³/s)"), "discharge": self._dict["unit_discharge"],
"z": _translate("LateralContribution", "Z (m)") "z": self._dict["unit_elevation"],
} }

View File

@ -18,7 +18,7 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
from Model.LateralContribution.LateralContributionTypes import ( from Model.LateralContribution.LateralContributionTypes import (
NotDefined, LateralContrib, Rain, Evaporation, NotDefined, LateralContrib, Rain, Evaporation,
@ -34,7 +34,7 @@ LC_types = {
} }
class LCTranslate(PamhyrTranslate): class LCTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(LCTranslate, self).__init__() super(LCTranslate, self).__init__()
@ -50,9 +50,9 @@ class LCTranslate(PamhyrTranslate):
} }
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("LateralContribution", "Name"), "name": self._dict["name"],
"type": _translate("LateralContribution", "Type"), "type": self._dict["type"],
"edge": _translate("LateralContribution", "Reach"), "edge": self._dict["reach"],
"begin_kp": _translate("LateralContribution", "Begin kp (m)"), "begin_kp": _translate("LateralContribution", "Begin kp (m)"),
"end_kp": _translate("LateralContribution", "End kp (m)") "end_kp": _translate("LateralContribution", "End kp (m)")
} }

View File

@ -42,6 +42,8 @@ from View.Tools.ASubWindow import WindowToolKit
from View.Tools.ListedSubWindow import ListedSubWindow from View.Tools.ListedSubWindow import ListedSubWindow
from View.DummyWindow import DummyWindow from View.DummyWindow import DummyWindow
from View.Translate import MainTranslate
from View.Configure.Window import ConfigureWindow from View.Configure.Window import ConfigureWindow
from View.Study.Window import NewStudyWindow from View.Study.Window import NewStudyWindow
from View.About.Window import AboutWindow from View.About.Window import AboutWindow
@ -73,8 +75,6 @@ except Exception as e:
from Model.Study import Study from Model.Study import Study
_translate = QCoreApplication.translate
logger = logging.getLogger() logger = logging.getLogger()
no_model_action = [ no_model_action = [
@ -128,6 +128,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
# Model # Model
self._study = None self._study = None
# Translate
self._trad = MainTranslate()
# Results # Results
self._last_solver = None self._last_solver = None
self._last_results = None self._last_results = None
@ -145,9 +148,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.setup_results() self.setup_results()
self.setup_timer() self.setup_timer()
self.trans = QTranslator(self)
# self.ui.retranslateUi()
if not self.conf.close_correctly: if not self.conf.close_correctly:
if self.conf.last_study != "": if self.conf.last_study != "":
self.dialog_reopen_study() self.dialog_reopen_study()
@ -305,18 +305,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if init: if init:
self.debug_action = QAction("Debug", self) self.debug_action = QAction("Debug", self)
self.debug_action.setToolTip( self.debug_action.setToolTip(self._trad["open_debug"])
_translate("MainWindow", "Open debug window")
)
self.debug_action.triggered.connect(self.open_debug) self.debug_action.triggered.connect(self.open_debug)
self.debug_sqlite_action = QAction("Debug SQLite", self) self.debug_sqlite_action = QAction("Debug SQLite", self)
self.debug_sqlite_action.setToolTip( self.debug_sqlite_action.setToolTip(self._trad["open_debug_sql"])
_translate(
"MainWindow",
"Open SQLite debuging tool ('sqlitebrowser')"
)
)
self.debug_sqlite_action.triggered.connect(self.open_sqlite) self.debug_sqlite_action.triggered.connect(self.open_sqlite)
if self.conf.debug: if self.conf.debug:
@ -635,9 +628,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
return lambda: self._activate_window(h) return lambda: self._activate_window(h)
action = QAction(window._title, self) action = QAction(window._title, self)
action.setToolTip( action.setToolTip(self._trad["active_window"])
_translate("MainWindow", "Activate this window")
)
h = window.hash() h = window.hash()
fn = lambda_generator(h) fn = lambda_generator(h)
action.triggered.connect(fn) action.triggered.connect(fn)

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class NetworkTranslate(PamhyrTranslate): class NetworkTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(NetworkTranslate, self).__init__() super(NetworkTranslate, self).__init__()
@ -32,12 +32,12 @@ class NetworkTranslate(PamhyrTranslate):
) )
self._sub_dict["table_headers_node"] = { self._sub_dict["table_headers_node"] = {
"name": _translate("Network", "Name"), "name": self._dict['name'],
"type": _translate("Network", "Type"), "type": self._dict['type'],
} }
self._sub_dict["table_headers_edge"] = { self._sub_dict["table_headers_edge"] = {
"name": _translate("Network", "Name"), "name": self._dict['name'],
"node1": _translate("Network", "Source node"), "node1": _translate("Network", "Source node"),
"node2": _translate("Network", "Destination node"), "node2": _translate("Network", "Destination node"),
} }

View File

@ -18,7 +18,7 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
from View.Reservoir.Translate import ReservoirTranslate from View.Reservoir.Translate import ReservoirTranslate
@ -34,6 +34,6 @@ class EditReservoirTranslate(ReservoirTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"z": _translate("Reservoir", "Elevation (m)"), "z": self._dict["unit_elevation"],
"Area": _translate("Reservoir", "Area (hectare)"), "Area": self._dict["unit_area"],
} }

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class ReservoirTranslate(PamhyrTranslate): class ReservoirTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(ReservoirTranslate, self).__init__() super(ReservoirTranslate, self).__init__()
@ -32,6 +32,6 @@ class ReservoirTranslate(PamhyrTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("Reservoir", "Name"), "name": self._dict["name"],
"node": _translate("Reservoir", "Node") "node": _translate("Reservoir", "Node"),
} }

View File

@ -33,30 +33,20 @@ class CustomPlotTranslate(ResultsTranslate):
# Value type # Value type
self._dict['time'] = _translate( self._dict['time'] = self._dict["unit_time_s"]
"CustomPlot", "Time (sec)" self._dict['kp'] = self._dict["unit_kp"]
) self._dict['water_elevation'] = self._dict["unit_water_elevation"]
self._dict['kp'] = _translate( self._dict['discharge'] = self._dict["unit_discharge"]
"CustomPlot", "Kp (m)"
)
self._dict['elevation'] = _translate( self._dict['elevation'] = _translate(
"CustomPlot", "Bed load elevation (m)" "CustomPlot", "Bed load elevation (m)"
) )
self._dict['water_elevation'] = _translate(
"CustomPlot", "Water elevation (m)"
)
self._dict['discharge'] = _translate(
"CustomPlot", "Discharge (m³/s)"
)
# Unit corresponding long name (plot axes display) # Unit corresponding long name (plot axes display)
self._dict['0-meter'] = _translate( self._dict['0-meter'] = _translate(
"CustomPlot", "Bed load elevation (m)" "CustomPlot", "Bed load elevation (m)"
) )
self._dict['1-m3s'] = _translate( self._dict['1-m3s'] = self._dict["unit_discharge"]
"CustomPlot", "Discharge (m³/s)"
)
# SubDict # SubDict

View File

@ -43,12 +43,12 @@ class PlotAC(PamhyrPlot):
self._current_reach_id = reach_id self._current_reach_id = reach_id
self._current_profile_id = profile_id self._current_profile_id = profile_id
self.label_x = _translate("Results", "X (m)") self.label_x = self._trad['x']
self.label_y = _translate("MainWindow_reach", "Elevation (m)") self.label_y = self._trad["unit_elevation"]
self.label_bottom = _translate("Results", "River bottom") self.label_bottom = self._trad['label_bottom']
self.label_water = _translate("Results", "Water elevation") self.label_water = self._trad['label_water']
self.label_water_max = _translate("Results", "Max water elevation") self.label_water_max = self._trad['label_water_max']
self._isometric_axis = False self._isometric_axis = False

View File

@ -29,8 +29,6 @@ from PyQt5.QtCore import (
logger = logging.getLogger() logger = logging.getLogger()
_translate = QCoreApplication.translate
class PlotKPC(PamhyrPlot): class PlotKPC(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None, def __init__(self, canvas=None, trad=None, toolbar=None,
@ -49,12 +47,12 @@ class PlotKPC(PamhyrPlot):
self._current_reach_id = reach_id self._current_reach_id = reach_id
self._current_profile_id = profile_id self._current_profile_id = profile_id
self.label_x = _translate("Results", "KP (m)") self.label_x = self._trad["unit_kp"]
self.label_y = _translate("Results", "Elevation (m)") self.label_y = self._trad["unit_elevation"]
self.label_bottom = _translate("Results", "River bottom") self.label_bottom = self._trad["label_bottom"]
self.label_water = _translate("Results", "Water elevation") self.label_water = self._trad["label_water"]
self.label_water_max = _translate("Results", "Max water elevation") self.label_water_max = self._trad["label_water_max"]
self._isometric_axis = False self._isometric_axis = False

View File

@ -171,6 +171,7 @@ class ResultsWindow(PamhyrWindow):
results=self._results, results=self._results,
reach_id=0, reach_id=0,
profile_id=0, profile_id=0,
trad=self._trad,
toolbar=self.toolbar, toolbar=self.toolbar,
display_current=True display_current=True
) )
@ -190,6 +191,7 @@ class ResultsWindow(PamhyrWindow):
results=self._results, results=self._results,
reach_id=0, reach_id=0,
profile_id=0, profile_id=0,
trad=self._trad,
toolbar=self.toolbar_2 toolbar=self.toolbar_2
) )
self.plot_kpc.draw() self.plot_kpc.draw()
@ -208,6 +210,7 @@ class ResultsWindow(PamhyrWindow):
results=self._results, results=self._results,
reach_id=0, reach_id=0,
profile_id=0, profile_id=0,
trad=self._trad,
toolbar=self.toolbar_3 toolbar=self.toolbar_3
) )
self.plot_ac.draw() self.plot_ac.draw()
@ -227,6 +230,7 @@ class ResultsWindow(PamhyrWindow):
results=self._results, results=self._results,
reach_id=0, reach_id=0,
profile_id=0, profile_id=0,
trad=self._trad,
toolbar=self.toolbar_4 toolbar=self.toolbar_4
) )
self.plot_h.draw() self.plot_h.draw()

View File

@ -18,24 +18,27 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class ResultsTranslate(PamhyrTranslate): class ResultsTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(ResultsTranslate, self).__init__() super(ResultsTranslate, self).__init__()
self._dict["Results"] = _translate( self._dict["Results"] = _translate("Results", "Results")
"Results", "Results"
)
self._dict['day'] = _translate( self._dict['day'] = _translate("Results", "day")
"Results", "day" self._dict['days'] = _translate("Results", "days")
)
self._dict['days'] = _translate( self._dict['x'] = _translate("Results", "X (m)")
"Results", "days"
self._dict['label_bottom'] = _translate("Results", "River bottom")
self._dict['label_water'] = _translate("Results", "Water elevation")
self._dict['label_water_max'] = _translate(
"Results",
"Max water elevation"
) )
self._sub_dict["table_headers_reach"] = { self._sub_dict["table_headers_reach"] = {
@ -43,12 +46,12 @@ class ResultsTranslate(PamhyrTranslate):
} }
self._sub_dict["table_headers_profile"] = { self._sub_dict["table_headers_profile"] = {
"name": _translate("Results", "Name"), "name": self._dict["name"],
"kp": _translate("Results", "KP (m)"), "kp": self._dict["unit_kp"],
} }
self._sub_dict["table_headers_raw_data"] = { self._sub_dict["table_headers_raw_data"] = {
"name": _translate("Results", "Profile"), "name": _translate("Results", "Profile"),
"water_elevation": _translate("Results", "Water elevation (m)"), "water_elevation": self._dict["unit_water_elevation"],
"discharge": _translate("Results", "Discharge (m³/s)"), "discharge": self._dict["unit_discharge"],
} }

View File

@ -31,14 +31,15 @@ class SedimentEditTranslate(SedimentTranslate):
"SedimentLayers", "Edit Sediment Layers" "SedimentLayers", "Edit Sediment Layers"
) )
self._dict["height"] = _translate("SedimentLayers", "Thickness (m)") self._dict["height"] = self._dict["unit_thickness"]
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("SedimentLayers", "Name"), "name": self._dict["name"],
# "type": _translate("SedimentLayers", "Type"), # "type": self._dict["type"],
"height": _translate("SedimentLayers", "Thickness (m)"), "height": self._dict["unit_thickness"],
"d50": _translate("SedimentLayers", "D50"), "d50": _translate("SedimentLayers", "D50"),
"sigma": _translate("SedimentLayers", "Sigma"), "sigma": _translate("SedimentLayers", "Sigma"),
"critical_constraint": _translate("SedimentLayers", "critical_constraint": _translate(
"Critical constraint"), "SedimentLayers", "Critical constraint"
),
} }

View File

@ -30,9 +30,7 @@ class SedimentProfileTranslate(SedimentReachTranslate):
self._dict["x"] = _translate( self._dict["x"] = _translate(
"SedimentLayers", "X (m)" "SedimentLayers", "X (m)"
) )
self._dict["height"] = _translate( self._dict["height"] = self._dict["unit_height"]
"SedimentLayers", "Height (m)"
)
self._dict["Profile sediment layers"] = _translate( self._dict["Profile sediment layers"] = _translate(
"SedimentLayers", "Profile sediment layers" "SedimentLayers", "Profile sediment layers"
@ -42,6 +40,6 @@ class SedimentProfileTranslate(SedimentReachTranslate):
"x": _translate("SedimentLayers", "X (m)"), "x": _translate("SedimentLayers", "X (m)"),
"y": _translate("SedimentLayers", "Y (m)"), "y": _translate("SedimentLayers", "Y (m)"),
"z": _translate("SedimentLayers", "Z (m)"), "z": _translate("SedimentLayers", "Z (m)"),
"name": _translate("SedimentLayers", "Name"), "name": self._dict["name"],
"sl": _translate("SedimentLayers", "Sediment layers"), "sl": _translate("SedimentLayers", "Sediment layers"),
} }

View File

@ -35,11 +35,11 @@ class SedimentReachTranslate(SedimentTranslate):
) )
self._dict["nd"] = _translate("SedimentLayers", "Not defined") self._dict["nd"] = _translate("SedimentLayers", "Not defined")
self._dict["kp"] = _translate("SedimentLayers", "Kp (m)") self._dict["kp"] = self._dict["unit_kp"]
self._dict["height"] = _translate("SedimentLayers", "Height (m)") self._dict["height"] = self._dict["unit_height"]
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("SedimentLayers", "Name"), "name": self._dict["name"],
"kp": _translate("SedimentLayers", "KP (m)"), "kp": self._dict["unit_kp"],
"sl": _translate("SedimentLayers", "Sediment layers"), "sl": _translate("SedimentLayers", "Sediment layers"),
} }

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class SedimentTranslate(PamhyrTranslate): class SedimentTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(SedimentTranslate, self).__init__() super(SedimentTranslate, self).__init__()
@ -32,6 +32,6 @@ class SedimentTranslate(PamhyrTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("SedimentLayers", "Name"), "name": self._dict["name"],
"comment": _translate("SedimentLayers", "Comment"), "comment": self._dict["comment"],
} }

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class ParamTranslate(PamhyrTranslate): class ParamTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(ParamTranslate, self).__init__() super(ParamTranslate, self).__init__()
@ -32,8 +32,8 @@ class ParamTranslate(PamhyrTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("SolverParameters", "Name"), "name": self._dict["name"],
"value": _translate("SolverParameters", "Value") "value": self._dict["value"],
} }
self._sub_dict["yes_no"] = { self._sub_dict["yes_no"] = {

View File

@ -18,12 +18,12 @@
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate from View.Translate import MainTranslate
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class StricklersTranslate(PamhyrTranslate): class StricklersTranslate(MainTranslate):
def __init__(self): def __init__(self):
super(StricklersTranslate, self).__init__() super(StricklersTranslate, self).__init__()
@ -32,8 +32,8 @@ class StricklersTranslate(PamhyrTranslate):
) )
self._sub_dict["table_headers"] = { self._sub_dict["table_headers"] = {
"name": _translate("Stricklers", "Name"), "name": self._dict["name"],
"minor": _translate("Stricklers", "Main channel"), "minor": self._dict["main_channel"],
"medium": _translate("Stricklers", "Floodway"), "medium": self._dict["floodway"],
"comment": _translate("Stricklers", "Comment"), "comment": self._dict["comment"],
} }

81
src/View/Translate.py Normal file
View File

@ -0,0 +1,81 @@
# Translate.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 <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication
from View.Tools.PamhyrTranslate import PamhyrTranslate
_translate = QCoreApplication.translate
class CommonWordTranslate(PamhyrTranslate):
def __init__(self):
super(CommonWordTranslate, self).__init__()
self._dict["name"] = _translate("CommonWord", "Name")
self._dict["type"] = _translate("CommonWord", "Type")
self._dict["value"] = _translate("CommonWord", "Value")
self._dict["comment"] = _translate("CommonWord", "Comment")
self._dict["description"] = _translate("CommonWord", "Description")
self._dict["time"] = _translate("CommonWord", "Time")
self._dict["date"] = _translate("CommonWord", "Date")
self._dict["reach"] = _translate("CommonWord", "Reach")
self._dict["reaches"] = _translate("CommonWord", "Reaches")
self._dict["cross_section"] = _translate("CommonWord", "Coss-section")
self._dict["main_channel"] = _translate("CommonWord", "Main channel")
self._dict["floodway"] = _translate("CommonWord", "Floodway")
class UnitTranslate(CommonWordTranslate):
def __init__(self):
super(UnitTranslate, self).__init__()
self._dict["unit_kp"] = _translate("Unit", "KP (m)")
self._dict["unit_width"] = _translate("Unit", "Width (m)")
self._dict["unit_height"] = _translate("Unit", "Height (m)")
self._dict["unit_diameter"] = _translate("Unit", "Diameter (m)")
self._dict["unit_thickness"] = _translate("Unit", "Thickness (m)")
self._dict["unit_elevation"] = _translate("Unit", "Elevation (m)")
self._dict["unit_water_elevation"] = _translate(
"Unit", "Water elevation (m)"
)
self._dict["unit_discharge"] = _translate("Unit", "Discharge (m³/s)")
self._dict["unit_area"] = _translate("Unit", "Area (hectare)"),
self._dict["unit_time_s"] = _translate("Unit", "Time (sec)")
self._dict["unit_time_p"] = _translate("Unit", "Time (JJJ:HH:MM:SS)")
self._dict["unit_date_s"] = _translate("Unit", "Date (sec)")
self._dict["unit_date_iso"] = _translate("Unit", "Date (ISO format)")
class MainTranslate(UnitTranslate):
def __init__(self):
super(MainTranslate, self).__init__()
self._dict["open_debug"] = _translate(
"MainWindow", "Open debug window"
)
self._dict["open_debug_sql"] = _translate(
"MainWindow", "Open SQLite debuging tool ('sqlitebrowser')"
)
self._dict["active_window"] = _translate(
"MainWindow", "Activate this window"
)

View File

@ -252,7 +252,6 @@ def old_pamhyr_date_to_timestamp(date: str):
def timestamp_to_old_pamhyr_date(time: int): def timestamp_to_old_pamhyr_date(time: int):
logger.debug(f"timestamp_to_old_pamhyr_date({time}: {type(time)})")
t0 = datetime.fromtimestamp(0) t0 = datetime.fromtimestamp(0)
# HACK: Windows do not accept negative timestamps # HACK: Windows do not accept negative timestamps