Skip to content

Commit

Permalink
Fix #760, issue with language on windows
Browse files Browse the repository at this point in the history
Fix the issue related to run.py qsettings not using the same options as
in preferences.py
  • Loading branch information
arsenetar committed Jan 12, 2021
1 parent 421a58a commit 95ccbad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
27 changes: 15 additions & 12 deletions qtlib/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
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__
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 95ccbad

Please sign in to comment.