Fix #760, issue with language on windows

Fix the issue related to run.py qsettings not using the same options as
in preferences.py
This commit is contained in:
Andrew Senetar 2021-01-11 21:41:14 -06:00
parent 421a58a61c
commit 95ccbad92b
Signed by: arsenetar
GPG Key ID: C63300DCE48AB2F1
2 changed files with 18 additions and 14 deletions

View File

@ -66,6 +66,20 @@ def adjust_after_deserialization(v):
return v return v
def createQSettings():
# Create a QSettings instance with the correct arguments.
# On windows use an ini file in the AppDataLocation instead of registry if possible as it
# makes it easier for a user to clear it out when there are issues.
if ISWINDOWS:
Locations = QStandardPaths.standardLocations(QStandardPaths.AppDataLocation)
if Locations:
return QSettings(op.join(Locations[0], "settings.ini"), QSettings.IniFormat)
else:
return QSettings()
else:
return QSettings()
# About QRect conversion: # About QRect conversion:
# I think Qt supports putting basic structures like QRect directly in QSettings, but I prefer not # I think Qt supports putting basic structures like QRect directly in QSettings, but I prefer not
# to rely on it and stay with generic structures. # to rely on it and stay with generic structures.
@ -77,18 +91,7 @@ class Preferences(QObject):
def __init__(self): def __init__(self):
QObject.__init__(self) QObject.__init__(self)
self.reset() self.reset()
# On windows use an ini file in the AppDataLocation instead of registry if possible as it self._settings = createQSettings()
# makes it easier for a user to clear it out when there are issues.
if ISWINDOWS:
Locations = QStandardPaths.standardLocations(QStandardPaths.AppDataLocation)
if Locations:
self._settings = QSettings(
op.join(Locations[0], "settings.ini"), QSettings.IniFormat
)
else:
self._settings = QSettings()
else:
self._settings = QSettings()
def _load_values(self, settings, get): def _load_values(self, settings, get):
pass pass

5
run.py
View File

@ -9,13 +9,14 @@ import sys
import os.path as op import os.path as op
import gc import gc
from PyQt5.QtCore import QCoreApplication, QSettings from PyQt5.QtCore import QCoreApplication
from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from hscommon.trans import install_gettext_trans_under_qt from hscommon.trans import install_gettext_trans_under_qt
from qtlib.error_report_dialog import install_excepthook from qtlib.error_report_dialog import install_excepthook
from qtlib.util import setupQtLogging from qtlib.util import setupQtLogging
from qtlib.preferences import createQSettings
from qt import dg_rc # noqa: F401 from qt import dg_rc # noqa: F401
from qt.platform import BASE_PATH from qt.platform import BASE_PATH
from core import __version__, __appname__ from core import __version__, __appname__
@ -52,7 +53,7 @@ def main():
QCoreApplication.setApplicationName(__appname__) QCoreApplication.setApplicationName(__appname__)
QCoreApplication.setApplicationVersion(__version__) QCoreApplication.setApplicationVersion(__version__)
setupQtLogging() setupQtLogging()
settings = QSettings() settings = createQSettings()
lang = settings.value("Language") lang = settings.value("Language")
locale_folder = op.join(BASE_PATH, "locale") locale_folder = op.join(BASE_PATH, "locale")
install_gettext_trans_under_qt(locale_folder, lang) install_gettext_trans_under_qt(locale_folder, lang)