Move Backend enum to usertypes

Otherwise we have a cyclic import
This commit is contained in:
Florian Bruhin 2016-07-10 16:17:19 +02:00
parent 34e39bed4e
commit d2ece6b542
8 changed files with 22 additions and 24 deletions

View File

@ -453,7 +453,7 @@ class CommandDispatcher:
self._open(url, tab, background, window) self._open(url, tab, background, window)
@cmdutils.register(instance='command-dispatcher', scope='window', @cmdutils.register(instance='command-dispatcher', scope='window',
backend=tabmod.Backend.QtWebKit) backend=usertypes.Backend.QtWebKit)
@cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment', @cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment',
'decrement']) 'decrement'])
def navigate(self, where: str, tab=False, bg=False, window=False): def navigate(self, where: str, tab=False, bg=False, window=False):
@ -486,7 +486,7 @@ class CommandDispatcher:
if where in ['prev', 'next']: if where in ['prev', 'next']:
# FIXME:qtwebengine have a proper API for this # 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 " raise cmdexc.CommandError(":navigate prev/next is not "
"supported yet with QtWebEngine") "supported yet with QtWebEngine")
page = widget._widget.page() # pylint: disable=protected-access page = widget._widget.page() # pylint: disable=protected-access
@ -1126,7 +1126,7 @@ class CommandDispatcher:
raise cmdexc.CommandError(str(e)) raise cmdexc.CommandError(str(e))
@cmdutils.register(instance='command-dispatcher', name='inspector', @cmdutils.register(instance='command-dispatcher', name='inspector',
scope='window', backend=tabmod.Backend.QtWebKit) scope='window', backend=usertypes.Backend.QtWebKit)
def toggle_inspector(self): def toggle_inspector(self):
"""Toggle the web inspector. """Toggle the web inspector.
@ -1155,7 +1155,7 @@ class CommandDispatcher:
tab.data.inspector.show() tab.data.inspector.show()
@cmdutils.register(instance='command-dispatcher', scope='window', @cmdutils.register(instance='command-dispatcher', scope='window',
backend=tabmod.Backend.QtWebKit) backend=usertypes.Backend.QtWebKit)
@cmdutils.argument('dest_old', hide=True) @cmdutils.argument('dest_old', hide=True)
def download(self, url=None, dest_old=None, *, mhtml_=False, dest=None): def download(self, url=None, dest_old=None, *, mhtml_=False, dest=None):
"""Download a given URL, or current page if no URL given. """Download a given URL, or current page if no URL given.
@ -1329,7 +1329,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', @cmdutils.register(instance='command-dispatcher',
modes=[KeyMode.insert], hide=True, scope='window', modes=[KeyMode.insert], hide=True, scope='window',
backend=tabmod.Backend.QtWebKit) backend=usertypes.Backend.QtWebKit)
def open_editor(self): def open_editor(self):
"""Open an external editor with the currently selected form field. """Open an external editor with the currently selected form field.
@ -1378,7 +1378,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', @cmdutils.register(instance='command-dispatcher',
modes=[KeyMode.insert], hide=True, scope='window', 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): def paste_primary(self):
"""Paste the primary selection at cursor position.""" """Paste the primary selection at cursor position."""
# FIXME:qtwebengine have a proper API for this # FIXME:qtwebengine have a proper API for this
@ -1671,11 +1671,11 @@ class CommandDispatcher:
""" """
tab = self._current_widget() tab = self._current_widget()
if tab.backend == tabmod.Backend.QtWebKit: if tab.backend == usertypes.Backend.QtWebKit:
assert QWebPage is not None assert QWebPage is not None
member = getattr(QWebPage, action, None) member = getattr(QWebPage, action, None)
base = QWebPage.WebAction base = QWebPage.WebAction
elif tab.backend == tabmod.Backend.QtWebEngine: elif tab.backend == usertypes.Backend.QtWebEngine:
assert QWebEnginePage is not None assert QWebEnginePage is not None
member = getattr(QWebEnginePage, action, None) member = getattr(QWebEnginePage, action, None)
base = QWebEnginePage.WebAction base = QWebEnginePage.WebAction

View File

@ -31,7 +31,6 @@ from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWebKit import QWebElement from PyQt5.QtWebKit import QWebElement
from PyQt5.QtWebKitWidgets import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
from qutebrowser.browser import tab as tabmod
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.keyinput import modeman, modeparsers
from qutebrowser.browser.webkit import webelem from qutebrowser.browser.webkit import webelem
@ -764,7 +763,7 @@ class HintManager(QObject):
@cmdutils.register(instance='hintmanager', scope='tab', name='hint', @cmdutils.register(instance='hintmanager', scope='tab', name='hint',
star_args_optional=True, maxsplit=2, star_args_optional=True, maxsplit=2,
backend=tabmod.Backend.QtWebKit) backend=usertypes.Backend.QtWebKit)
@cmdutils.argument('win_id', win_id=True) @cmdutils.argument('win_id', win_id=True)
def start(self, rapid=False, group=webelem.Group.all, target=Target.normal, def start(self, rapid=False, group=webelem.Group.all, target=Target.normal,
*args, win_id): *args, win_id):

View File

@ -33,9 +33,6 @@ from qutebrowser.utils import utils, objreg, usertypes, message
tab_id_gen = itertools.count(0) tab_id_gen = itertools.count(0)
Backend = usertypes.enum('Backend', ['QtWebKit', 'QtWebEngine'])
def create(win_id, parent=None): def create(win_id, parent=None):
"""Get a QtWebKit/QtWebEngine tab object. """Get a QtWebKit/QtWebEngine tab object.

View File

@ -258,7 +258,7 @@ class WebEngineViewTab(tabmod.AbstractTab):
self.search = WebEngineSearch(parent=self) self.search = WebEngineSearch(parent=self)
self._set_widget(widget) self._set_widget(widget)
self._connect_signals() self._connect_signals()
self.backend = tabmod.Backend.QtWebEngine self.backend = usertypes.Backend.QtWebEngine
def openurl(self, url): def openurl(self, url):
self._widget.load(url) self._widget.load(url)

View File

@ -462,7 +462,7 @@ class WebViewTab(tabmod.AbstractTab):
self._set_widget(widget) self._set_widget(widget)
self._connect_signals() self._connect_signals()
self.zoom.set_default() self.zoom.set_default()
self.backend = tabmod.Backend.QtWebKit self.backend = usertypes.Backend.QtWebKit
def openurl(self, url): def openurl(self, url):
self._widget.openurl(url) self._widget.openurl(url)

View File

@ -29,7 +29,6 @@ from qutebrowser.commands import cmdexc, argparser
from qutebrowser.utils import (log, utils, message, docutils, objreg, from qutebrowser.utils import (log, utils, message, docutils, objreg,
usertypes, typing) usertypes, typing)
from qutebrowser.utils import debug as debug_utils from qutebrowser.utils import debug as debug_utils
from qutebrowser.browser import tab as tabmod
class ArgInfo: class ArgInfo:
@ -183,8 +182,8 @@ class Command:
"{}: This command needs javascript enabled.".format(self.name)) "{}: This command needs javascript enabled.".format(self.name))
backend_mapping = { backend_mapping = {
'webkit': tabmod.Backend.QtWebKit, 'webkit': usertypes.Backend.QtWebKit,
'webengine': tabmod.Backend.QtWebEngine, 'webengine': usertypes.Backend.QtWebEngine,
} }
used_backend = backend_mapping[objreg.get('args').backend] used_backend = backend_mapping[objreg.get('args').backend]
if self.backend is not None and used_backend != self.backend: if self.backend is not None and used_backend != self.backend:

View File

@ -251,6 +251,10 @@ LoadStatus = enum('LoadStatus', ['none', 'success', 'success_https', 'error',
'warn', 'loading']) 'warn', 'loading'])
# Backend of a tab
Backend = enum('Backend', ['QtWebKit', 'QtWebEngine'])
class Question(QObject): class Question(QObject):
"""A question asked to the user, e.g. via the status bar. """A question asked to the user, e.g. via the status bar.

View File

@ -23,7 +23,6 @@ import pytest
from qutebrowser.commands import cmdutils, cmdexc, argparser, command from qutebrowser.commands import cmdutils, cmdexc, argparser, command
from qutebrowser.utils import usertypes, typing, objreg from qutebrowser.utils import usertypes, typing, objreg
from qutebrowser.browser import tab as tabmod
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -373,10 +372,10 @@ class TestRun:
fake_args.backend = 'webkit' fake_args.backend = 'webkit'
@pytest.mark.parametrize('backend, used, ok', [ @pytest.mark.parametrize('backend, used, ok', [
(tabmod.Backend.QtWebEngine, 'webengine', True), (usertypes.Backend.QtWebEngine, 'webengine', True),
(tabmod.Backend.QtWebEngine, 'webkit', False), (usertypes.Backend.QtWebEngine, 'webkit', False),
(tabmod.Backend.QtWebKit, 'webengine', False), (usertypes.Backend.QtWebKit, 'webengine', False),
(tabmod.Backend.QtWebKit, 'webkit', True), (usertypes.Backend.QtWebKit, 'webkit', True),
(None, 'webengine', True), (None, 'webengine', True),
(None, 'webkit', True), (None, 'webkit', True),
]) ])
@ -402,7 +401,7 @@ class TestRun:
display an error instead of crashing. display an error instead of crashing.
""" """
@cmdutils.register(instance='doesnotexist', @cmdutils.register(instance='doesnotexist',
backend=tabmod.Backend.QtWebEngine) backend=usertypes.Backend.QtWebEngine)
def fun(self): def fun(self):
"""Blah.""" """Blah."""
pass pass