diff --git a/src/config.py b/src/config.py index f009768062dc73f4f20ce6b09a53982e08f8afa4..1417e86df1d7620351a107a32ed3a790fbc0523f 100644 --- a/src/config.py +++ b/src/config.py @@ -30,10 +30,21 @@ class Config(object): self.backup_frequence = "00:05:00" self.backup_max = 10 + # Languages + self.lang = "" + @classmethod def filename(cls): return os.environ["HOME"] + config_dir + config_file + @classmethod + def languages(cls): + return { + "System": "", + "English": "en", + "French": "fr", + } + def save(self): os.makedirs(os.path.dirname(self.filename), exist_ok=True) with open(self.filename, 'wb') as out_file: diff --git a/src/pamhyr.py b/src/pamhyr.py index 3c02c32776c521d85b885c98c5b0b5ea2748bc63..1ca646ac072343bf462f340f8ffc92b0ba4cfd79 100755 --- a/src/pamhyr.py +++ b/src/pamhyr.py @@ -16,9 +16,25 @@ def main(): app = QApplication(sys.argv) translator = QTranslator() - lang = locale.getdefaultlocale() - if "fr" not in lang[0]: - translator.load(os.path.dirname(__file__) + "/lang/fr.qm") + + lang_file = "" + if conf.lang == "": + # System language + sys_lang = locale.getdefaultlocale() + if "fr" in sys_lang[0]: + lang_file = os.path.dirname(__file__) + "/lang/fr.qm" + elif conf.lang == "fr": + # French + lang_file = os.path.dirname(__file__) + "/lang/fr.qm" + else: + lang_file = "" + # English default language + + if lang_file != "": + ok = translator.load(lang_file) + if not ok: + print("failed") + app.installTranslator(translator) application = ApplicationWindow(conf=conf) diff --git a/src/view/ASubWindow.py b/src/view/ASubWindow.py index 29ef8c8125d280fc3ad2ae5addd471fb3b394a1e..a2bd75492167012cc91d2bb299c823dc6fcb1082 100644 --- a/src/view/ASubWindow.py +++ b/src/view/ASubWindow.py @@ -237,6 +237,17 @@ class ASubWindow(QDialog): """ self.find(QComboBox, name).setCurrentText(item) + def get_combobox_text(self, name:str): + """Get current text of combo box + + Args: + name: The combo box component name + + Returns: + Current text + """ + return self.find(QComboBox, name).currentText() + # Custom dialog def file_dialog(self, select_file=True, callback=lambda x: None): diff --git a/src/view/ConfigureWindow.py b/src/view/ConfigureWindow.py index 4962fa20928233193dc05c0fa99304a68be3f6b6..551bf3fab21d45ed2e65c281a20f83e1a1aada2a 100644 --- a/src/view/ConfigureWindow.py +++ b/src/view/ConfigureWindow.py @@ -11,7 +11,8 @@ from PyQt5.QtCore import ( from PyQt5.QtWidgets import ( QDialogButtonBox, QPushButton, QLineEdit, - QFileDialog, QTableView, QAbstractItemView + QFileDialog, QTableView, QAbstractItemView, + QComboBox, ) @@ -90,6 +91,13 @@ class ConfigureWindow(ASubWindow, ListedSubWindow): self.find(QTableView, "tableView_solver").resizeColumnsToContents() self.connect() + # Language + languages = Config.languages() + for lang in languages: + self.combobox_add_item("comboBox_language", lang) + if self.conf.lang == languages[lang]: + self.set_combobox_text("comboBox_language", lang) + def connect(self): buttons = { "pushButton_solver_add": self.add_solver, @@ -129,6 +137,9 @@ class ConfigureWindow(ASubWindow, ListedSubWindow): self.conf.backup_frequence = self.get_time_edit("timeEdit_backup_frequence") self.conf.backup_max = self.get_spin_box("spinBox_backup_max") + # Language + self.conf.lang = Config.languages()[self.get_combobox_text("comboBox_language")] + self.end() def reject(self): diff --git a/src/view/MainWindow.py b/src/view/MainWindow.py index 222415d62c9885a8a2f58df2459d522b1bef9187..4b4e7754b21eb230b613589867f4d2d88902313d 100644 --- a/src/view/MainWindow.py +++ b/src/view/MainWindow.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import os +from queue import Queue from PyQt5 import QtGui from PyQt5.QtCore import ( @@ -18,6 +19,7 @@ from view.ConfigureWindow import ConfigureWindow from view.NewStudyWindow import NewStudyWindow from view.NetworkWindow import NetworkWindow from view.AboutWindow import AboutWindow +from view.ui.MainWindow import Ui_MainWindow from model.Study import Study @@ -78,7 +80,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow): Returns: Nothing """ - self.ui.findChild(QAction, action).setEnabled(enable) + self.findChild(QAction, action).setEnabled(enable) def init_callback(self): """Connect action to callback function @@ -115,30 +117,13 @@ class ApplicationWindow(QMainWindow, ListedSubWindow): "action_toolBar_sections": lambda: self.open_dummy("Tronçons"), "action_toolBar_frictions": lambda: self.open_dummy("Frottements"), "action_toolBar_building": lambda: self.open_dummy("Ouvrages"), - ## Language - "action_english": lambda: self.set_language(""), - "action_french": lambda: self.set_language("fr"), } for action in actions: - self.ui.findChild(QAction, action)\ - .triggered.connect(actions[action]) - - def set_language(self, lang): - if lang != "": - translator = QTranslator() - translator.load(os.path.dirname(__file__) + f"/lang/{lang}.qm") - QApplication.instance().installTranslator(translator) - self.trans = translator - else: - QApplication.instance().removeTranslator(self.trans) - - self.retranslateUi() + self.findChild(QAction, action)\ + .triggered.connect(actions[action]) + # action.triggered.connect(actions[action]) - def retranslateUi(self): - for action in self.menubar.children(): - if isinstance(action, QAction): - action.setText(self.trans("MainWindow", action.getText())) def changeEvent(self, event): if event.type() == QEvent.LanguageChange: diff --git a/src/view/ui/ConfigureDialog.ui b/src/view/ui/ConfigureDialog.ui index 77a43e434fadc72a74abdab443a407da22664c9c..c54b2b45f4d0f9131892190d7a7773315664035b 100644 --- a/src/view/ui/ConfigureDialog.ui +++ b/src/view/ui/ConfigureDialog.ui @@ -107,7 +107,7 @@ </item> </layout> </widget> - <widget class="QWidget" name="tab_mailleur"> + <widget class="QWidget" name="tab_mesh"> <attribute name="title"> <string>Meshing tool</string> </attribute> @@ -116,7 +116,7 @@ <rect> <x>10</x> <y>10</y> - <width>621</width> + <width>611</width> <height>30</height> </rect> </property> @@ -155,7 +155,7 @@ <x>10</x> <y>10</y> <width>621</width> - <height>93</height> + <height>61</height> </rect> </property> <layout class="QHBoxLayout" name="horizontalLayout"> @@ -198,7 +198,7 @@ </layout> </widget> </widget> - <widget class="QWidget" name="tab"> + <widget class="QWidget" name="tab_backup"> <attribute name="title"> <string>Backup</string> </attribute> @@ -208,7 +208,7 @@ <x>10</x> <y>10</y> <width>611</width> - <height>125</height> + <height>121</height> </rect> </property> <layout class="QHBoxLayout" name="horizontalLayout_4"> @@ -313,6 +313,51 @@ </layout> </widget> </widget> + <widget class="QWidget" name="tab_2"> + <attribute name="title"> + <string>Language</string> + </attribute> + <widget class="QLabel" name="label_4"> + <property name="geometry"> + <rect> + <x>11</x> + <y>11</y> + <width>309</width> + <height>16</height> + </rect> + </property> + <property name="font"> + <font> + <italic>true</italic> + </font> + </property> + <property name="text"> + <string>Please restart application after language modification</string> + </property> + </widget> + <widget class="QWidget" name=""> + <property name="geometry"> + <rect> + <x>11</x> + <y>33</y> + <width>191</width> + <height>26</height> + </rect> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Language</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="comboBox_language"/> + </item> + </layout> + </widget> + </widget> </widget> </item> <item> diff --git a/src/view/ui/MainWindow.ui b/src/view/ui/MainWindow.ui index 41ce2ca61feb19d234e53b5d9d7aeae1aafe5f41..d5a2b90054be98951693aa35d0388db0a6f2446f 100644 --- a/src/view/ui/MainWindow.ui +++ b/src/view/ui/MainWindow.ui @@ -201,16 +201,6 @@ <addaction name="action_menu_help_mage"/> <addaction name="action_menu_about"/> </widget> - <widget class="QMenu" name="menu_language"> - <property name="locale"> - <locale language="English" country="Europe"/> - </property> - <property name="title"> - <string>&Language</string> - </property> - <addaction name="action_english"/> - <addaction name="action_french"/> - </widget> <addaction name="menu_File"/> <addaction name="menu_network"/> <addaction name="menu_geometry"/> @@ -218,7 +208,6 @@ <addaction name="menu_run"/> <addaction name="menu_plot"/> <addaction name="menu_cartography"/> - <addaction name="menu_language"/> <addaction name="menu_help"/> </widget> <widget class="QStatusBar" name="statusbar"/>