How to use the qutebrowser.config.config function in qutebrowser

To help you get started, we’ve selected a few qutebrowser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qutebrowser / qutebrowser / tests / unit / config / test_configcache.py View on Github external
def test_configcache_except_pattern(config_stub):
    with pytest.raises(AssertionError):
        assert config.cache['content.javascript.enabled']
github qutebrowser / qutebrowser / qutebrowser / browser / navigate.py View on Github external
rel_values = {'prev', 'previous'} if prev else {'next'}
    for e in elems:
        if e.tag_name() not in ['link', 'a'] or 'rel' not in e:
            continue
        if set(e['rel'].split(' ')) & rel_values:
            log.hints.debug("Found {!r} with rel={}".format(e, e['rel']))
            return e

    # Then check for regular links/buttons.
    elems = [e for e in elems if e.tag_name() != 'link']
    option = 'prev_regexes' if prev else 'next_regexes'
    if not elems:
        return None

    # pylint: disable=bad-config-option
    for regex in getattr(config.val.hints, option):
        # pylint: enable=bad-config-option
        log.hints.vdebug("== Checking regex '{}'.".format(regex.pattern))
        for e in elems:
            text = str(e)
            if not text:
                continue
            if regex.search(text):
                log.hints.debug("Regex '{}' matched on '{}'.".format(
                    regex.pattern, text))
                return e
            else:
                log.hints.vdebug("No match on '{}'!".format(text))
    return None
github qutebrowser / qutebrowser / qutebrowser / config / configcache.py View on Github external
def __getitem__(self, attr: str) -> typing.Any:
        try:
            return self._cache[attr]
        except KeyError:
            assert not config.instance.get_opt(attr).supports_pattern
            self._cache[attr] = config.instance.get(attr)
            return self._cache[attr]
github qutebrowser / qutebrowser / qutebrowser / browser / webengine / cookies.py View on Github external
def _accept_cookie(request):
    """Check whether the given cookie should be accepted."""
    accept = config.val.content.cookies.accept
    if accept == 'all':
        return True
    elif accept in ['no-3rdparty', 'no-unknown-3rdparty']:
        if qtutils.version_check('5.11.3', compiled=False):
            third_party = request.thirdParty
        else:
            # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-71393
            third_party = (request.thirdParty and
                           not request.firstPartyUrl.isEmpty())
        return not third_party
    elif accept == 'never':
        return False
    else:
        raise utils.Unreachable
github qutebrowser / qutebrowser / qutebrowser / browser / hints.py View on Github external
def _get_hint_mode(self, mode: typing.Optional[str]) -> str:
        """Get the hinting mode to use based on a mode argument."""
        if mode is None:
            return config.val.hints.mode

        opt = config.instance.get_opt('hints.mode')
        try:
            opt.typ.to_py(mode)
        except configexc.ValidationError as e:
            raise cmdutils.CommandError("Invalid mode: {}".format(e))
        return mode
github qutebrowser / qutebrowser / qutebrowser / commands / runners.py View on Github external
def _completion_match(self, cmdstr):
        """Replace cmdstr with a matching completion if there's only one match.

        Args:
            cmdstr: The string representing the entered command so far

        Return:
            cmdstr modified to the matching completion or unmodified
        """
        matches = [cmd for cmd in sorted(objects.commands, key=len)
                   if cmdstr in cmd]
        if len(matches) == 1:
            cmdstr = matches[0]
        elif len(matches) > 1 and config.val.completion.use_best_match:
            cmdstr = matches[0]
        return cmdstr
github qutebrowser / qutebrowser / qutebrowser / browser / network / proxy.py View on Github external
def get_error(self):
        """Check if proxy can't be resolved.

        Return:
           None if proxy is correct, otherwise an error message.
        """
        proxy = config.val.content.proxy
        if isinstance(proxy, pac.PACFetcher):
            return proxy.fetch_error()
        else:
            return None
github qutebrowser / qutebrowser / qutebrowser / mainwindow / tabwidget.py View on Github external
def _tab_layout(self, opt):
        """Compute the text/icon rect from the opt rect.

        This is based on Qt's QCommonStylePrivate::tabLayout
        (qtbase/src/widgets/styles/qcommonstyle.cpp) as we can't use the
        private implementation.

        Args:
            opt: QStyleOptionTab

        Return:
            A Layout object with two QRects.
        """
        padding = config.cache['tabs.padding']
        indicator_padding = config.cache['tabs.indicator.padding']

        text_rect = QRect(opt.rect)
        if not text_rect.isValid():
            # This happens sometimes according to crash reports, but no idea
            # why...
            return None

        text_rect.adjust(padding.left, padding.top, -padding.right,
                         -padding.bottom)

        indicator_width = config.cache['tabs.indicator.width']
        if indicator_width == 0:
            indicator_rect = QRect()
        else:
            indicator_rect = QRect(opt.rect)
            qtutils.ensure_valid(indicator_rect)
github qutebrowser / qutebrowser / qutebrowser / misc / consolewidget.py View on Github external
def __init__(self, _namespace, parent):
        """Constructor.

        Args:
            _namespace: The local namespace of the interpreter.
        """
        super().__init__(parent=parent)
        self._update_font()
        config.instance.changed.connect(self._update_font)
        self._history = cmdhistory.History(parent=self)
        self.returnPressed.connect(self.on_return_pressed)
github qutebrowser / qutebrowser / qutebrowser / browser / webengine / webenginetab.py View on Github external
def connect_signals(self):
        """Connect signals to our private slots."""
        config.instance.changed.connect(self._on_config_changed)

        self._tab.search.cleared.connect(functools.partial(
            self._update_stylesheet, searching=False))
        self._tab.search.finished.connect(self._update_stylesheet)