diff --git a/qt/preferences.py b/qt/preferences.py index dd267388..d0b84820 100644 --- a/qt/preferences.py +++ b/qt/preferences.py @@ -5,17 +5,15 @@ # http://www.gnu.org/licenses/gpl-3.0.html from PyQt5.QtWidgets import QApplication, QDockWidget -from PyQt5.QtCore import Qt, QSettings, QRect, QObject, pyqtSignal, QStandardPaths +from PyQt5.QtCore import Qt, QRect, QObject, pyqtSignal from PyQt5.QtGui import QColor from hscommon import trans -from hscommon.plat import ISLINUX, ISWINDOWS +from hscommon.plat import ISLINUX from core.app import AppMode from core.scanner import ScanType from hscommon.util import tryint -from core.util import executable_folder - -from os import path as op +from qt.util import create_qsettings def get_langnames(): @@ -70,27 +68,6 @@ def _adjust_after_deserialization(v): return v -def create_qsettings(): - # Create a QSettings instance with the correct arguments. - config_location = op.join(executable_folder(), "settings.ini") - if op.isfile(config_location): - settings = QSettings(config_location, QSettings.IniFormat) - settings.setValue("Portable", True) - elif ISWINDOWS: - # 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. - locations = QStandardPaths.standardLocations(QStandardPaths.AppDataLocation) - if locations: - settings = QSettings(op.join(locations[0], "settings.ini"), QSettings.IniFormat) - else: - settings = QSettings() - settings.setValue("Portable", False) - else: - settings = QSettings() - settings.setValue("Portable", False) - return settings - - class PreferencesBase(QObject): prefsChanged = pyqtSignal() diff --git a/qt/util.py b/qt/util.py index 1b8057ad..ba6e0eb6 100644 --- a/qt/util.py +++ b/qt/util.py @@ -14,8 +14,9 @@ import logging from core.util import executable_folder from hscommon.util import first +from hscommon.plat import ISWINDOWS -from PyQt5.QtCore import QStandardPaths +from PyQt5.QtCore import QStandardPaths, QSettings from PyQt5.QtGui import QPixmap, QIcon, QGuiApplication from PyQt5.QtWidgets import ( QSpacerItem, @@ -137,3 +138,24 @@ def escape_amp(s): # Returns `s` with escaped ampersand (& --> &&). QAction text needs to have & escaped because # that character is used to define "accel keys". return s.replace("&", "&&") + + +def create_qsettings(): + # Create a QSettings instance with the correct arguments. + config_location = op.join(executable_folder(), "settings.ini") + if op.isfile(config_location): + settings = QSettings(config_location, QSettings.IniFormat) + settings.setValue("Portable", True) + elif ISWINDOWS: + # 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. + locations = QStandardPaths.standardLocations(QStandardPaths.AppDataLocation) + if locations: + settings = QSettings(op.join(locations[0], "settings.ini"), QSettings.IniFormat) + else: + settings = QSettings() + settings.setValue("Portable", False) + else: + settings = QSettings() + settings.setValue("Portable", False) + return settings diff --git a/run.py b/run.py index 1c286235..d6b5d236 100644 --- a/run.py +++ b/run.py @@ -15,8 +15,7 @@ from PyQt5.QtWidgets import QApplication from hscommon.trans import install_gettext_trans_under_qt from qt.error_report_dialog import install_excepthook -from qt.util import setup_qt_logging -from qt.preferences import create_qsettings +from qt.util import setup_qt_logging, create_qsettings from qt import dg_rc # noqa: F401 from qt.platform import BASE_PATH from core import __version__, __appname__