Permalink
Browse files

Initial stubbing out of a new config

  • Loading branch information...
The-Compiler committed Jun 8, 2017
1 parent d2c289b commit 3385fe1560409a9125e5ea8713c17dac304bc0ce
@@ -148,7 +148,8 @@ def init(args, crash_handler):
log.init.debug("Connecting signals...")
config_obj = objreg.get('config')
config_obj.style_changed.connect(style.get_stylesheet.cache_clear)
# FIXME:conf
# config_obj.style_changed.connect(style.get_stylesheet.cache_clear)
qApp.focusChanged.connect(on_focus_changed)
_process_args(args)
@@ -106,6 +106,8 @@ def _get_alias(self, text, default=None):
The new command string if an alias was found. Default value
otherwise.
"""
# FIXME:conf
return default
parts = text.strip().split(maxsplit=1)
try:
alias = config.get('aliases', parts[0])
@@ -285,9 +285,10 @@ def _get_cmd_completions(include_hidden, include_aliases, prefix=''):
bindings = ', '.join(cmd_to_keys.get(obj.name, []))
cmdlist.append((prefix + obj.name, obj.desc, bindings))
if include_aliases:
for name, cmd in config.section('aliases').items():
bindings = ', '.join(cmd_to_keys.get(name, []))
cmdlist.append((name, "Alias for '{}'".format(cmd), bindings))
# FIXME:conf
# if include_aliases:
# for name, cmd in config.section('aliases').items():
# bindings = ', '.join(cmd_to_keys.get(name, []))
# cmdlist.append((name, "Alias for '{}'".format(cmd), bindings))
return cmdlist
@@ -37,7 +37,7 @@
from PyQt5.QtCore import pyqtSignal, QObject, QUrl, QSettings
from PyQt5.QtGui import QColor
from qutebrowser.config import configdata, configexc, textwrapper
from qutebrowser.config import configdata, configexc, textwrapper, newconfig
from qutebrowser.config.parsers import keyconf
from qutebrowser.config.parsers import ini
from qutebrowser.commands import cmdexc, cmdutils
@@ -132,7 +132,8 @@ def get(*args, **kwargs):
def section(sect):
"""Get a config section from the global config."""
return objreg.get('config')[sect]
config = objreg.get('config')
return newconfig.SectionStub(config, sect)
def _init_main_config(parent=None):
@@ -242,13 +243,20 @@ def _init_misc():
QSettings.setPath(fmt, QSettings.UserScope, path)
def _init_new_config(parent):
new_config = newconfig.NewConfigManager(parent)
new_config.read_defaults()
objreg.register('config', new_config)
def init(parent=None):
"""Initialize the config.
Args:
parent: The parent to pass to QObjects which get initialized.
"""
_init_main_config(parent)
# _init_main_config(parent)
_init_new_config(parent)
_init_key_config(parent)
_init_misc()
@@ -27,6 +27,8 @@
sections.
"""
# FIXME:conf reintroduce interpolation?
import sys
import re
import collections
@@ -121,6 +123,13 @@
DEFAULT_FONT_SIZE = '10pt' if sys.platform == 'darwin' else '8pt'
# FIXME:conf what to do about this?
MONOSPACE = (' xos4 Terminus, Terminus, Monospace, '
'"DejaVu Sans Mono", Monaco, '
'"Bitstream Vera Sans Mono", "Andale Mono", '
'"Courier New", Courier, "Liberation Mono", '
'monospace, Fixed, Consolas, Terminal')
def data(readonly=False):
@@ -155,7 +164,7 @@ def data(readonly=False):
"the filename will be appended."),
('default-page',
SettingValue(typ.FuzzyUrl(), '${startpage}'),
SettingValue(typ.FuzzyUrl(), 'https://start.duckduckgo.com/'),
"The page to open if :open -t/-b/-w is used without URL. Use "
"`about:blank` for a blank page."),
@@ -1051,7 +1060,7 @@ def data(readonly=False):
"Top border color of the completion widget category headers."),
('completion.category.border.bottom',
SettingValue(typ.QssColor(), '${completion.category.border.top}'),
SettingValue(typ.QssColor(), 'black'),
"Bottom border color of the completion widget category headers."),
('completion.item.selected.fg',
@@ -1068,19 +1077,19 @@ def data(readonly=False):
('completion.item.selected.border.bottom',
SettingValue(
typ.QssColor(), '${completion.item.selected.border.top}'),
typ.QssColor(), '#bbbb00'),
"Bottom border color of the selected completion item."),
('completion.match.fg',
SettingValue(typ.QssColor(), '#ff4444'),
"Foreground color of the matched text in the completion."),
('completion.scrollbar.fg',
SettingValue(typ.QssColor(), '${completion.fg}'),
SettingValue(typ.QssColor(), 'white'),
"Color of the scrollbar handle in completion view."),
('completion.scrollbar.bg',
SettingValue(typ.QssColor(), '${completion.bg}'),
SettingValue(typ.QssColor(), '#333333'),
"Color of the scrollbar in completion view"),
('statusbar.fg',
@@ -1092,49 +1101,49 @@ def data(readonly=False):
"Background color of the statusbar."),
('statusbar.fg.private',
SettingValue(typ.QssColor(), '${statusbar.fg}'),
SettingValue(typ.QssColor(), 'white'),
"Foreground color of the statusbar in private browsing mode."),
('statusbar.bg.private',
SettingValue(typ.QssColor(), '#666666'),
"Background color of the statusbar in private browsing mode."),
('statusbar.fg.insert',
SettingValue(typ.QssColor(), '${statusbar.fg}'),
SettingValue(typ.QssColor(), 'white'),
"Foreground color of the statusbar in insert mode."),
('statusbar.bg.insert',
SettingValue(typ.QssColor(), 'darkgreen'),
"Background color of the statusbar in insert mode."),
('statusbar.fg.command',
SettingValue(typ.QssColor(), '${statusbar.fg}'),
SettingValue(typ.QssColor(), 'white'),
"Foreground color of the statusbar in command mode."),
('statusbar.bg.command',
SettingValue(typ.QssColor(), '${statusbar.bg}'),
SettingValue(typ.QssColor(), 'black'),
"Background color of the statusbar in command mode."),
('statusbar.fg.command.private',
SettingValue(typ.QssColor(), '${statusbar.fg.private}'),
SettingValue(typ.QssColor(), 'white'),
"Foreground color of the statusbar in private browsing + command "
"mode."),
('statusbar.bg.command.private',
SettingValue(typ.QssColor(), '${statusbar.bg.private}'),
SettingValue(typ.QssColor(), 'grey'),
"Background color of the statusbar in private browsing + command "
"mode."),
('statusbar.fg.caret',
SettingValue(typ.QssColor(), '${statusbar.fg}'),
SettingValue(typ.QssColor(), 'white'),
"Foreground color of the statusbar in caret mode."),
('statusbar.bg.caret',
SettingValue(typ.QssColor(), 'purple'),
"Background color of the statusbar in caret mode."),
('statusbar.fg.caret-selection',
SettingValue(typ.QssColor(), '${statusbar.fg}'),
SettingValue(typ.QssColor(), 'white'),
"Foreground color of the statusbar in caret mode with a "
"selection"),
@@ -1148,7 +1157,7 @@ def data(readonly=False):
"Background color of the progress bar."),
('statusbar.url.fg',
SettingValue(typ.QssColor(), '${statusbar.fg}'),
SettingValue(typ.QssColor(), 'white'),
"Default foreground color of the URL in the statusbar."),
('statusbar.url.fg.success',
@@ -1200,11 +1209,11 @@ def data(readonly=False):
"Background color of selected odd tabs."),
('tabs.fg.selected.even',
SettingValue(typ.QtColor(), '${tabs.fg.selected.odd}'),
SettingValue(typ.QtColor(), 'white'),
"Foreground color of selected even tabs."),
('tabs.bg.selected.even',
SettingValue(typ.QtColor(), '${tabs.bg.selected.odd}'),
SettingValue(typ.QtColor(), 'black'),
"Background color of selected even tabs."),
('tabs.bg.bar',
@@ -1255,7 +1264,7 @@ def data(readonly=False):
"Color gradient start for download backgrounds."),
('downloads.fg.stop',
SettingValue(typ.QtColor(), '${downloads.fg.start}'),
SettingValue(typ.QtColor(), '#0000aa'),
"Color gradient end for download text."),
('downloads.bg.stop',
@@ -1356,31 +1365,31 @@ def data(readonly=False):
"Default monospace fonts."),
('completion',
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used in the completion widget."),
('completion.category',
SettingValue(typ.Font(), 'bold ${completion}'),
SettingValue(typ.Font(), 'bold ' + DEFAULT_FONT_SIZE + MONOSPACE),
"Font used in the completion categories."),
('tabbar',
SettingValue(typ.QtFont(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.QtFont(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used in the tab bar."),
('statusbar',
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used in the statusbar."),
('downloads',
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used for the downloadbar."),
('hints',
SettingValue(typ.Font(), 'bold 13px ${_monospace}'),
"Font used for the hints."),
('debug-console',
SettingValue(typ.QtFont(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.QtFont(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used for the debugging console."),
('web-family-standard',
@@ -1432,19 +1441,19 @@ def data(readonly=False):
"The default font size for fixed-pitch text."),
('keyhint',
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used in the keyhint widget."),
('messages.error',
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used for error messages."),
('messages.warning',
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used for warning messages."),
('messages.info',
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
SettingValue(typ.Font(), DEFAULT_FONT_SIZE + MONOSPACE),
"Font used for info messages."),
('prompts',
@@ -0,0 +1,61 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014-2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""New qutebrowser configuration code."""
from PyQt5.QtCore import pyqtSignal, QObject
from qutebrowser.config import configdata
class SectionStub:
# FIXME get rid of this once we get rid of sections
def __init__(self, conf, name):
self._conf = conf
self._name = name
def __getitem__(self, item):
return self._conf.get(self._name, item)
class NewConfigManager(QObject):
# FIXME:conf QObject?
changed = pyqtSignal(str, str) # FIXME:conf stub... where is this used?
def __init__(self, parent=None):
super().__init__(parent)
self._values = {}
def _key(self, sect, opt):
return sect + ' -> ' + opt
def read_defaults(self):
for name, section in configdata.data().items():
for key, value in section.items():
self._values[self._key(name, key)] = value
def get(self, section, option):
val = self._values[self._key(section, option)]
return val.typ.transform(val.value())
@@ -40,7 +40,7 @@ def get_stylesheet(template_str):
Return:
The formatted template as string.
"""
colordict = ColorDict(config.section('colors'))
colordict = ColorDict(config)
template = jinja2.Template(template_str)
return template.render(color=colordict, font=config.section('fonts'),
config=objreg.get('config'))
@@ -70,10 +70,13 @@ def _update_stylesheet(obj):
obj.setStyleSheet(get_stylesheet(obj.STYLESHEET))
class ColorDict(collections.UserDict):
class ColorDict:
"""A dict aimed at Qt stylesheet colors."""
def __init__(self, config):
self._config = config
def __getitem__(self, key):
"""Override dict __getitem__.
@@ -86,11 +89,7 @@ def __getitem__(self, key):
else, return the plain value.
"""
try:
val = self.data[key]
except KeyError:
log.config.exception("No color defined for {}!".format(key))
return ''
val = self._config.get('colors', key)
if isinstance(val, QColor):
# This could happen when accidentally declaring something as
# QtColor instead of Color in the config, and it'd go unnoticed as

0 comments on commit 3385fe1

Please sign in to comment.