From 95ccbad92bf9affd531d3e700cc5ef4b5e5535f1 Mon Sep 17 00:00:00 2001 From: Andrew Senetar Date: Mon, 11 Jan 2021 21:41:14 -0600 Subject: [PATCH] Fix #760, issue with language on windows Fix the issue related to run.py qsettings not using the same options as in preferences.py --- qtlib/preferences.py | 27 +++++++++++++++------------ run.py | 5 +++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/qtlib/preferences.py b/qtlib/preferences.py index ceffa7ef..9a859f5d 100644 --- a/qtlib/preferences.py +++ b/qtlib/preferences.py @@ -66,6 +66,20 @@ def adjust_after_deserialization(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: # 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. @@ -77,18 +91,7 @@ class Preferences(QObject): def __init__(self): QObject.__init__(self) self.reset() - # 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: - self._settings = QSettings( - op.join(Locations[0], "settings.ini"), QSettings.IniFormat - ) - else: - self._settings = QSettings() - else: - self._settings = QSettings() + self._settings = createQSettings() def _load_values(self, settings, get): pass diff --git a/run.py b/run.py index 76fd0cd0..e6f779e6 100644 --- a/run.py +++ b/run.py @@ -9,13 +9,14 @@ import sys import os.path as op import gc -from PyQt5.QtCore import QCoreApplication, QSettings +from PyQt5.QtCore import QCoreApplication from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtWidgets import QApplication from hscommon.trans import install_gettext_trans_under_qt from qtlib.error_report_dialog import install_excepthook from qtlib.util import setupQtLogging +from qtlib.preferences import createQSettings from qt import dg_rc # noqa: F401 from qt.platform import BASE_PATH from core import __version__, __appname__ @@ -52,7 +53,7 @@ def main(): QCoreApplication.setApplicationName(__appname__) QCoreApplication.setApplicationVersion(__version__) setupQtLogging() - settings = QSettings() + settings = createQSettings() lang = settings.value("Language") locale_folder = op.join(BASE_PATH, "locale") install_gettext_trans_under_qt(locale_folder, lang)