How to use the qutebrowser.utils.usertypes 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 / utils / usertypes / test_enum.py View on Github external
def test_is_int():
    """Test the is_int argument."""
    int_enum = usertypes.enum('Enum', ['item'], is_int=True)
    no_int_enum = usertypes.enum('Enum', ['item'])
    assert isinstance(int_enum.item, int)
    assert not isinstance(no_int_enum.item, int)
github qutebrowser / qutebrowser / tests / helpers / messagemock.py View on Github external
def _record_message(self, level, text):
        log_levels = {
            usertypes.MessageLevel.error: logging.ERROR,
            usertypes.MessageLevel.info: logging.INFO,
            usertypes.MessageLevel.warning: logging.WARNING,
        }
        log_level = log_levels[level]

        logging.getLogger('messagemock').log(log_level, text)
        self.messages.append(Message(level, text))
github qutebrowser / qutebrowser / qutebrowser / browser / browsertab.py View on Github external
fullscreen: Whether the tab has a video shown fullscreen currently.
        netrc_used: Whether netrc authentication was performed.
        input_mode: current input mode for the tab.
    """

    keep_icon = attr.ib(False)  # type: bool
    viewing_source = attr.ib(False)  # type: bool
    inspector = attr.ib(None)  # type: typing.Optional[AbstractWebInspector]
    open_target = attr.ib(
        usertypes.ClickTarget.normal)  # type: usertypes.ClickTarget
    override_target = attr.ib(
        None)  # type: typing.Optional[usertypes.ClickTarget]
    pinned = attr.ib(False)  # type: bool
    fullscreen = attr.ib(False)  # type: bool
    netrc_used = attr.ib(False)  # type: bool
    input_mode = attr.ib(usertypes.KeyMode.normal)  # type: usertypes.KeyMode
    last_navigation = attr.ib(None)  # type: usertypes.NavigationRequest

    def should_show_icon(self) -> bool:
        return (config.val.tabs.favicons.show == 'always' or
                config.val.tabs.favicons.show == 'pinned' and self.pinned)


class AbstractAction:

    """Attribute ``action`` of AbstractTab for Qt WebActions."""

    # The class actions are defined on (QWeb{Engine,}Page)
    action_class = None  # type: type
    # The type of the actions (QWeb{Engine,}Page.WebAction)
    action_base = None  # type: type
github qutebrowser / qutebrowser / qutebrowser / misc / backendproblem.py View on Github external
def _handle_nouveau_graphics():
    """Force software rendering when using the Nouveau driver.

    WORKAROUND for https://bugreports.qt.io/browse/QTBUG-41242
    Should be fixed in Qt 5.10 via https://codereview.qt-project.org/#/c/208664/
    """
    assert objects.backend == usertypes.Backend.QtWebEngine, objects.backend

    if os.environ.get('QUTE_SKIP_NOUVEAU_CHECK'):
        return

    if version.opengl_vendor() != 'nouveau':
        return

    if (os.environ.get('LIBGL_ALWAYS_SOFTWARE') == '1' or
            # qt.force_software_rendering = 'software-opengl'
            'QT_XCB_FORCE_SOFTWARE_OPENGL' in os.environ or
            # qt.force_software_rendering = 'chromium', also see:
            # https://build.opensuse.org/package/view_file/openSUSE:Factory/libqt5-qtwebengine/disable-gpu-when-using-nouveau-boo-1005323.diff?expand=1
            'QT_WEBENGINE_DISABLE_NOUVEAU_WORKAROUND' in os.environ):
        return

    button = _Button("Force software rendering", 'qt.force_software_rendering',
github qutebrowser / qutebrowser / qutebrowser / misc / throttle.py View on Github external
delay_ms: int,
                 parent: QObject = None) -> None:
        """Constructor.

        Args:
            delay_ms: The time to wait before allowing another call of the
                         function. -1 disables the wrapper.
            func: The function/method to call on __call__.
            parent: The parent object.
        """
        super().__init__(parent)
        self._delay_ms = delay_ms
        self._func = func
        self._pending_call = None  # type: typing.Optional[_CallArgs]
        self._last_call_ms = None  # type: typing.Optional[int]
        self._timer = usertypes.Timer(self, 'throttle-timer')
        self._timer.setSingleShot(True)
github qutebrowser / qutebrowser / qutebrowser / browser / browsertab.py View on Github external
def _is_case_sensitive(self, ignore_case: usertypes.IgnoreCase) -> bool:
        """Check if case-sensitivity should be used.

        This assumes self.text is already set properly.

        Arguments:
            ignore_case: The ignore_case value from the config.
        """
        assert self.text is not None
        mapping = {
            usertypes.IgnoreCase.smart: not self.text.islower(),
            usertypes.IgnoreCase.never: True,
            usertypes.IgnoreCase.always: False,
        }
        return mapping[ignore_case]
github qutebrowser / qutebrowser / qutebrowser / keyinput / modeparsers.py View on Github external
def __init__(self, win_id, parent=None):
        super().__init__(win_id, parent, supports_count=True)
        self._read_config('normal')
        self._partial_timer = usertypes.Timer(self, 'partial-match')
        self._partial_timer.setSingleShot(True)
        self._partial_timer.timeout.connect(self._clear_partial_match)
        self._inhibited = False
        self._inhibited_timer = usertypes.Timer(self, 'normal-inhibited')
        self._inhibited_timer.setSingleShot(True)
github qutebrowser / qutebrowser / qutebrowser / config / configinit.py View on Github external
def get_backend(args: argparse.Namespace) -> usertypes.Backend:
    """Find out what backend to use based on available libraries."""
    str_to_backend = {
        'webkit': usertypes.Backend.QtWebKit,
        'webengine': usertypes.Backend.QtWebEngine,
    }

    if args.backend is not None:
        return str_to_backend[args.backend]
    else:
        return str_to_backend[config.val.backend]
github qutebrowser / qutebrowser / qutebrowser / browser / browsertab.py View on Github external
Only used when sources are shown via pygments.
        open_target: Where to open the next link.
                     Only used for QtWebKit.
        override_target: Override for open_target for fake clicks (like hints).
                         Only used for QtWebKit.
        pinned: Flag to pin the tab.
        fullscreen: Whether the tab has a video shown fullscreen currently.
        netrc_used: Whether netrc authentication was performed.
        input_mode: current input mode for the tab.
    """

    keep_icon = attr.ib(False)  # type: bool
    viewing_source = attr.ib(False)  # type: bool
    inspector = attr.ib(None)  # type: typing.Optional[AbstractWebInspector]
    open_target = attr.ib(
        usertypes.ClickTarget.normal)  # type: usertypes.ClickTarget
    override_target = attr.ib(
        None)  # type: typing.Optional[usertypes.ClickTarget]
    pinned = attr.ib(False)  # type: bool
    fullscreen = attr.ib(False)  # type: bool
    netrc_used = attr.ib(False)  # type: bool
    input_mode = attr.ib(usertypes.KeyMode.normal)  # type: usertypes.KeyMode
    last_navigation = attr.ib(None)  # type: usertypes.NavigationRequest

    def should_show_icon(self) -> bool:
        return (config.val.tabs.favicons.show == 'always' or
                config.val.tabs.favicons.show == 'pinned' and self.pinned)


class AbstractAction:

    """Attribute ``action`` of AbstractTab for Qt WebActions."""