Use object registry for config.
This commit is contained in:
parent
07dde5be80
commit
953e50721c
@ -56,7 +56,6 @@ class Application(QApplication):
|
|||||||
registry: The object registry of global objects.
|
registry: The object registry of global objects.
|
||||||
meta_registry: The object registry of object registries.
|
meta_registry: The object registry of object registries.
|
||||||
mainwindow: The MainWindow QWidget.
|
mainwindow: The MainWindow QWidget.
|
||||||
config: The main ConfigManager
|
|
||||||
_args: ArgumentParser instance.
|
_args: ArgumentParser instance.
|
||||||
_commandrunner: The main CommandRunner instance.
|
_commandrunner: The main CommandRunner instance.
|
||||||
_debugconsole: The ConsoleWidget for debugging.
|
_debugconsole: The ConsoleWidget for debugging.
|
||||||
@ -94,7 +93,6 @@ class Application(QApplication):
|
|||||||
self._keyparsers = None
|
self._keyparsers = None
|
||||||
self._crashdlg = None
|
self._crashdlg = None
|
||||||
self._crashlogfile = None
|
self._crashlogfile = None
|
||||||
self.config = None
|
|
||||||
self.keyconfig = None
|
self.keyconfig = None
|
||||||
|
|
||||||
sys.excepthook = self._exception_hook
|
sys.excepthook = self._exception_hook
|
||||||
@ -169,8 +167,8 @@ class Application(QApplication):
|
|||||||
else:
|
else:
|
||||||
confdir = self._args.confdir
|
confdir = self._args.confdir
|
||||||
try:
|
try:
|
||||||
self.config = config.ConfigManager(confdir, 'qutebrowser.conf',
|
config_obj = config.ConfigManager(
|
||||||
self)
|
confdir, 'qutebrowser.conf', self)
|
||||||
except (configtypes.ValidationError,
|
except (configtypes.ValidationError,
|
||||||
config.NoOptionError,
|
config.NoOptionError,
|
||||||
config.NoSectionError,
|
config.NoSectionError,
|
||||||
@ -190,6 +188,8 @@ class Application(QApplication):
|
|||||||
msgbox.exec_()
|
msgbox.exec_()
|
||||||
# We didn't really initialize much so far, so we just quit hard.
|
# We didn't really initialize much so far, so we just quit hard.
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
self.registry['config'] = config_obj
|
||||||
try:
|
try:
|
||||||
self.keyconfig = keyconfparser.KeyConfigParser(
|
self.keyconfig = keyconfparser.KeyConfigParser(
|
||||||
confdir, 'keys.conf')
|
confdir, 'keys.conf')
|
||||||
@ -346,7 +346,7 @@ class Application(QApplication):
|
|||||||
|
|
||||||
if tabbedbrowser.count() == 0:
|
if tabbedbrowser.count() == 0:
|
||||||
log.init.debug("Opening startpage")
|
log.init.debug("Opening startpage")
|
||||||
for urlstr in self.config.get('general', 'startpage'):
|
for urlstr in config.get('general', 'startpage'):
|
||||||
try:
|
try:
|
||||||
url = urlutils.fuzzy_url(urlstr)
|
url = urlutils.fuzzy_url(urlstr)
|
||||||
except urlutils.FuzzyUrlError as e:
|
except urlutils.FuzzyUrlError as e:
|
||||||
@ -385,6 +385,7 @@ class Application(QApplication):
|
|||||||
prompter = self.registry['prompter']
|
prompter = self.registry['prompter']
|
||||||
cmd_history = self.registry['cmd_history']
|
cmd_history = self.registry['cmd_history']
|
||||||
downloadmanager = self.registry['downloadmanager']
|
downloadmanager = self.registry['downloadmanager']
|
||||||
|
config_obj = self.registry['config']
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
self.lastWindowClosed.connect(self.shutdown)
|
self.lastWindowClosed.connect(self.shutdown)
|
||||||
@ -423,10 +424,10 @@ class Application(QApplication):
|
|||||||
Qt.DirectConnection)
|
Qt.DirectConnection)
|
||||||
|
|
||||||
# config
|
# config
|
||||||
self.config.style_changed.connect(style.get_stylesheet.cache_clear)
|
config_obj.style_changed.connect(style.get_stylesheet.cache_clear)
|
||||||
for obj in (tabs, completion, mainwin, cmd_history,
|
for obj in (tabs, completion, mainwin, cmd_history,
|
||||||
websettings, modeman, status, status.txt):
|
websettings, modeman, status, status.txt):
|
||||||
self.config.changed.connect(obj.on_config_changed)
|
config_obj.changed.connect(obj.on_config_changed)
|
||||||
for obj in kp.values():
|
for obj in kp.values():
|
||||||
self.keyconfig.changed.connect(obj.on_keyconfig_changed)
|
self.keyconfig.changed.connect(obj.on_keyconfig_changed)
|
||||||
|
|
||||||
@ -767,11 +768,16 @@ class Application(QApplication):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
# Save everything
|
# Save everything
|
||||||
if hasattr(self, 'config') and self.config is not None:
|
try:
|
||||||
|
config_obj = self.registry['config']
|
||||||
|
except KeyError:
|
||||||
|
log.destroy.debug("Config not initialized yet, so not saving "
|
||||||
|
"anything.")
|
||||||
|
else:
|
||||||
to_save = []
|
to_save = []
|
||||||
if self.config.get('general', 'auto-save-config'):
|
if config.get('general', 'auto-save-config'):
|
||||||
if hasattr(self, 'config'):
|
if hasattr(self, 'config'):
|
||||||
to_save.append(("config", self.config.save))
|
to_save.append(("config", config_obj.save))
|
||||||
if hasattr(self, 'keyconfig'):
|
if hasattr(self, 'keyconfig'):
|
||||||
to_save.append(("keyconfig", self.keyconfig.save))
|
to_save.append(("keyconfig", self.keyconfig.save))
|
||||||
to_save += [("window geometry", self._save_geometry),
|
to_save += [("window geometry", self._save_geometry),
|
||||||
@ -802,9 +808,6 @@ class Application(QApplication):
|
|||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
log.destroy.warning("Could not save {}.".format(what))
|
log.destroy.warning("Could not save {}.".format(what))
|
||||||
log.destroy.debug(e)
|
log.destroy.debug(e)
|
||||||
else:
|
|
||||||
log.destroy.debug("Config not initialized yet, so not saving "
|
|
||||||
"anything.")
|
|
||||||
# Re-enable faulthandler to stdout, then remove crash log
|
# Re-enable faulthandler to stdout, then remove crash log
|
||||||
log.destroy.debug("Deactiving crash log...")
|
log.destroy.debug("Deactiving crash log...")
|
||||||
self._destroy_crashlogfile()
|
self._destroy_crashlogfile()
|
||||||
|
@ -30,28 +30,23 @@ import functools
|
|||||||
import configparser
|
import configparser
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, QObject, QCoreApplication
|
from PyQt5.QtCore import pyqtSignal, QObject
|
||||||
|
|
||||||
from qutebrowser.utils import log
|
from qutebrowser.utils import log
|
||||||
from qutebrowser.config import configdata, iniparsers, configtypes, textwrapper
|
from qutebrowser.config import configdata, iniparsers, configtypes, textwrapper
|
||||||
from qutebrowser.commands import cmdexc, cmdutils
|
from qutebrowser.commands import cmdexc, cmdutils
|
||||||
from qutebrowser.utils import message
|
from qutebrowser.utils import message, utils
|
||||||
from qutebrowser.utils.usertypes import Completion
|
from qutebrowser.utils.usertypes import Completion
|
||||||
|
|
||||||
|
|
||||||
def instance():
|
|
||||||
"""Get the global config instance."""
|
|
||||||
return QCoreApplication.instance().config
|
|
||||||
|
|
||||||
|
|
||||||
def get(*args, **kwargs):
|
def get(*args, **kwargs):
|
||||||
"""Convenience method to call get(...) of the config instance."""
|
"""Convenience method to call get(...) of the config instance."""
|
||||||
return instance().get(*args, **kwargs)
|
return utils.get_object('config').get(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def section(sect):
|
def section(sect):
|
||||||
"""Get a config section from the global config."""
|
"""Get a config section from the global config."""
|
||||||
return instance()[sect]
|
return utils.get_object('config')[sect]
|
||||||
|
|
||||||
|
|
||||||
class NoSectionError(configparser.NoSectionError):
|
class NoSectionError(configparser.NoSectionError):
|
||||||
|
@ -25,7 +25,7 @@ import jinja2
|
|||||||
from PyQt5.QtGui import QColor
|
from PyQt5.QtGui import QColor
|
||||||
|
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.utils import log
|
from qutebrowser.utils import log, utils
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=16)
|
@functools.lru_cache(maxsize=16)
|
||||||
@ -42,7 +42,7 @@ def get_stylesheet(template_str):
|
|||||||
fontdict = FontDict(config.section('fonts'))
|
fontdict = FontDict(config.section('fonts'))
|
||||||
template = jinja2.Template(template_str)
|
template = jinja2.Template(template_str)
|
||||||
return template.render(color=colordict, font=fontdict,
|
return template.render(color=colordict, font=fontdict,
|
||||||
config=config.instance())
|
config=utils.get_object('config'))
|
||||||
|
|
||||||
|
|
||||||
def set_register_stylesheet(obj):
|
def set_register_stylesheet(obj):
|
||||||
@ -60,7 +60,7 @@ def set_register_stylesheet(obj):
|
|||||||
log.style.vdebug("stylesheet for {}: {}".format(
|
log.style.vdebug("stylesheet for {}: {}".format(
|
||||||
obj.__class__.__name__, qss))
|
obj.__class__.__name__, qss))
|
||||||
obj.setStyleSheet(qss)
|
obj.setStyleSheet(qss)
|
||||||
config.instance().changed.connect(
|
utils.get_object('config').changed.connect(
|
||||||
functools.partial(_update_stylesheet, obj))
|
functools.partial(_update_stylesheet, obj))
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject
|
|||||||
|
|
||||||
from qutebrowser.config import config, configdata
|
from qutebrowser.config import config, configdata
|
||||||
from qutebrowser.commands import cmdutils
|
from qutebrowser.commands import cmdutils
|
||||||
from qutebrowser.utils import usertypes, log
|
from qutebrowser.utils import usertypes, log, utils
|
||||||
from qutebrowser.models import completion as models
|
from qutebrowser.models import completion as models
|
||||||
from qutebrowser.models.completionfilter import CompletionFilterModel as CFM
|
from qutebrowser.models.completionfilter import CompletionFilterModel as CFM
|
||||||
|
|
||||||
@ -69,6 +69,7 @@ class Completer(QObject):
|
|||||||
|
|
||||||
def _init_setting_completions(self):
|
def _init_setting_completions(self):
|
||||||
"""Initialize setting completion models."""
|
"""Initialize setting completion models."""
|
||||||
|
config_obj = utils.get_object('config')
|
||||||
self._models[usertypes.Completion.section] = CFM(
|
self._models[usertypes.Completion.section] = CFM(
|
||||||
models.SettingSectionCompletionModel(self), self)
|
models.SettingSectionCompletionModel(self), self)
|
||||||
self._models[usertypes.Completion.option] = {}
|
self._models[usertypes.Completion.option] = {}
|
||||||
@ -77,13 +78,13 @@ class Completer(QObject):
|
|||||||
model = models.SettingOptionCompletionModel(sectname, self)
|
model = models.SettingOptionCompletionModel(sectname, self)
|
||||||
self._models[usertypes.Completion.option][sectname] = CFM(
|
self._models[usertypes.Completion.option][sectname] = CFM(
|
||||||
model, self)
|
model, self)
|
||||||
config.instance().changed.connect(model.on_config_changed)
|
config_obj.changed.connect(model.on_config_changed)
|
||||||
self._models[usertypes.Completion.value][sectname] = {}
|
self._models[usertypes.Completion.value][sectname] = {}
|
||||||
for opt in configdata.DATA[sectname].keys():
|
for opt in configdata.DATA[sectname].keys():
|
||||||
model = models.SettingValueCompletionModel(sectname, opt, self)
|
model = models.SettingValueCompletionModel(sectname, opt, self)
|
||||||
self._models[usertypes.Completion.value][sectname][opt] = CFM(
|
self._models[usertypes.Completion.value][sectname][opt] = CFM(
|
||||||
model, self)
|
model, self)
|
||||||
config.instance().changed.connect(model.on_config_changed)
|
config_obj.changed.connect(model.on_config_changed)
|
||||||
|
|
||||||
def _get_new_completion(self, parts, cursor_part):
|
def _get_new_completion(self, parts, cursor_part):
|
||||||
"""Get a new completion model.
|
"""Get a new completion model.
|
||||||
|
Loading…
Reference in New Issue
Block a user