From d2ece6b5421d75cccf24a13bd0daa866a57fcc15 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 10 Jul 2016 16:17:19 +0200 Subject: [PATCH] Move Backend enum to usertypes Otherwise we have a cyclic import --- qutebrowser/browser/commands.py | 16 ++++++++-------- qutebrowser/browser/hints.py | 3 +-- qutebrowser/browser/tab.py | 3 --- qutebrowser/browser/webengine/webenginetab.py | 2 +- qutebrowser/browser/webkit/webkittab.py | 2 +- qutebrowser/commands/command.py | 5 ++--- qutebrowser/utils/usertypes.py | 4 ++++ tests/unit/commands/test_cmdutils.py | 11 +++++------ 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 13a36f8f5..00fcb0b3b 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -453,7 +453,7 @@ class CommandDispatcher: self._open(url, tab, background, window) @cmdutils.register(instance='command-dispatcher', scope='window', - backend=tabmod.Backend.QtWebKit) + backend=usertypes.Backend.QtWebKit) @cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment', 'decrement']) def navigate(self, where: str, tab=False, bg=False, window=False): @@ -486,7 +486,7 @@ class CommandDispatcher: if where in ['prev', 'next']: # FIXME:qtwebengine have a proper API for this - if widget.backend == tabmod.Backend.QtWebEngine: + if widget.backend == usertypes.Backend.QtWebEngine: raise cmdexc.CommandError(":navigate prev/next is not " "supported yet with QtWebEngine") page = widget._widget.page() # pylint: disable=protected-access @@ -1126,7 +1126,7 @@ class CommandDispatcher: raise cmdexc.CommandError(str(e)) @cmdutils.register(instance='command-dispatcher', name='inspector', - scope='window', backend=tabmod.Backend.QtWebKit) + scope='window', backend=usertypes.Backend.QtWebKit) def toggle_inspector(self): """Toggle the web inspector. @@ -1155,7 +1155,7 @@ class CommandDispatcher: tab.data.inspector.show() @cmdutils.register(instance='command-dispatcher', scope='window', - backend=tabmod.Backend.QtWebKit) + backend=usertypes.Backend.QtWebKit) @cmdutils.argument('dest_old', hide=True) def download(self, url=None, dest_old=None, *, mhtml_=False, dest=None): """Download a given URL, or current page if no URL given. @@ -1329,7 +1329,7 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', modes=[KeyMode.insert], hide=True, scope='window', - backend=tabmod.Backend.QtWebKit) + backend=usertypes.Backend.QtWebKit) def open_editor(self): """Open an external editor with the currently selected form field. @@ -1378,7 +1378,7 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', modes=[KeyMode.insert], hide=True, scope='window', - needs_js=True, backend=tabmod.Backend.QtWebKit) + needs_js=True, backend=usertypes.Backend.QtWebKit) def paste_primary(self): """Paste the primary selection at cursor position.""" # FIXME:qtwebengine have a proper API for this @@ -1671,11 +1671,11 @@ class CommandDispatcher: """ tab = self._current_widget() - if tab.backend == tabmod.Backend.QtWebKit: + if tab.backend == usertypes.Backend.QtWebKit: assert QWebPage is not None member = getattr(QWebPage, action, None) base = QWebPage.WebAction - elif tab.backend == tabmod.Backend.QtWebEngine: + elif tab.backend == usertypes.Backend.QtWebEngine: assert QWebEnginePage is not None member = getattr(QWebEnginePage, action, None) base = QWebEnginePage.WebAction diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 9370939be..a04e0e1ee 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -31,7 +31,6 @@ from PyQt5.QtGui import QMouseEvent from PyQt5.QtWebKit import QWebElement from PyQt5.QtWebKitWidgets import QWebPage -from qutebrowser.browser import tab as tabmod from qutebrowser.config import config from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.browser.webkit import webelem @@ -764,7 +763,7 @@ class HintManager(QObject): @cmdutils.register(instance='hintmanager', scope='tab', name='hint', star_args_optional=True, maxsplit=2, - backend=tabmod.Backend.QtWebKit) + backend=usertypes.Backend.QtWebKit) @cmdutils.argument('win_id', win_id=True) def start(self, rapid=False, group=webelem.Group.all, target=Target.normal, *args, win_id): diff --git a/qutebrowser/browser/tab.py b/qutebrowser/browser/tab.py index 4af6a2efe..bec30ffe7 100644 --- a/qutebrowser/browser/tab.py +++ b/qutebrowser/browser/tab.py @@ -33,9 +33,6 @@ from qutebrowser.utils import utils, objreg, usertypes, message tab_id_gen = itertools.count(0) -Backend = usertypes.enum('Backend', ['QtWebKit', 'QtWebEngine']) - - def create(win_id, parent=None): """Get a QtWebKit/QtWebEngine tab object. diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 98e47b042..1c5c5c672 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -258,7 +258,7 @@ class WebEngineViewTab(tabmod.AbstractTab): self.search = WebEngineSearch(parent=self) self._set_widget(widget) self._connect_signals() - self.backend = tabmod.Backend.QtWebEngine + self.backend = usertypes.Backend.QtWebEngine def openurl(self, url): self._widget.load(url) diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index f973abb0e..678c6aa6b 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -462,7 +462,7 @@ class WebViewTab(tabmod.AbstractTab): self._set_widget(widget) self._connect_signals() self.zoom.set_default() - self.backend = tabmod.Backend.QtWebKit + self.backend = usertypes.Backend.QtWebKit def openurl(self, url): self._widget.openurl(url) diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index c6db96e1c..35ba2fbfe 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -29,7 +29,6 @@ from qutebrowser.commands import cmdexc, argparser from qutebrowser.utils import (log, utils, message, docutils, objreg, usertypes, typing) from qutebrowser.utils import debug as debug_utils -from qutebrowser.browser import tab as tabmod class ArgInfo: @@ -183,8 +182,8 @@ class Command: "{}: This command needs javascript enabled.".format(self.name)) backend_mapping = { - 'webkit': tabmod.Backend.QtWebKit, - 'webengine': tabmod.Backend.QtWebEngine, + 'webkit': usertypes.Backend.QtWebKit, + 'webengine': usertypes.Backend.QtWebEngine, } used_backend = backend_mapping[objreg.get('args').backend] if self.backend is not None and used_backend != self.backend: diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index 632f45276..872531d4f 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -251,6 +251,10 @@ LoadStatus = enum('LoadStatus', ['none', 'success', 'success_https', 'error', 'warn', 'loading']) +# Backend of a tab +Backend = enum('Backend', ['QtWebKit', 'QtWebEngine']) + + class Question(QObject): """A question asked to the user, e.g. via the status bar. diff --git a/tests/unit/commands/test_cmdutils.py b/tests/unit/commands/test_cmdutils.py index 31735a101..b32a8ed63 100644 --- a/tests/unit/commands/test_cmdutils.py +++ b/tests/unit/commands/test_cmdutils.py @@ -23,7 +23,6 @@ import pytest from qutebrowser.commands import cmdutils, cmdexc, argparser, command from qutebrowser.utils import usertypes, typing, objreg -from qutebrowser.browser import tab as tabmod @pytest.fixture(autouse=True) @@ -373,10 +372,10 @@ class TestRun: fake_args.backend = 'webkit' @pytest.mark.parametrize('backend, used, ok', [ - (tabmod.Backend.QtWebEngine, 'webengine', True), - (tabmod.Backend.QtWebEngine, 'webkit', False), - (tabmod.Backend.QtWebKit, 'webengine', False), - (tabmod.Backend.QtWebKit, 'webkit', True), + (usertypes.Backend.QtWebEngine, 'webengine', True), + (usertypes.Backend.QtWebEngine, 'webkit', False), + (usertypes.Backend.QtWebKit, 'webengine', False), + (usertypes.Backend.QtWebKit, 'webkit', True), (None, 'webengine', True), (None, 'webkit', True), ]) @@ -402,7 +401,7 @@ class TestRun: display an error instead of crashing. """ @cmdutils.register(instance='doesnotexist', - backend=tabmod.Backend.QtWebEngine) + backend=usertypes.Backend.QtWebEngine) def fun(self): """Blah.""" pass