mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
refactoring: Add PamhyrTranslate class for GUI translation and document it.
This commit is contained in:
1 parent
e7fd2077bd
commit
2e94348bb8
5 files changed
+145
-70
No files matched your search
@@ -41,10 +41,7 @@ from Model.River import RiverNode, RiverReach, River
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
from View.Network.GraphWidget import GraphWidget
|
||||
from View.Network.UndoCommand import *
|
||||
from View.Network.translate import (
|
||||
table_headers_node, table_headers_edge,
|
||||
retranslate,
|
||||
)
|
||||
from View.Network.translate import NetworkTranslate
|
||||
from View.Network.Table import (
|
||||
ComboBoxDelegate, NodeTableModel, EdgeTableModel,
|
||||
)
|
||||
@@ -63,24 +60,25 @@ class NetworkWindow(PamhyrWindow):
|
||||
title = self._pamhyr_name + " - " + study.name,
|
||||
study = study,
|
||||
config = config,
|
||||
trad = NetworkTranslate(),
|
||||
options = ['undo'],
|
||||
parent=parent,
|
||||
)
|
||||
|
||||
self._graph = study.river
|
||||
self._table_headers_node = self._trad.get_dict("table_headers_node")
|
||||
self._table_headers_edge = self._trad.get_dict("table_headers_edge")
|
||||
|
||||
self.setup_graph()
|
||||
self.setup_table()
|
||||
self.setup_connections()
|
||||
|
||||
def setup_table(self):
|
||||
retranslate()
|
||||
|
||||
# Nodes table
|
||||
table = self.find(QTableView, "tableView_nodes")
|
||||
self._nodes_model = NodeTableModel(
|
||||
table_view = table,
|
||||
table_headers = table_headers_node,
|
||||
table_headers = self._table_headers_node,
|
||||
editable_headers = ["name"],
|
||||
data = self._graph,
|
||||
undo = self._undo_stack,
|
||||
@@ -99,7 +97,7 @@ class NetworkWindow(PamhyrWindow):
|
||||
|
||||
self._reachs_model = EdgeTableModel(
|
||||
table_view = table,
|
||||
table_headers = table_headers_edge,
|
||||
table_headers = self._table_headers_edge,
|
||||
editable_headers = ["name", "node1", "node2"],
|
||||
delegates = {
|
||||
"node1": self.delegate_combobox,
|
||||
|
||||
@@ -18,23 +18,21 @@
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from View.Tools.PamhyrTranslate import PamhyrTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
table_headers_node = {
|
||||
"name": _translate("Network", "Name"),
|
||||
"type": _translate("Network", "Type"),
|
||||
}
|
||||
class NetworkTranslate(PamhyrTranslate):
|
||||
def __init__(self):
|
||||
super(NetworkTranslate, self).__init__()
|
||||
|
||||
table_headers_edge = {
|
||||
"name": _translate("Network", "Name"),
|
||||
"node1": _translate("Network", "Source node"),
|
||||
"node2": _translate("Network", "Destination node"),
|
||||
}
|
||||
self._sub_dict["table_headers_node"] = {
|
||||
"name": _translate("Network", "Name"),
|
||||
"type": _translate("Network", "Type"),
|
||||
}
|
||||
|
||||
def retranslate():
|
||||
table_headers_node["name"] = _translate("Network", "Name")
|
||||
table_headers_node["type"] = _translate("Network", "Type")
|
||||
|
||||
table_headers_edge["name"] = _translate("Network", "Name")
|
||||
table_headers_edge["node1"] = _translate("Network", "Source node")
|
||||
table_headers_edge["node2"] = _translate("Network", "Destination node")
|
||||
self._sub_dict["table_headers_edge"] = {
|
||||
"name": _translate("Network", "Name"),
|
||||
"node1": _translate("Network", "Source node"),
|
||||
"node2": _translate("Network", "Destination node"),
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
# PamhyrTranslate.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
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class PamhyrTranslate(object):
|
||||
def __init__(self):
|
||||
# Module global dictionnary
|
||||
self._dict = {}
|
||||
# Module sub dictionnary
|
||||
self._sub_dict = {}
|
||||
|
||||
def __getitem__(self, index):
|
||||
if index not in self._dict:
|
||||
return None
|
||||
return self._dict[index]
|
||||
|
||||
def _get_in_sub_dict(self, dictionary, index):
|
||||
if dictionary not in self._sub_dict:
|
||||
return None
|
||||
return self._sub_dict[index]
|
||||
|
||||
def get(self, dictionary, index):
|
||||
if dictionary == "global":
|
||||
return self[index]
|
||||
|
||||
return self._get_in_sub_dict(dictionary, index)
|
||||
|
||||
def get_dict(self, dictionary):
|
||||
_dict = None
|
||||
|
||||
if dictionary == "global":
|
||||
_dict = self._dict
|
||||
|
||||
if dictionary in self._sub_dict:
|
||||
_dict = self._sub_dict[dictionary]
|
||||
|
||||
return _dict
|
||||
@@ -140,12 +140,13 @@ class PamhyrWindow(ASubMainWindow, ListedSubWindow, PamhyrWindowTools):
|
||||
|
||||
def __init__(self,
|
||||
title = "Pamhyr2",
|
||||
study = None, config = None,
|
||||
study = None, config = None, trad = None,
|
||||
options = ["undo", "copy"],
|
||||
parent = None):
|
||||
self._title = title
|
||||
self._study = study
|
||||
self._config = config
|
||||
self._trad = trad
|
||||
self._parent = parent
|
||||
|
||||
super(PamhyrWindow, self).__init__(
|
||||
@@ -166,21 +167,22 @@ class PamhyrDialog(ASubWindow, ListedSubWindow, PamhyrWindowTools):
|
||||
|
||||
def __init__(self,
|
||||
title = "Pamhyr2",
|
||||
study = None, config = None,
|
||||
study = None, config = None, trad = None,
|
||||
options = ["undo", "copy"],
|
||||
parent = None):
|
||||
self._title = title
|
||||
self._study = study
|
||||
self._config = config
|
||||
self._trad = trad
|
||||
self._parent = parent
|
||||
|
||||
logger.info(self._pamhyr_name)
|
||||
logger.info(self._pamhyr_ui)
|
||||
|
||||
super(PamhyrDialog, self).__init__(
|
||||
name = self._pamhyr_name,
|
||||
ui = self._pamhyr_ui,
|
||||
parent = parent,
|
||||
)
|
||||
|
||||
self._hash_data.append(self._study)
|
||||
self._hash_data.append(self._config)
|
||||
|
||||
self._set_title()
|
||||
Reference in new issue
Block a user