Add a context manager to unset organizationName.
This commit is contained in:
parent
83b636a0a7
commit
9534deb2e7
@ -37,6 +37,7 @@ import contextlib
|
|||||||
|
|
||||||
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
|
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
|
||||||
QIODevice, QSaveFile)
|
QIODevice, QSaveFile)
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
|
|
||||||
MAXVALS = {
|
MAXVALS = {
|
||||||
@ -200,6 +201,21 @@ def savefile_open(filename, binary=False, encoding='utf-8'):
|
|||||||
raise OSError(f.errorString())
|
raise OSError(f.errorString())
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def unset_organization():
|
||||||
|
"""Temporarily unset QApplication.organizationName().
|
||||||
|
|
||||||
|
This is primarily needed in config.py.
|
||||||
|
"""
|
||||||
|
qapp = QApplication.instance()
|
||||||
|
orgname = qapp.organizationName()
|
||||||
|
qapp.setOrganizationName(None)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
qapp.setOrganizationName(orgname)
|
||||||
|
|
||||||
|
|
||||||
class PyQIODevice(io.BufferedIOBase):
|
class PyQIODevice(io.BufferedIOBase):
|
||||||
|
|
||||||
"""Wrapper for a QIODevice which provides a python interface.
|
"""Wrapper for a QIODevice which provides a python interface.
|
||||||
|
@ -24,21 +24,13 @@ import os.path
|
|||||||
|
|
||||||
from PyQt5.QtCore import QCoreApplication, QStandardPaths
|
from PyQt5.QtCore import QCoreApplication, QStandardPaths
|
||||||
|
|
||||||
from qutebrowser.utils import log
|
from qutebrowser.utils import log, qtutils
|
||||||
|
|
||||||
|
|
||||||
def _writable_location(typ):
|
def _writable_location(typ):
|
||||||
"""Wrapper around QStandardPaths.writableLocation."""
|
"""Wrapper around QStandardPaths.writableLocation."""
|
||||||
qapp = QCoreApplication.instance()
|
with qtutils.unset_organization():
|
||||||
orgname = qapp.organizationName()
|
|
||||||
# We need to temporarily unset the organisationname here since the
|
|
||||||
# webinspector wants it to be set to store its persistent data correctly,
|
|
||||||
# but we don't want that to happen.
|
|
||||||
qapp.setOrganizationName(None)
|
|
||||||
try:
|
|
||||||
path = QStandardPaths.writableLocation(typ)
|
path = QStandardPaths.writableLocation(typ)
|
||||||
finally:
|
|
||||||
qapp.setOrganizationName(orgname)
|
|
||||||
if not path:
|
if not path:
|
||||||
raise ValueError("QStandardPaths returned an empty value!")
|
raise ValueError("QStandardPaths returned an empty value!")
|
||||||
# Qt seems to use '/' as path separator even on Windows...
|
# Qt seems to use '/' as path separator even on Windows...
|
||||||
|
Loading…
Reference in New Issue
Block a user