Skip to content

Commit

Permalink
Move create_qsettings() out of preferences
Browse files Browse the repository at this point in the history
- Load order was impacting translations
- Fix by moving create_qsettings() for now
  • Loading branch information
arsenetar committed May 9, 2022
1 parent 7a44c72 commit 40ff40b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
29 changes: 3 additions & 26 deletions qt/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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()

Expand Down
24 changes: 23 additions & 1 deletion qt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

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,
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

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__
Expand Down

0 comments on commit 40ff40b

Please sign in to comment.