diff --git a/widgets/ToolBar.py b/widgets/ToolBar.py index f319337..9e71a56 100755 --- a/widgets/ToolBar.py +++ b/widgets/ToolBar.py @@ -23,7 +23,6 @@ def __init__(self, actionManager, parent=None): self.cb = QComboBox() self.cb.addItems(["Chinese", "English", "Tibetan"]) self.cb.currentIndexChanged.connect(self.onSelectionchange) - self.addWidget(self.cb) if self.cb.currentText() == 'Chinese': @@ -33,13 +32,21 @@ def __init__(self, actionManager, parent=None): else: value = 'tibetan' - language = Setting.objects.filter(key='language') - if not language: + if not Setting.objects.filter(key='language').exists(): Setting.objects.create( key='language', value=value ) + # 一開始的,也要顯示上次選擇後的當前語言 + language = Setting.objects.get(key='language') + if language.value == 'zh-hant': + self.cb.setCurrentIndex(0) + elif language.value == 'en': + self.cb.setCurrentIndex(1) + else: + self.cb.setCurrentIndex(2) + def onSelectionchange(self,i): if self.cb.currentText() == 'Chinese': value = 'zh-hant' @@ -49,14 +56,29 @@ def onSelectionchange(self,i): value = 'tibetan' language = Setting.objects.get(key='language') + oldLanguage = language.value + newLanguage = value + +# # 選擇語言後,依然顯示當前語言? +# languageN = language.value +# if languageN == 'zh-hant': +# self.cb.setCurrentIndex(0) +# elif languageN == 'en': +# self.cb.setCurrentIndex(1) +# else: +# self.cb.setCurrentIndex(2) + + # 設定所選擇的語言 if language: language.value=value language.save() - msg = QMessageBox() - msg.setIcon(QMessageBox.Information) - msg.setText(str(_("You can change the language until you activate the editor next time."))) - retval = msg.exec_() + # 需要更換語言時才顯示提醒 + if oldLanguage != newLanguage: + msg = QMessageBox() + msg.setIcon(QMessageBox.Information) + msg.setText(str(_("You can change the language until you activate the editor next time.") + '\n' + f'language:{value}')) + retval = msg.exec_() translation.activate(value)