Rename browser.tab module and classes

This commit is contained in:
Florian Bruhin 2016-07-10 17:23:08 +02:00
parent 2649418c0b
commit b791095324
12 changed files with 59 additions and 61 deletions

View File

@ -45,10 +45,10 @@ def create(win_id, parent=None):
mode_manager = modeman.instance(win_id)
if objreg.get('args').backend == 'webengine':
from qutebrowser.browser.webengine import webenginetab
tab_class = webenginetab.WebEngineViewTab
tab_class = webenginetab.WebEngineTab
else:
from qutebrowser.browser.webkit import webkittab
tab_class = webkittab.WebViewTab
tab_class = webkittab.WebKitTab
return tab_class(win_id=win_id, mode_manager=mode_manager, parent=parent)

View File

@ -40,8 +40,7 @@ import pygments.formatters
from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners
from qutebrowser.config import config, configexc
from qutebrowser.browser import urlmarks
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import urlmarks, browsertab
from qutebrowser.browser.webkit import webelem, inspector, downloads, mhtml
from qutebrowser.keyinput import modeman
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
@ -1122,7 +1121,7 @@ class CommandDispatcher:
"""
try:
self._current_widget().caret.follow_selected(tab=tab)
except tabmod.WebTabError as e:
except browsertab.WebTabError as e:
raise cmdexc.CommandError(str(e))
@cmdutils.register(instance='command-dispatcher', name='inspector',

View File

@ -29,12 +29,12 @@ from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEnginePage
# pylint: enable=no-name-in-module,import-error,useless-suppression
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import browsertab
from qutebrowser.browser.webengine import webview
from qutebrowser.utils import usertypes, qtutils, log
class WebEngineSearch(tabmod.AbstractSearch):
class WebEngineSearch(browsertab.AbstractSearch):
"""QtWebEngine implementations related to searching on the page."""
@ -51,7 +51,7 @@ class WebEngineSearch(tabmod.AbstractSearch):
log.stub()
class WebEngineCaret(tabmod.AbstractCaret):
class WebEngineCaret(browsertab.AbstractCaret):
"""QtWebEngine implementations related to moving the cursor/selection."""
@ -126,7 +126,7 @@ class WebEngineCaret(tabmod.AbstractCaret):
log.stub()
class WebEngineScroller(tabmod.AbstractScroller):
class WebEngineScroller(browsertab.AbstractScroller):
"""QtWebEngine implementations related to scrolling."""
@ -203,7 +203,7 @@ class WebEngineScroller(tabmod.AbstractScroller):
log.stub()
class WebEngineHistory(tabmod.AbstractHistory):
class WebEngineHistory(browsertab.AbstractHistory):
"""QtWebEngine implementations related to page history."""
@ -232,7 +232,7 @@ class WebEngineHistory(tabmod.AbstractHistory):
log.stub()
class WebEngineZoom(tabmod.AbstractZoom):
class WebEngineZoom(browsertab.AbstractZoom):
"""QtWebEngine implementations related to zooming."""
@ -243,7 +243,7 @@ class WebEngineZoom(tabmod.AbstractZoom):
return self._widget.zoomFactor()
class WebEngineViewTab(tabmod.AbstractTab):
class WebEngineTab(browsertab.AbstractTab):
"""A QtWebEngine tab in the browser."""

View File

@ -28,12 +28,12 @@ from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.QtWebKit import QWebSettings
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import browsertab
from qutebrowser.browser.webkit import webview, tabhistory
from qutebrowser.utils import qtutils, objreg, usertypes, utils
class WebViewSearch(tabmod.AbstractSearch):
class WebKitSearch(browsertab.AbstractSearch):
"""QtWebKit implementations related to searching on the page."""
@ -75,7 +75,7 @@ class WebViewSearch(tabmod.AbstractSearch):
self._widget.search(self.text, flags)
class WebViewCaret(tabmod.AbstractCaret):
class WebKitCaret(browsertab.AbstractCaret):
"""QtWebKit implementations related to moving the cursor/selection."""
@ -281,13 +281,13 @@ class WebViewCaret(tabmod.AbstractCaret):
selected_element = xml.etree.ElementTree.fromstring(
'<html>{}</html>'.format(selection)).find('a')
except xml.etree.ElementTree.ParseError:
raise tabmod.WebTabError('Could not parse selected element!')
raise browsertab.WebTabError('Could not parse selected element!')
if selected_element is not None:
try:
url = selected_element.attrib['href']
except KeyError:
raise tabmod.WebTabError('Anchor element without href!')
raise browsertab.WebTabError('Anchor element without href!')
url = self._tab.url().resolved(QUrl(url))
if tab:
self._tab.new_tab_requested.emit(url)
@ -295,7 +295,7 @@ class WebViewCaret(tabmod.AbstractCaret):
self._tab.openurl(url)
class WebViewZoom(tabmod.AbstractZoom):
class WebKitZoom(browsertab.AbstractZoom):
"""QtWebKit implementations related to zooming."""
@ -306,7 +306,7 @@ class WebViewZoom(tabmod.AbstractZoom):
return self._widget.zoomFactor()
class WebViewScroller(tabmod.AbstractScroller):
class WebKitScroller(browsertab.AbstractScroller):
"""QtWebKit implementations related to scrolling."""
@ -406,7 +406,7 @@ class WebViewScroller(tabmod.AbstractScroller):
return self.pos_px().y() >= frame.scrollBarMaximum(Qt.Vertical)
class WebViewHistory(tabmod.AbstractHistory):
class WebKitHistory(browsertab.AbstractHistory):
"""QtWebKit implementations related to page history."""
@ -446,19 +446,19 @@ class WebViewHistory(tabmod.AbstractHistory):
self._tab.scroll.to_point, cur_data['scroll-pos']))
class WebViewTab(tabmod.AbstractTab):
class WebKitTab(browsertab.AbstractTab):
"""A QtWebKit tab in the browser."""
def __init__(self, win_id, mode_manager, parent=None):
super().__init__(win_id)
widget = webview.WebView(win_id, self.tab_id, tab=self)
self.history = WebViewHistory(self)
self.scroll = WebViewScroller(parent=self)
self.caret = WebViewCaret(win_id=win_id, mode_manager=mode_manager,
self.history = WebKitHistory(self)
self.scroll = WebKitScroller(parent=self)
self.caret = WebKitCaret(win_id=win_id, mode_manager=mode_manager,
tab=self, parent=self)
self.zoom = WebViewZoom(win_id=win_id, parent=self)
self.search = WebViewSearch(parent=self)
self.zoom = WebKitZoom(win_id=win_id, parent=self)
self.search = WebKitSearch(parent=self)
self._set_widget(widget)
self._connect_signals()
self.zoom.set_default()

View File

@ -22,7 +22,7 @@
from collections import defaultdict
from PyQt5.QtCore import Qt, QTimer, pyqtSlot
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import browsertab
from qutebrowser.config import config, configdata
from qutebrowser.utils import objreg, log, qtutils, utils
from qutebrowser.commands import cmdutils
@ -193,7 +193,7 @@ class TabCompletionModel(base.BaseCompletionModel):
"""Add hooks to new windows."""
window.tabbed_browser.new_tab.connect(self.on_new_tab)
@pyqtSlot(tabmod.AbstractTab)
@pyqtSlot(browsertab.AbstractTab)
def on_new_tab(self, tab):
"""Add hooks to new tabs."""
tab.url_text_changed.connect(self.rebuild)

View File

@ -21,7 +21,7 @@
from PyQt5.QtCore import pyqtSlot
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import browsertab
from qutebrowser.mainwindow.statusbar import textbase
@ -51,7 +51,7 @@ class Percentage(textbase.TextBase):
else:
self.setText('[{:2}%]'.format(y))
@pyqtSlot(tabmod.AbstractTab)
@pyqtSlot(browsertab.AbstractTab)
def on_tab_changed(self, tab):
"""Update scroll position when tab changed."""
self.set_perc(*tab.scroll.pos_perc())

View File

@ -22,7 +22,7 @@
from PyQt5.QtCore import pyqtSlot, QSize
from PyQt5.QtWidgets import QProgressBar, QSizePolicy
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import browsertab
from qutebrowser.config import style
from qutebrowser.utils import utils, usertypes
@ -59,7 +59,7 @@ class Progress(QProgressBar):
self.setValue(0)
self.show()
@pyqtSlot(tabmod.AbstractTab)
@pyqtSlot(browsertab.AbstractTab)
def on_tab_changed(self, tab):
"""Set the correct value when the current tab changed."""
if self is None: # pragma: no branch

View File

@ -21,7 +21,7 @@
from PyQt5.QtCore import pyqtSlot
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import browsertab
from qutebrowser.config import config
from qutebrowser.mainwindow.statusbar import textbase
from qutebrowser.utils import usertypes, log, objreg
@ -99,7 +99,7 @@ class Text(textbase.TextBase):
"""Clear jstext when page loading started."""
self._jstext = ''
@pyqtSlot(tabmod.AbstractTab)
@pyqtSlot(browsertab.AbstractTab)
def on_tab_changed(self, tab):
"""Set the correct jstext when the current tab changed."""
self._jstext = tab.statusbar_message

View File

@ -21,7 +21,7 @@
from PyQt5.QtCore import pyqtSlot, pyqtProperty, Qt, QUrl
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import browsertab
from qutebrowser.mainwindow.statusbar import textbase
from qutebrowser.config import style
from qutebrowser.utils import usertypes
@ -160,7 +160,7 @@ class UrlText(textbase.TextBase):
self._hover_url = None
self._update_url()
@pyqtSlot(tabmod.AbstractTab)
@pyqtSlot(browsertab.AbstractTab)
def on_tab_changed(self, tab):
"""Update URL if the tab changed."""
self._hover_url = None

View File

@ -29,8 +29,7 @@ from PyQt5.QtGui import QIcon
from qutebrowser.config import config
from qutebrowser.keyinput import modeman
from qutebrowser.mainwindow import tabwidget
from qutebrowser.browser import signalfilter
from qutebrowser.browser import tab as tabmod
from qutebrowser.browser import signalfilter, browsertab
from qutebrowser.utils import (log, usertypes, utils, qtutils, objreg,
urlutils, message)
@ -100,8 +99,8 @@ class TabbedBrowser(tabwidget.TabWidget):
cur_load_status_changed = pyqtSignal(str)
close_window = pyqtSignal()
resized = pyqtSignal('QRect')
current_tab_changed = pyqtSignal(tabmod.AbstractTab)
new_tab = pyqtSignal(tabmod.AbstractTab, int)
current_tab_changed = pyqtSignal(browsertab.AbstractTab)
new_tab = pyqtSignal(browsertab.AbstractTab, int)
def __init__(self, win_id, parent=None):
super().__init__(win_id, parent)
@ -338,7 +337,7 @@ class TabbedBrowser(tabwidget.TabWidget):
return
self.close_tab(tab)
@pyqtSlot(tabmod.AbstractTab)
@pyqtSlot(browsertab.AbstractTab)
def on_window_close_requested(self, widget):
"""Close a tab with a widget given."""
try:
@ -380,7 +379,7 @@ class TabbedBrowser(tabwidget.TabWidget):
window=window.win_id)
return tabbed_browser.tabopen(url, background, explicit)
tab = tabmod.create(win_id=self._win_id, parent=self)
tab = browsertab.create(win_id=self._win_id, parent=self)
self._connect_tab_signals(tab)
idx = self._get_new_tab_idx(explicit)
@ -479,7 +478,7 @@ class TabbedBrowser(tabwidget.TabWidget):
modeman.maybe_leave(self._win_id, usertypes.KeyMode.hint,
'load started')
@pyqtSlot(tabmod.AbstractTab, str)
@pyqtSlot(browsertab.AbstractTab, str)
def on_title_changed(self, tab, text):
"""Set the title of a tab.
@ -503,7 +502,7 @@ class TabbedBrowser(tabwidget.TabWidget):
if idx == self.currentIndex():
self.update_window_title()
@pyqtSlot(tabmod.AbstractTab, str)
@pyqtSlot(browsertab.AbstractTab, str)
def on_url_text_changed(self, tab, url):
"""Set the new URL as title if there's no title yet.
@ -519,7 +518,7 @@ class TabbedBrowser(tabwidget.TabWidget):
if not self.page_title(idx):
self.set_page_title(idx, url)
@pyqtSlot(tabmod.AbstractTab, QIcon)
@pyqtSlot(browsertab.AbstractTab, QIcon)
def on_icon_changed(self, tab, icon):
"""Set the icon of a tab.

View File

@ -29,7 +29,7 @@ from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
QNetworkCacheMetaData)
from PyQt5.QtWidgets import QCommonStyle, QLineEdit
from qutebrowser.browser import tab
from qutebrowser.browser import browsertab
from qutebrowser.browser.webkit import history
from qutebrowser.config import configexc
from qutebrowser.utils import usertypes
@ -225,7 +225,7 @@ def fake_qprocess():
return m
class FakeWebTabScroller(tab.AbstractScroller):
class FakeWebTabScroller(browsertab.AbstractScroller):
"""Fake AbstractScroller to use in tests."""
@ -237,7 +237,7 @@ class FakeWebTabScroller(tab.AbstractScroller):
return self._pos_perc
class FakeWebTab(tab.AbstractTab):
class FakeWebTab(browsertab.AbstractTab):
"""Fake AbstractTab to use in tests."""
@ -544,7 +544,7 @@ class TabbedBrowserStub(QObject):
"""Stub for the tabbed-browser object."""
new_tab = pyqtSignal(tab.AbstractTab, int)
new_tab = pyqtSignal(browsertab.AbstractTab, int)
def __init__(self, parent=None):
super().__init__(parent)

View File

@ -21,7 +21,7 @@ import pytest
from PyQt5.QtCore import pyqtSignal, QPoint
from qutebrowser.browser import tab
from qutebrowser.browser import browsertab
from qutebrowser.keyinput import modeman
try:
@ -59,7 +59,7 @@ def test_tab(qtbot, view, config_stub, tab_registry):
w = view()
qtbot.add_widget(w)
tab_w = tab.AbstractTab(win_id=0)
tab_w = browsertab.AbstractTab(win_id=0)
qtbot.add_widget(tab_w)
tab_w.show()
@ -68,13 +68,13 @@ def test_tab(qtbot, view, config_stub, tab_registry):
mode_manager = modeman.ModeManager(0)
tab_w.history = tab.AbstractHistory(tab_w)
tab_w.scroll = tab.AbstractScroller(parent=tab_w)
tab_w.caret = tab.AbstractCaret(win_id=tab_w.win_id,
mode_manager=mode_manager, tab=tab_w,
parent=tab_w)
tab_w.zoom = tab.AbstractZoom(win_id=tab_w.win_id)
tab_w.search = tab.AbstractSearch(parent=tab_w)
tab_w.history = browsertab.AbstractHistory(tab_w)
tab_w.scroll = browsertab.AbstractScroller(parent=tab_w)
tab_w.caret = browsertab.AbstractCaret(win_id=tab_w.win_id,
mode_manager=mode_manager,
tab=tab_w, parent=tab_w)
tab_w.zoom = browsertab.AbstractZoom(win_id=tab_w.win_id)
tab_w.search = browsertab.AbstractSearch(parent=tab_w)
tab_w._set_widget(w)
assert tab_w._widget is w
@ -86,13 +86,13 @@ def test_tab(qtbot, view, config_stub, tab_registry):
class TestTabData:
def test_known_attr(self):
data = tab.TabData()
data = browsertab.TabData()
assert not data.keep_icon
data.keep_icon = True
assert data.keep_icon
def test_unknown_attr(self):
data = tab.TabData()
data = browsertab.TabData()
with pytest.raises(AttributeError):
data.bar = 42 # pylint: disable=assigning-non-slot
with pytest.raises(AttributeError):