Adds languages combo to preferences

This commit is contained in:
Bruno Kühnen Meneguello
2021-02-16 23:07:13 -03:00
parent ae53ce5544
commit 48575c09ca
2 changed files with 30 additions and 0 deletions
+10
View File
@@ -393,6 +393,16 @@ class Config:
return
def listLanguages(self):
langs = dict(map(lambda lang: (lang, QLocale(lang).nativeLanguageName().title()),
map(lambda v: v[0][3:],
filter(lambda v: v[0].startswith("nw_") and v[1] == ".qm",
map(os.path.splitext, os.listdir(self.nwLangPath))))))
if "en" not in langs:
langs["en"] = QLocale("en").nativeLanguageName().title()
return sorted(langs.items(), key=lambda x: x[0])
def loadConfig(self):
"""Load preferences from file and replace default settings.
"""
+20
View File
@@ -138,6 +138,23 @@ class GuiPreferencesGeneral(QWidget):
# =============
self.mainForm.addGroupLabel(self.tr("Look and Feel"))
## Select Locale
self.guiLang = QComboBox()
self.guiLang.setMinimumWidth(self.mainConf.pxInt(200))
self.theLangs = self.mainConf.listLanguages()
print(self.theLangs)
for lang, langName in self.theLangs:
self.guiLang.addItem(langName, lang)
langIdx = self.guiLang.findData(self.mainConf.guiLang)
if langIdx != -1:
self.guiLang.setCurrentIndex(langIdx)
self.mainForm.addRow(
self.tr("Main GUI language"),
self.guiLang,
self.tr("Changing this requires restarting novelWriter.")
)
## Select Theme
self.guiTheme = QComboBox()
self.guiTheme.setMinimumWidth(self.mainConf.pxInt(200))
@@ -240,6 +257,7 @@ class GuiPreferencesGeneral(QWidget):
def saveValues(self):
"""Save the values set for this tab.
"""
guiLang = self.guiLang.currentData()
guiTheme = self.guiTheme.currentData()
guiIcons = self.guiIcons.currentData()
guiDark = self.guiDark.isChecked()
@@ -248,12 +266,14 @@ class GuiPreferencesGeneral(QWidget):
# Check if restart is needed
needsRestart = False
needsRestart |= self.mainConf.guiLang != guiLang
needsRestart |= self.mainConf.guiTheme != guiTheme
needsRestart |= self.mainConf.guiIcons != guiIcons
needsRestart |= self.mainConf.guiDark != guiDark
needsRestart |= self.mainConf.guiFont != guiFont
needsRestart |= self.mainConf.guiFontSize != guiFontSize
self.mainConf.guiLang = guiLang
self.mainConf.guiTheme = guiTheme
self.mainConf.guiIcons = guiIcons
self.mainConf.guiDark = guiDark