Ejemplo n.º 1
0
 def __init__(self, win_id, parent=None):
     super().__init__(parent)
     if sys.platform == 'darwin' and qtutils.version_check('5.4'):
         # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-42948
         # See https://github.com/The-Compiler/qutebrowser/issues/462
         self.setStyle(QStyleFactory.create('Fusion'))
     self._win_id = win_id
     self.load_status = LoadStatus.none
     self._check_insertmode = False
     self.inspector = None
     self.scroll_pos = (-1, -1)
     self.statusbar_message = ''
     self._old_scroll_pos = (-1, -1)
     self.open_target = usertypes.ClickTarget.normal
     self._force_open_target = None
     self._zoom = None
     self._has_ssl_errors = False
     self.keep_icon = False
     self.init_neighborlist()
     cfg = objreg.get('config')
     cfg.changed.connect(self.init_neighborlist)
     # For some reason, this signal doesn't get disconnected automatically
     # when the WebView is destroyed on older PyQt versions.
     # See https://github.com/The-Compiler/qutebrowser/issues/390
     self.destroyed.connect(
         functools.partial(cfg.changed.disconnect, self.init_neighborlist))
     self._cur_url = None
     self.cur_url = QUrl()
     self.progress = 0
     self.registry = objreg.ObjectRegistry()
     self.tab_id = next(tab_id_gen)
     tab_registry = objreg.get('tab-registry',
                               scope='window',
                               window=win_id)
     tab_registry[self.tab_id] = self
     objreg.register('webview', self, registry=self.registry)
     page = webpage.BrowserPage(win_id, self.tab_id, self)
     self.setPage(page)
     hintmanager = hints.HintManager(win_id, self.tab_id, self)
     hintmanager.mouse_event.connect(self.on_mouse_event)
     hintmanager.set_open_target.connect(self.set_force_open_target)
     objreg.register('hintmanager', hintmanager, registry=self.registry)
     mode_manager = objreg.get('mode-manager',
                               scope='window',
                               window=win_id)
     mode_manager.entered.connect(self.on_mode_entered)
     mode_manager.left.connect(self.on_mode_left)
     page.linkHovered.connect(self.linkHovered)
     page.mainFrame().loadStarted.connect(self.on_load_started)
     self.urlChanged.connect(self.on_url_changed)
     page.mainFrame().loadFinished.connect(self.on_load_finished)
     self.loadProgress.connect(lambda p: setattr(self, 'progress', p))
     self.page().statusBarMessage.connect(
         lambda msg: setattr(self, 'statusbar_message', msg))
     self.page().networkAccessManager().sslErrors.connect(
         lambda *args: setattr(self, '_has_ssl_errors', True))
     self.viewing_source = False
     self.setZoomFactor(float(config.get('ui', 'default-zoom')) / 100)
     self._default_zoom_changed = False
     objreg.get('config').changed.connect(self.on_config_changed)
Ejemplo n.º 2
0
    def __init__(self, *, win_id: int, private: bool,
                 parent: QWidget = None) -> None:
        self.is_private = private
        self.win_id = win_id
        self.tab_id = next(tab_id_gen)
        super().__init__(parent)

        self.registry = objreg.ObjectRegistry()
        tab_registry = objreg.get('tab-registry', scope='window',
                                  window=win_id)
        tab_registry[self.tab_id] = self
        objreg.register('tab', self, registry=self.registry)

        self.data = TabData()
        self._layout = miscwidgets.WrapperLayout(self)
        self._widget = None  # type: typing.Optional[QWidget]
        self._progress = 0
        self._has_ssl_errors = False
        self._load_status = usertypes.LoadStatus.none
        self._mouse_event_filter = mouse.MouseEventFilter(
            self, parent=self)
        self.backend = None

        # FIXME:qtwebengine  Should this be public api via self.hints?
        #                    Also, should we get it out of objreg?
        hintmanager = hints.HintManager(win_id, self.tab_id, parent=self)
        objreg.register('hintmanager', hintmanager, scope='tab',
                        window=self.win_id, tab=self.tab_id)

        self.before_load_started.connect(self._on_before_load_started)
Ejemplo n.º 3
0
    def __init__(self, *, win_id, mode_manager, private, parent=None):
        self.private = private
        self.win_id = win_id
        self.tab_id = next(tab_id_gen)
        super().__init__(parent)

        self.registry = objreg.ObjectRegistry()
        tab_registry = objreg.get('tab-registry',
                                  scope='window',
                                  window=win_id)
        tab_registry[self.tab_id] = self
        objreg.register('tab', self, registry=self.registry)

        self.data = TabData()
        self._layout = miscwidgets.WrapperLayout(self)
        self._widget = None
        self._progress = 0
        self._has_ssl_errors = False
        self._mode_manager = mode_manager
        self._load_status = usertypes.LoadStatus.none
        self._mouse_event_filter = mouse.MouseEventFilter(self, parent=self)
        self.backend = None

        # FIXME:qtwebengine  Should this be public api via self.hints?
        #                    Also, should we get it out of objreg?
        hintmanager = hints.HintManager(win_id, self.tab_id, parent=self)
        objreg.register('hintmanager',
                        hintmanager,
                        scope='tab',
                        window=self.win_id,
                        tab=self.tab_id)

        self.predicted_navigation.connect(
            lambda url: self.title_changed.emit(url.toDisplayString()))
Ejemplo n.º 4
0
    def __init__(self, win_id, parent=None):
        self.win_id = win_id
        self.tab_id = next(tab_id_gen)
        super().__init__(parent)

        self.registry = objreg.ObjectRegistry()
        tab_registry = objreg.get('tab-registry', scope='window',
                                  window=win_id)
        tab_registry[self.tab_id] = self
        objreg.register('tab', self, registry=self.registry)

        # self.history = AbstractHistory(self)
        # self.scroller = AbstractScroller(self, parent=self)
        # self.caret = AbstractCaret(win_id=win_id, tab=self, mode_manager=...,
        #                            parent=self)
        # self.zoom = AbstractZoom(win_id=win_id)
        # self.search = AbstractSearch(parent=self)
        # self.printing = AbstractPrinting()
        # self.elements = AbstractElements(self)

        self.data = TabData()
        self._layout = miscwidgets.WrapperLayout(self)
        self._widget = None
        self._progress = 0
        self._has_ssl_errors = False
        self._load_status = usertypes.LoadStatus.none
        self._mouse_event_filter = mouse.MouseEventFilter(
            self, widget_class=self.WIDGET_CLASS, parent=self)
        self.backend = None

        # FIXME:qtwebengine  Should this be public api via self.hints?
        #                    Also, should we get it out of objreg?
        hintmanager = hints.HintManager(win_id, self.tab_id, parent=self)
        objreg.register('hintmanager', hintmanager, scope='tab',
                        window=self.win_id, tab=self.tab_id)
Ejemplo n.º 5
0
 def __init__(self, win_id, parent=None):
     super().__init__(parent)
     if sys.platform == 'darwin' and qtutils.version_check('5.4'):
         # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-42948
         # See https://github.com/The-Compiler/qutebrowser/issues/462
         self.setStyle(QStyleFactory.create('Fusion'))
     self.win_id = win_id
     self.load_status = LoadStatus.none
     self._check_insertmode = False
     self.inspector = None
     self.scroll_pos = (-1, -1)
     self.statusbar_message = ''
     self._old_scroll_pos = (-1, -1)
     self._zoom = None
     self._has_ssl_errors = False
     self._ignore_wheel_event = False
     self.keep_icon = False
     self.search_text = None
     self.search_flags = 0
     self.selection_enabled = False
     self.init_neighborlist()
     self._set_bg_color()
     cfg = objreg.get('config')
     cfg.changed.connect(self.init_neighborlist)
     # For some reason, this signal doesn't get disconnected automatically
     # when the WebView is destroyed on older PyQt versions.
     # See https://github.com/The-Compiler/qutebrowser/issues/390
     self.destroyed.connect(
         functools.partial(cfg.changed.disconnect, self.init_neighborlist))
     self.cur_url = QUrl()
     self._orig_url = QUrl()
     self.progress = 0
     self.registry = objreg.ObjectRegistry()
     self.tab_id = next(tab_id_gen)
     tab_registry = objreg.get('tab-registry',
                               scope='window',
                               window=win_id)
     tab_registry[self.tab_id] = self
     objreg.register('webview', self, registry=self.registry)
     page = self._init_page()
     hintmanager = hints.HintManager(win_id, self.tab_id, self)
     hintmanager.mouse_event.connect(self.on_mouse_event)
     hintmanager.start_hinting.connect(page.on_start_hinting)
     hintmanager.stop_hinting.connect(page.on_stop_hinting)
     objreg.register('hintmanager', hintmanager, registry=self.registry)
     mode_manager = objreg.get('mode-manager',
                               scope='window',
                               window=win_id)
     mode_manager.entered.connect(self.on_mode_entered)
     mode_manager.left.connect(self.on_mode_left)
     self.viewing_source = False
     self.setZoomFactor(float(config.get('ui', 'default-zoom')) / 100)
     self._default_zoom_changed = False
     if config.get('input', 'rocker-gestures'):
         self.setContextMenuPolicy(Qt.PreventContextMenu)
     self.urlChanged.connect(self.on_url_changed)
     self.loadProgress.connect(lambda p: setattr(self, 'progress', p))
     objreg.get('config').changed.connect(self.on_config_changed)
Ejemplo n.º 6
0
    def __init__(self, *, win_id, mode_manager, private, parent=None):
        self.private = private
        self.win_id = win_id
        self.tab_id = next(tab_id_gen)
        super().__init__(parent)

        self.registry = objreg.ObjectRegistry()
        tab_registry = objreg.get('tab-registry',
                                  scope='window',
                                  window=win_id)
        tab_registry[self.tab_id] = self
        objreg.register('tab', self, registry=self.registry)

        # self.history = AbstractHistory(self)
        # self.scroller = AbstractScroller(self, parent=self)
        # self.caret = AbstractCaret(win_id=win_id, tab=self,
        #                            mode_manager=mode_manager, parent=self)
        # self.zoom = AbstractZoom(win_id=win_id)
        # self.search = AbstractSearch(parent=self)
        # self.printing = AbstractPrinting()
        # self.elements = AbstractElements(self)
        # self.action = AbstractAction()

        # we assume the parent always exists if using tree tabs
        if parent:
            self.node = Node(self, parent=parent.tree_root)
        else:
            self.node = Node(self, parent=None)

        self.data = TabData()
        self._layout = miscwidgets.WrapperLayout(self)
        self._widget = None
        self._progress = 0
        self._has_ssl_errors = False
        self._mode_manager = mode_manager
        self._load_status = usertypes.LoadStatus.none
        self._mouse_event_filter = mouse.MouseEventFilter(self, parent=self)
        self.backend = None

        # FIXME:qtwebengine  Should this be public api via self.hints?
        #                    Also, should we get it out of objreg?
        hintmanager = hints.HintManager(win_id, self.tab_id, parent=self)
        objreg.register('hintmanager',
                        hintmanager,
                        scope='tab',
                        window=self.win_id,
                        tab=self.tab_id)

        self.predicted_navigation.connect(
            lambda url: self.title_changed.emit(url.toDisplayString()))
Ejemplo n.º 7
0
 def __init__(self, win_id, parent=None):
     super().__init__(parent)
     self._win_id = win_id
     self.load_status = LoadStatus.none
     self._check_insertmode = False
     self.inspector = None
     self.scroll_pos = (-1, -1)
     self.statusbar_message = ''
     self._old_scroll_pos = (-1, -1)
     self.open_target = usertypes.ClickTarget.normal
     self._force_open_target = None
     self._zoom = None
     self._has_ssl_errors = False
     self.init_neighborlist()
     objreg.get('config').changed.connect(self.init_neighborlist)
     self._cur_url = None
     self.cur_url = QUrl()
     self.progress = 0
     self.registry = objreg.ObjectRegistry()
     self.tab_id = next(tab_id_gen)
     tab_registry = objreg.get('tab-registry',
                               scope='window',
                               window=win_id)
     tab_registry[self.tab_id] = self
     objreg.register('webview', self, registry=self.registry)
     page = webpage.BrowserPage(win_id, self)
     self.setPage(page)
     hintmanager = hints.HintManager(win_id, self.tab_id, self)
     hintmanager.mouse_event.connect(self.on_mouse_event)
     hintmanager.set_open_target.connect(self.set_force_open_target)
     objreg.register('hintmanager', hintmanager, registry=self.registry)
     page.linkHovered.connect(self.linkHovered)
     page.mainFrame().loadStarted.connect(self.on_load_started)
     self.urlChanged.connect(self.on_url_changed)
     page.mainFrame().loadFinished.connect(self.on_load_finished)
     page.scrollRequested.connect(self.on_scroll_requested)
     # Calculate scroll position once
     self.on_scroll_requested()
     self.loadProgress.connect(lambda p: setattr(self, 'progress', p))
     self.page().statusBarMessage.connect(
         lambda msg: setattr(self, 'statusbar_message', msg))
     self.page().networkAccessManager().sslErrors.connect(
         lambda *args: setattr(self, '_has_ssl_errors', True))
     self.viewing_source = False
     self.setZoomFactor(float(config.get('ui', 'default-zoom')) / 100)
Ejemplo n.º 8
0
def init(win_id: int, parent: QObject) -> 'ModeManager':
    """Initialize the mode manager and the keyparsers for the given win_id."""
    modeman = ModeManager(win_id, parent)
    objreg.register('mode-manager', modeman, scope='window', window=win_id)

    commandrunner = runners.CommandRunner(win_id)

    hintmanager = hints.HintManager(win_id, parent=parent)
    objreg.register('hintmanager',
                    hintmanager,
                    scope='window',
                    window=win_id,
                    command_only=True)

    keyparsers = {
        usertypes.KeyMode.normal:
        modeparsers.NormalKeyParser(win_id=win_id,
                                    commandrunner=commandrunner,
                                    parent=modeman),
        usertypes.KeyMode.hint:
        modeparsers.HintKeyParser(win_id=win_id,
                                  commandrunner=commandrunner,
                                  hintmanager=hintmanager,
                                  parent=modeman),
        usertypes.KeyMode.insert:
        modeparsers.PassthroughKeyParser(win_id=win_id,
                                         mode=usertypes.KeyMode.insert,
                                         commandrunner=commandrunner,
                                         parent=modeman),
        usertypes.KeyMode.passthrough:
        modeparsers.PassthroughKeyParser(win_id=win_id,
                                         mode=usertypes.KeyMode.passthrough,
                                         commandrunner=commandrunner,
                                         parent=modeman),
        usertypes.KeyMode.command:
        modeparsers.PassthroughKeyParser(win_id=win_id,
                                         mode=usertypes.KeyMode.command,
                                         commandrunner=commandrunner,
                                         parent=modeman),
        usertypes.KeyMode.prompt:
        modeparsers.PassthroughKeyParser(win_id=win_id,
                                         mode=usertypes.KeyMode.prompt,
                                         commandrunner=commandrunner,
                                         parent=modeman),
        usertypes.KeyMode.yesno:
        modeparsers.PromptKeyParser(win_id=win_id,
                                    commandrunner=commandrunner,
                                    parent=modeman),
        usertypes.KeyMode.caret:
        modeparsers.CaretKeyParser(win_id=win_id,
                                   commandrunner=commandrunner,
                                   parent=modeman),
        usertypes.KeyMode.set_mark:
        modeparsers.RegisterKeyParser(win_id=win_id,
                                      mode=usertypes.KeyMode.set_mark,
                                      commandrunner=commandrunner,
                                      parent=modeman),
        usertypes.KeyMode.jump_mark:
        modeparsers.RegisterKeyParser(win_id=win_id,
                                      mode=usertypes.KeyMode.jump_mark,
                                      commandrunner=commandrunner,
                                      parent=modeman),
        usertypes.KeyMode.record_macro:
        modeparsers.RegisterKeyParser(win_id=win_id,
                                      mode=usertypes.KeyMode.record_macro,
                                      commandrunner=commandrunner,
                                      parent=modeman),
        usertypes.KeyMode.run_macro:
        modeparsers.RegisterKeyParser(win_id=win_id,
                                      mode=usertypes.KeyMode.run_macro,
                                      commandrunner=commandrunner,
                                      parent=modeman),
    }  # type: _ParserDictType

    objreg.register('keyparsers', keyparsers, scope='window', window=win_id)

    modeman.destroyed.connect(  # type: ignore
        functools.partial(objreg.delete,
                          'keyparsers',
                          scope='window',
                          window=win_id))

    for mode, parser in keyparsers.items():
        modeman.register(mode, parser)

    return modeman
Ejemplo n.º 9
0
def init(win_id: int, parent: QObject) -> 'ModeManager':
    """Initialize the mode manager and the keyparsers for the given win_id."""
    modeman = ModeManager(win_id, parent)
    objreg.register('mode-manager', modeman, scope='window', window=win_id)

    commandrunner = runners.CommandRunner(win_id)

    hintmanager = hints.HintManager(win_id, parent=parent)
    objreg.register('hintmanager',
                    hintmanager,
                    scope='window',
                    window=win_id,
                    command_only=True)

    keyparsers = {
        usertypes.KeyMode.normal:
        modeparsers.NormalKeyParser(win_id=win_id,
                                    commandrunner=commandrunner,
                                    parent=modeman),
        usertypes.KeyMode.hint:
        modeparsers.HintKeyParser(win_id=win_id,
                                  commandrunner=commandrunner,
                                  hintmanager=hintmanager,
                                  parent=modeman),
        usertypes.KeyMode.insert:
        modeparsers.CommandKeyParser(mode=usertypes.KeyMode.insert,
                                     win_id=win_id,
                                     commandrunner=commandrunner,
                                     parent=modeman,
                                     passthrough=True,
                                     do_log=False,
                                     supports_count=False),
        usertypes.KeyMode.passthrough:
        modeparsers.CommandKeyParser(mode=usertypes.KeyMode.passthrough,
                                     win_id=win_id,
                                     commandrunner=commandrunner,
                                     parent=modeman,
                                     passthrough=True,
                                     do_log=False,
                                     supports_count=False),
        usertypes.KeyMode.command:
        modeparsers.CommandKeyParser(mode=usertypes.KeyMode.command,
                                     win_id=win_id,
                                     commandrunner=commandrunner,
                                     parent=modeman,
                                     passthrough=True,
                                     do_log=False,
                                     supports_count=False),
        usertypes.KeyMode.prompt:
        modeparsers.CommandKeyParser(mode=usertypes.KeyMode.prompt,
                                     win_id=win_id,
                                     commandrunner=commandrunner,
                                     parent=modeman,
                                     passthrough=True,
                                     do_log=False,
                                     supports_count=False),
        usertypes.KeyMode.yesno:
        modeparsers.CommandKeyParser(mode=usertypes.KeyMode.yesno,
                                     win_id=win_id,
                                     commandrunner=commandrunner,
                                     parent=modeman,
                                     supports_count=False),
        usertypes.KeyMode.caret:
        modeparsers.CommandKeyParser(mode=usertypes.KeyMode.caret,
                                     win_id=win_id,
                                     commandrunner=commandrunner,
                                     parent=modeman,
                                     passthrough=True),
        usertypes.KeyMode.set_mark:
        modeparsers.RegisterKeyParser(mode=usertypes.KeyMode.set_mark,
                                      win_id=win_id,
                                      commandrunner=commandrunner,
                                      parent=modeman),
        usertypes.KeyMode.jump_mark:
        modeparsers.RegisterKeyParser(mode=usertypes.KeyMode.jump_mark,
                                      win_id=win_id,
                                      commandrunner=commandrunner,
                                      parent=modeman),
        usertypes.KeyMode.record_macro:
        modeparsers.RegisterKeyParser(mode=usertypes.KeyMode.record_macro,
                                      win_id=win_id,
                                      commandrunner=commandrunner,
                                      parent=modeman),
        usertypes.KeyMode.run_macro:
        modeparsers.RegisterKeyParser(mode=usertypes.KeyMode.run_macro,
                                      win_id=win_id,
                                      commandrunner=commandrunner,
                                      parent=modeman),
    }  # type: ParserDictType

    for mode, parser in keyparsers.items():
        modeman.register(mode, parser)

    return modeman