How to use the qutebrowser.utils.objreg.get 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 / qutebrowser / misc / backendproblem.py View on Github external
def _show_dialog(*args, **kwargs):
    """Show a dialog for a backend problem."""
    cmd_args = objreg.get('args')
    if cmd_args.no_err_windows:
        text = _error_text(*args, **kwargs)
        print(text, file=sys.stderr)
        sys.exit(usertypes.Exit.err_init)

    dialog = _Dialog(*args, **kwargs)

    status = dialog.exec_()
    quitter = objreg.get('quitter')

    if status in [_Result.quit, QDialog.Rejected]:
        pass
    elif status == _Result.restart_webkit:
        quitter.restart(override_args={'backend': 'webkit'})
    elif status == _Result.restart_webengine:
        quitter.restart(override_args={'backend': 'webengine'})
github qutebrowser / qutebrowser / qutebrowser / keyinput / modeparsers.py View on Github external
def _handle_filter_key(self, e):
        """Handle keys for string filtering.

        Return True if the keypress has been handled, and False if not.

        Args:
            e: the KeyPressEvent from Qt.

        Return:
            A QKeySequence match.
        """
        log.keyboard.debug("Got filter key 0x{:x} text {}".format(
            e.key(), e.text()))
        hintmanager = objreg.get('hintmanager', scope='tab',
                                 window=self._win_id, tab='current')
        if e.key() == Qt.Key_Backspace:
            log.keyboard.debug("Got backspace, mode {}, filtertext '{}', "
                               "sequence '{}'".format(self._last_press,
                                                      self._filtertext,
                                                      self._sequence))
            if self._last_press == LastPress.filtertext and self._filtertext:
                self._filtertext = self._filtertext[:-1]
                hintmanager.filter_hints(self._filtertext)
                return QKeySequence.ExactMatch
            elif self._last_press == LastPress.keystring and self._sequence:
                self._sequence = self._sequence[:-1]
                self.keystring_updated.emit(str(self._sequence))
                if not self._sequence and self._filtertext:
                    # Switch back to hint filtering mode (this can happen only
                    # in numeric mode after the number has been deleted).
github qutebrowser / qutebrowser / qutebrowser / browser / signalfilter.py View on Github external
def _filter_signals(self, signal, tab, *args):
        """Filter signals and trigger TabbedBrowser signals if needed.

        Triggers signal if the original signal was sent from the _current_ tab
        and not from any other one.

        The original signal does not matter, since we get the new signal and
        all args.

        Args:
            signal: The signal to emit if the sender was the current widget.
            tab: The WebView which the filter belongs to.
            *args: The args to pass to the signal.
        """
        log_signal = debug.signal_name(signal) not in self.BLACKLIST
        tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                    window=self._win_id)
        try:
            tabidx = tabbed_browser.widget.indexOf(tab)
        except RuntimeError:
            # The tab has been deleted already
            return
        if tabidx == tabbed_browser.widget.currentIndex():
            if log_signal:
                log.signals.debug("emitting: {} (tab {})".format(
                    debug.dbg_signal(signal, args), tabidx))
            signal.emit(*args)
        else:
            if log_signal:
                log.signals.debug("ignoring: {} (tab {})".format(
                    debug.dbg_signal(signal, args), tabidx))
github qutebrowser / qutebrowser / qutebrowser / browser / mhtml.py View on Github external
def start_download(dest):
    """Start downloading the current page and all assets to a MHTML file.

    This will overwrite dest if it already exists.

    Args:
        dest: The filename where the resulting file should be saved.
    """
    dest = os.path.expanduser(dest)
    web_view = objreg.get('webview', scope='tab', tab='current')
    loader = _Downloader(web_view, dest)
    loader.run()
github qutebrowser / qutebrowser / qutebrowser / misc / crashsignal.py View on Github external
def _get_exception_info(self):
        """Get info needed for the exception hook/dialog.

        Return:
            An ExceptionInfo object.
        """
        try:
            pages = self._recover_pages(forgiving=True)
        except Exception as e:
            log.destroy.exception("Error while recovering pages: {}".format(e))
            pages = []

        try:
            cmd_history = objreg.get('command-history')[-5:]
        except Exception as e:
            log.destroy.exception("Error while getting history: {}".format(e))
            cmd_history = []

        try:
            objects = debug.get_all_objects()
        except Exception:
            log.destroy.exception("Error while getting objects")
            objects = ""
        return ExceptionInfo(pages, cmd_history, objects)
github qutebrowser / qutebrowser / qutebrowser / browser / webelem.py View on Github external
def _click_href(self, click_target):
        """Fake a click on an element with a href by opening the link."""
        baseurl = self._tab.url()
        url = self.resolve_url(baseurl)
        if url is None:
            self._click_fake_event(click_target)
            return

        tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                    window=self._tab.win_id)

        if click_target in [usertypes.ClickTarget.tab,
                            usertypes.ClickTarget.tab_bg]:
            background = click_target == usertypes.ClickTarget.tab_bg
            tabbed_browser.tabopen(url, background=background)
        elif click_target == usertypes.ClickTarget.window:
            window = mainwindow.MainWindow(private=tabbed_browser.private)
            window.show()
            window.tabbed_browser.tabopen(url)
        else:
            raise ValueError("Unknown ClickTarget {}".format(click_target))
github qutebrowser / qutebrowser / qutebrowser / commands / userscripts.py View on Github external
runner = _POSIXUserscriptRunner(tabbed_browser)
    elif utils.is_windows:  # pragma: no cover
        runner = _WindowsUserscriptRunner(tabbed_browser)
    else:  # pragma: no cover
        raise UnsupportedError

    runner.got_cmd.connect(
        lambda cmd:
        log.commands.debug("Got userscript command: {}".format(cmd)))
    runner.got_cmd.connect(commandrunner.run_safely)

    env['QUTE_USER_AGENT'] = websettings.user_agent()
    env['QUTE_CONFIG_DIR'] = standarddir.config()
    env['QUTE_DATA_DIR'] = standarddir.data()
    env['QUTE_DOWNLOAD_DIR'] = downloads.download_dir()
    env['QUTE_COMMANDLINE_TEXT'] = objreg.get('status-command', scope='window',
                                              window=win_id).text()

    cmd_path = os.path.expanduser(cmd)

    # if cmd is not given as an absolute path, look it up
    # ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_HOME)
    if not os.path.isabs(cmd_path):
        log.misc.debug("{} is no absolute path".format(cmd_path))
        cmd_path = _lookup_path(cmd)
    elif not os.path.exists(cmd_path):
        raise NotFoundError(cmd_path)
    log.misc.debug("Userscript to run: {}".format(cmd_path))

    runner.finished.connect(commandrunner.deleteLater)
    runner.finished.connect(runner.deleteLater)
github qutebrowser / qutebrowser / qutebrowser / misc / backendproblem.py View on Github external
def _change_setting(self, setting, value):
        """Change the given setting and restart."""
        config.instance.set_obj(setting, value, save_yaml=True)
        save_manager = objreg.get('save-manager')
        save_manager.save_all(is_exit=True)

        if setting == 'backend' and value == 'webkit':
            self.done(_Result.restart_webkit)
        elif setting == 'backend' and value == 'webengine':
            self.done(_Result.restart_webengine)
        else:
            self.done(_Result.restart)
github qutebrowser / qutebrowser / qutebrowser / browser / shared.py View on Github external
def get_tab(win_id, target):
    """Get a tab widget for the given usertypes.ClickTarget.

    Args:
        win_id: The window ID to open new tabs in
        target: A usertypes.ClickTarget
    """
    if target == usertypes.ClickTarget.tab:
        win_id = win_id
        bg_tab = False
    elif target == usertypes.ClickTarget.tab_bg:
        win_id = win_id
        bg_tab = True
    elif target == usertypes.ClickTarget.window:
        tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                    window=win_id)
        window = mainwindow.MainWindow(private=tabbed_browser.is_private)
        window.show()
        win_id = window.win_id
        bg_tab = False
    else:
        raise ValueError("Invalid ClickTarget {}".format(target))

    tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                window=win_id)
    return tabbed_browser.tabopen(url=None, background=bg_tab)