Fix some lint

This commit is contained in:
Florian Bruhin 2016-07-05 20:11:42 +02:00
parent 4e5a7a891e
commit 17466b4f26
18 changed files with 97 additions and 85 deletions

View File

@ -37,7 +37,7 @@ disable=no-self-use,
[BASIC] [BASIC]
function-rgx=[a-z_][a-z0-9_]{2,50}$ function-rgx=[a-z_][a-z0-9_]{2,50}$
const-rgx=[A-Za-z_][A-Za-z0-9_]{0,30}$ const-rgx=[A-Za-z_][A-Za-z0-9_]{0,30}$
method-rgx=[a-z_][A-Za-z0-9_]{2,50}$ method-rgx=[a-z_][A-Za-z0-9_]{1,50}$
attr-rgx=[a-z_][a-z0-9_]{0,30}$ attr-rgx=[a-z_][a-z0-9_]{0,30}$
argument-rgx=[a-z_][a-z0-9_]{0,30}$ argument-rgx=[a-z_][a-z0-9_]{0,30}$
variable-rgx=[a-z_][a-z0-9_]{0,30}$ variable-rgx=[a-z_][a-z0-9_]{0,30}$

View File

@ -21,12 +21,10 @@
import os import os
import os.path import os.path
import sys
import shlex import shlex
import posixpath import posixpath
import functools import functools
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWidgets import QApplication, QTabBar from PyQt5.QtWidgets import QApplication, QTabBar
from PyQt5.QtCore import Qt, QUrl, QEvent from PyQt5.QtCore import Qt, QUrl, QEvent
from PyQt5.QtGui import QKeyEvent from PyQt5.QtGui import QKeyEvent
@ -487,7 +485,8 @@ class CommandDispatcher:
if where in ['prev', 'next']: if where in ['prev', 'next']:
# FIXME:refactor have a proper API for this # FIXME:refactor have a proper API for this
frame = widget._widget.page().currentFrame() page = widget._widget.page() # pylint: disable=protected-access
frame = page.currentFrame()
if frame is None: if frame is None:
raise cmdexc.CommandError("No frame focused!") raise cmdexc.CommandError("No frame focused!")
else: else:
@ -1034,12 +1033,11 @@ class CommandDispatcher:
env['QUTE_TITLE'] = self._tabbed_browser.page_title(idx) env['QUTE_TITLE'] = self._tabbed_browser.page_title(idx)
tab = self._tabbed_browser.currentWidget() tab = self._tabbed_browser.currentWidget()
if tab is None: if tab is not None and tab.caret.has_selection():
mainframe = None env['QUTE_SELECTED_TEXT'] = tab.caret.selection()
else: env['QUTE_SELECTED_HTML'] = tab.caret.selection(html=True)
if tab.caret.has_selection():
env['QUTE_SELECTED_TEXT'] = tab.caret.selection() # FIXME:refactor: If tab is None, run_async will fail!
env['QUTE_SELECTED_HTML'] = tab.caret.selection(html=True)
try: try:
url = self._tabbed_browser.current_url() url = self._tabbed_browser.current_url()
@ -1112,7 +1110,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
scope='window') scope='window')
def follow_selected(self, tab=False): def follow_selected(self, *, tab=False):
"""Follow the selected text. """Follow the selected text.
Args: Args:
@ -1139,7 +1137,8 @@ class CommandDispatcher:
"webinspector!") "webinspector!")
tab.data.inspector = inspector.WebInspector() tab.data.inspector = inspector.WebInspector()
# FIXME:refactor have a proper API for this # FIXME:refactor have a proper API for this
tab.data.inspector.setPage(tab._widget.page()) page = tab._widget.page() # pylint: disable=protected-access
tab.data.inspector.setPage(page)
tab.data.inspector.show() tab.data.inspector.show()
elif tab.data.inspector.isVisible(): elif tab.data.inspector.isVisible():
tab.data.inspector.hide() tab.data.inspector.hide()
@ -1188,6 +1187,7 @@ class CommandDispatcher:
self._download_mhtml(dest) self._download_mhtml(dest)
else: else:
# FIXME:refactor have a proper API for this # FIXME:refactor have a proper API for this
# pylint: disable=protected-access
page = self._current_widget()._widget.page() page = self._current_widget()._widget.page()
download_manager.get(self._current_url(), page=page, download_manager.get(self._current_url(), page=page,
filename=dest) filename=dest)
@ -1224,6 +1224,7 @@ class CommandDispatcher:
raise cmdexc.CommandError("Already viewing source!") raise cmdexc.CommandError("Already viewing source!")
def show_source_cb(source): def show_source_cb(source):
"""Show source as soon as it's ready."""
lexer = pygments.lexers.HtmlLexer() lexer = pygments.lexers.HtmlLexer()
formatter = pygments.formatters.HtmlFormatter(full=True, formatter = pygments.formatters.HtmlFormatter(full=True,
linenos='table') linenos='table')
@ -1252,13 +1253,13 @@ class CommandDispatcher:
with open(dest, 'w', encoding='utf-8') as f: with open(dest, 'w', encoding='utf-8') as f:
f.write(data) f.write(data)
except OSError as e: except OSError as e:
message.error(self._win_id, 'Could not write page: {}'.format(e)) message.error(self._win_id,
'Could not write page: {}'.format(e))
else: else:
message.info(self._win_id, "Dumped page to {}.".format(dest)) message.info(self._win_id, "Dumped page to {}.".format(dest))
tab.dump_async(callback, plain=plain) tab.dump_async(callback, plain=plain)
@cmdutils.register(instance='command-dispatcher', name='help', @cmdutils.register(instance='command-dispatcher', name='help',
scope='window') scope='window')
@cmdutils.argument('topic', completion=usertypes.Completion.helptopic) @cmdutils.argument('topic', completion=usertypes.Completion.helptopic)
@ -1331,9 +1332,10 @@ class CommandDispatcher:
`general -> editor` config option. `general -> editor` config option.
""" """
# FIXME:refactor have a proper API for this # FIXME:refactor have a proper API for this
frame = self._current_widget()._widget.page().currentFrame() tab = self._current_widget()
page = tab._widget.page() # pylint: disable=protected-access
try: try:
elem = webelem.focus_elem(frame) elem = webelem.focus_elem(page.currentFrame())
except webelem.IsNullError: except webelem.IsNullError:
raise cmdexc.CommandError("No element focused!") raise cmdexc.CommandError("No element focused!")
if not elem.is_editable(strict=True): if not elem.is_editable(strict=True):
@ -1375,9 +1377,10 @@ class CommandDispatcher:
def paste_primary(self): def paste_primary(self):
"""Paste the primary selection at cursor position.""" """Paste the primary selection at cursor position."""
# FIXME:refactor have a proper API for this # FIXME:refactor have a proper API for this
frame = self._current_widget()._widget.page().currentFrame() tab = self._current_widget()
page = tab._widget.page() # pylint: disable=protected-access
try: try:
elem = webelem.focus_elem(frame) elem = webelem.focus_elem(page.currentFrame())
except webelem.IsNullError: except webelem.IsNullError:
raise cmdexc.CommandError("No element focused!") raise cmdexc.CommandError("No element focused!")
if not elem.is_editable(strict=True): if not elem.is_editable(strict=True):
@ -1695,9 +1698,9 @@ class CommandDispatcher:
if out is None: if out is None:
# Getting the actual error (if any) seems to be difficult. # Getting the actual error (if any) seems to be difficult.
# The error does end up in # The error does end up in
# BrowserPage.javaScriptConsoleMessage(), but distinguishing # BrowserPage.javaScriptConsoleMessage(), but
# between :jseval errors and errors from the webpage is not # distinguishing between :jseval errors and errors from the
# trivial... # webpage is not trivial...
message.info(self._win_id, 'No output or error') message.info(self._win_id, 'No output or error')
else: else:
# The output can be a string, number, dict, array, etc. But # The output can be a string, number, dict, array, etc. But
@ -1705,13 +1708,11 @@ class CommandDispatcher:
# qutebrowser hang # qutebrowser hang
out = str(out) out = str(out)
if len(out) > 5000: if len(out) > 5000:
message.info(self._win_id, out[:5000] + ' [...trimmed...]') out = out[:5000] + ' [...trimmed...]'
else: message.info(self._win_id, out)
message.info(self._win_id, out)
self._current_widget().run_js_async(js_code, callback=jseval_cb) self._current_widget().run_js_async(js_code, callback=jseval_cb)
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
def fake_key(self, keystring, global_=False): def fake_key(self, keystring, global_=False):
"""Send a fake keypress or key string to the website or qutebrowser. """Send a fake keypress or key string to the website or qutebrowser.

View File

@ -819,7 +819,9 @@ class HintManager(QObject):
tab = tabbed_browser.currentWidget() tab = tabbed_browser.currentWidget()
if tab is None: if tab is None:
raise cmdexc.CommandError("No WebView available yet!") raise cmdexc.CommandError("No WebView available yet!")
mainframe = tab._widget.page().mainFrame() # FIXME # FIXME:refactor have a proper API for this
page = tab._widget.page() # pylint: disable=protected-access
mainframe = page.mainFrame()
if mainframe is None: if mainframe is None:
raise cmdexc.CommandError("No frame focused!") raise cmdexc.CommandError("No frame focused!")
mode_manager = objreg.get('mode-manager', scope='window', mode_manager = objreg.get('mode-manager', scope='window',

View File

@ -42,28 +42,34 @@ class WebTabError(Exception):
class WrapperLayout(QLayout): class WrapperLayout(QLayout):
"""A Qt layout which simply wraps a single widget.
This is used so the widget is hidden behind a AbstractTab API and can't
easily be accidentally accessed.
"""
def __init__(self, widget, parent=None): def __init__(self, widget, parent=None):
super().__init__(parent) super().__init__(parent)
self._widget = widget self._widget = widget
def addItem(self, w): def addItem(self, _widget):
raise AssertionError("Should never be called!") raise AssertionError("Should never be called!")
def sizeHint(self): def sizeHint(self):
return self._widget.sizeHint() return self._widget.sizeHint()
def itemAt(self, i): def itemAt(self, _index):
# FIXME why does this get called? # FIXME why does this get called?
return None return None
def takeAt(self, i): def takeAt(self, _index):
raise AssertionError("Should never be called!") raise AssertionError("Should never be called!")
def setGeometry(self, r): def setGeometry(self, rect):
self._widget.setGeometry(r) self._widget.setGeometry(rect)
class TabData(QObject): class TabData:
"""A simple namespace with a fixed set of attributes. """A simple namespace with a fixed set of attributes.
@ -82,7 +88,8 @@ class TabData(QObject):
def __getattr__(self, attr): def __getattr__(self, attr):
if attr.startswith('_'): if attr.startswith('_'):
return super().__getattr__(attr) # WORKAROUND for https://github.com/PyCQA/pylint/issues/979
return super().__getattr__(attr) # pylint: disable=no-member
try: try:
return self._data[attr] return self._data[attr]
except KeyError: except KeyError:
@ -92,7 +99,8 @@ class TabData(QObject):
if attr.startswith('_'): if attr.startswith('_'):
return super().__setattr__(attr, value) return super().__setattr__(attr, value)
if attr not in self._data: if attr not in self._data:
raise AttributeError("Can't set unknown attribute {!r}".format(attr)) msg = "Can't set unknown attribute {!r}".format(attr)
raise AttributeError(msg)
self._data[attr] = value self._data[attr] = value
@ -218,6 +226,7 @@ class AbstractZoom(QObject):
if factor < 0: if factor < 0:
return return
perc = int(100 * factor) perc = int(100 * factor)
# FIXME move this somewhere else?
message.info(self.win_id, "Zoom level: {}%".format(perc)) message.info(self.win_id, "Zoom level: {}%".format(perc))
self._neighborlist.fuzzyval = perc self._neighborlist.fuzzyval = perc
self._set_factor_internal(factor) self._set_factor_internal(factor)
@ -300,7 +309,7 @@ class AbstractCaret(QObject):
def selection(self, html=False): def selection(self, html=False):
raise NotImplementedError raise NotImplementedError
def follow_selected(self, tab=False): def follow_selected(self, *, tab=False):
raise NotImplementedError raise NotImplementedError
@ -452,6 +461,7 @@ class AbstractTab(QWidget):
self.backend = None self.backend = None
def _set_widget(self, widget): def _set_widget(self, widget):
# pylint: disable=protected-access
self._layout = WrapperLayout(widget, self) self._layout = WrapperLayout(widget, self)
self._widget = widget self._widget = widget
self.history._history = widget.history() self.history._history = widget.history()

View File

@ -24,16 +24,19 @@ from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
try: try:
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage from PyQt5.QtWebEngineWidgets import QWebEnginePage
except ImportError: except ImportError:
QWebEngineView = None QWebEngineView = None
QWebEnginePage = None
from qutebrowser.browser import tab from qutebrowser.browser import tab
from qutebrowser.browser.webengine import webview from qutebrowser.browser.webengine import webview
from qutebrowser.utils import usertypes, qtutils from qutebrowser.utils import usertypes, qtutils
## FIXME:refactor add stubs for abstract things which aren't implemented yet.
## pylint: disable=abstract-method
class WebEngineSearch(tab.AbstractSearch): class WebEngineSearch(tab.AbstractSearch):
## TODO ## TODO
@ -66,7 +69,7 @@ class WebEngineCaret(tab.AbstractCaret):
class WebEngineScroller(tab.AbstractScroller): class WebEngineScroller(tab.AbstractScroller):
def _key_press(self, key, count=1, getter_name=None, direction=None): def _key_press(self, key, count=1):
# FIXME for some reason this does not work? :-/ # FIXME for some reason this does not work? :-/
# FIXME Abort scrolling if the minimum/maximum was reached. # FIXME Abort scrolling if the minimum/maximum was reached.
press_evt = QKeyEvent(QEvent.KeyPress, key, Qt.NoModifier, 0, 0, 0) press_evt = QKeyEvent(QEvent.KeyPress, key, Qt.NoModifier, 0, 0, 0)
@ -91,16 +94,16 @@ class WebEngineScroller(tab.AbstractScroller):
return (perc_x, perc_y) return (perc_x, perc_y)
def up(self, count=1): def up(self, count=1):
self._key_press(Qt.Key_Up, count, 'scrollBarMinimum', Qt.Vertical) self._key_press(Qt.Key_Up, count)
def down(self, count=1): def down(self, count=1):
self._key_press(Qt.Key_Down, count, 'scrollBarMaximum', Qt.Vertical) self._key_press(Qt.Key_Down, count)
def left(self, count=1): def left(self, count=1):
self._key_press(Qt.Key_Left, count, 'scrollBarMinimum', Qt.Horizontal) self._key_press(Qt.Key_Left, count)
def right(self, count=1): def right(self, count=1):
self._key_press(Qt.Key_Right, count, 'scrollBarMaximum', Qt.Horizontal) self._key_press(Qt.Key_Right, count)
def top(self): def top(self):
self._key_press(Qt.Key_Home) self._key_press(Qt.Key_Home)
@ -109,11 +112,10 @@ class WebEngineScroller(tab.AbstractScroller):
self._key_press(Qt.Key_End) self._key_press(Qt.Key_End)
def page_up(self, count=1): def page_up(self, count=1):
self._key_press(Qt.Key_PageUp, count, 'scrollBarMinimum', Qt.Vertical) self._key_press(Qt.Key_PageUp, count)
def page_down(self, count=1): def page_down(self, count=1):
self._key_press(Qt.Key_PageDown, count, 'scrollBarMaximum', self._key_press(Qt.Key_PageDown, count)
Qt.Vertical)
## TODO ## TODO

View File

@ -26,6 +26,8 @@ from PyQt5.QtWebEngineWidgets import QWebEngineView
class WebEngineView(QWebEngineView): class WebEngineView(QWebEngineView):
"""Custom QWebEngineView subclass with qutebrowser-specific features."""
mouse_wheel_zoom = pyqtSignal(QPoint) mouse_wheel_zoom = pyqtSignal(QPoint)
def wheelEvent(self, e): def wheelEvent(self, e):

View File

@ -255,7 +255,8 @@ class _Downloader:
web_url = self.web_view.cur_url web_url = self.web_view.cur_url
# FIXME:refactor have a proper API for this # FIXME:refactor have a proper API for this
web_frame = self.web_view._widget.page().mainFrame() page = self.web_view._widget.page() # pylint: disable=protected-access
web_frame = page.mainFrame()
self.writer = MHTMLWriter( self.writer = MHTMLWriter(
web_frame.toHtml().encode('utf-8'), web_frame.toHtml().encode('utf-8'),

View File

@ -28,12 +28,12 @@ from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWebKitWidgets import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.QtWebKit import QWebSettings from PyQt5.QtWebKit import QWebSettings
from qutebrowser.browser import tab from qutebrowser.browser import tab as tabmod
from qutebrowser.browser.webkit import webview, tabhistory from qutebrowser.browser.webkit import webview, tabhistory
from qutebrowser.utils import qtutils, objreg, usertypes, utils from qutebrowser.utils import qtutils, objreg, usertypes, utils
class WebViewSearch(tab.AbstractSearch): class WebViewSearch(tabmod.AbstractSearch):
def clear(self): def clear(self):
# We first clear the marked text, then the highlights # We first clear the marked text, then the highlights
@ -73,7 +73,7 @@ class WebViewSearch(tab.AbstractSearch):
self._widget.search(self.text, flags) self._widget.search(self.text, flags)
class WebViewCaret(tab.AbstractCaret): class WebViewCaret(tabmod.AbstractCaret):
@pyqtSlot(usertypes.KeyMode) @pyqtSlot(usertypes.KeyMode)
def on_mode_entered(self, mode): def on_mode_entered(self, mode):
@ -99,8 +99,8 @@ class WebViewCaret(tab.AbstractCaret):
self._widget.page().currentFrame().evaluateJavaScript( self._widget.page().currentFrame().evaluateJavaScript(
utils.read_file('javascript/position_caret.js')) utils.read_file('javascript/position_caret.js'))
@pyqtSlot(usertypes.KeyMode) @pyqtSlot()
def on_mode_left(self, mode): def on_mode_left(self):
settings = self._widget.settings() settings = self._widget.settings()
if settings.testAttribute(QWebSettings.CaretBrowsingEnabled): if settings.testAttribute(QWebSettings.CaretBrowsingEnabled):
if self.selection_enabled and self._widget.hasSelection(): if self.selection_enabled and self._widget.hasSelection():
@ -277,13 +277,13 @@ class WebViewCaret(tab.AbstractCaret):
selected_element = xml.etree.ElementTree.fromstring( selected_element = xml.etree.ElementTree.fromstring(
'<html>{}</html>'.format(selection)).find('a') '<html>{}</html>'.format(selection)).find('a')
except xml.etree.ElementTree.ParseError: except xml.etree.ElementTree.ParseError:
raise tab.WebTabError('Could not parse selected element!') raise tabmod.WebTabError('Could not parse selected element!')
if selected_element is not None: if selected_element is not None:
try: try:
url = selected_element.attrib['href'] url = selected_element.attrib['href']
except KeyError: except KeyError:
raise tab.WebTabError('Anchor element without href!') raise tabmod.WebTabError('Anchor element without href!')
url = self._tab.cur_url.resolved(QUrl(url)) url = self._tab.cur_url.resolved(QUrl(url))
if tab: if tab:
self._tab.new_tab_requested.emit(url) self._tab.new_tab_requested.emit(url)
@ -291,7 +291,7 @@ class WebViewCaret(tab.AbstractCaret):
self._tab.openurl(url) self._tab.openurl(url)
class WebViewZoom(tab.AbstractZoom): class WebViewZoom(tabmod.AbstractZoom):
def _set_factor_internal(self, factor): def _set_factor_internal(self, factor):
self._widget.setZoomFactor(factor) self._widget.setZoomFactor(factor)
@ -300,7 +300,7 @@ class WebViewZoom(tab.AbstractZoom):
return self._widget.zoomFactor() return self._widget.zoomFactor()
class WebViewScroller(tab.AbstractScroller): class WebViewScroller(tabmod.AbstractScroller):
def pos_px(self): def pos_px(self):
return self._widget.page().mainFrame().scrollPosition() return self._widget.page().mainFrame().scrollPosition()
@ -316,7 +316,7 @@ class WebViewScroller(tab.AbstractScroller):
qtutils.check_overflow(y, 'int') qtutils.check_overflow(y, 'int')
self._widget.page().mainFrame().scroll(x, y) self._widget.page().mainFrame().scroll(x, y)
def delta_page(self, x=0, y=0): def delta_page(self, x=0.0, y=0.0):
if y.is_integer(): if y.is_integer():
y = int(y) y = int(y)
if y == 0: if y == 0:
@ -339,7 +339,7 @@ class WebViewScroller(tab.AbstractScroller):
else: else:
for val, orientation in [(x, Qt.Horizontal), (y, Qt.Vertical)]: for val, orientation in [(x, Qt.Horizontal), (y, Qt.Vertical)]:
if val is not None: if val is not None:
perc = qtutils.check_overflow(val, 'int', fatal=False) val = qtutils.check_overflow(val, 'int', fatal=False)
frame = self._widget.page().mainFrame() frame = self._widget.page().mainFrame()
m = frame.scrollBarMaximum(orientation) m = frame.scrollBarMaximum(orientation)
if m == 0: if m == 0:
@ -396,7 +396,7 @@ class WebViewScroller(tab.AbstractScroller):
return self.pos_px().y() >= frame.scrollBarMaximum(Qt.Vertical) return self.pos_px().y() >= frame.scrollBarMaximum(Qt.Vertical)
class WebViewHistory(tab.AbstractHistory): class WebViewHistory(tabmod.AbstractHistory):
def current_idx(self): def current_idx(self):
return self._history.currentItemIndex() return self._history.currentItemIndex()
@ -434,7 +434,7 @@ class WebViewHistory(tab.AbstractHistory):
self._tab.scroll.to_point, cur_data['scroll-pos'])) self._tab.scroll.to_point, cur_data['scroll-pos']))
class WebViewTab(tab.AbstractTab): class WebViewTab(tabmod.AbstractTab):
def __init__(self, win_id, modeman, parent=None): def __init__(self, win_id, modeman, parent=None):
super().__init__(win_id) super().__init__(win_id)
@ -447,8 +447,8 @@ class WebViewTab(tab.AbstractTab):
self.search = WebViewSearch(parent=self) self.search = WebViewSearch(parent=self)
self._set_widget(widget) self._set_widget(widget)
self._connect_signals() self._connect_signals()
self.zoom._set_default_zoom() self.zoom._set_default_zoom() # pylint: disable=protected-access
self.backend = tab.Backend.QtWebKit self.backend = tabmod.Backend.QtWebKit
def openurl(self, url): def openurl(self, url):
self._widget.openurl(url) self._widget.openurl(url)
@ -520,9 +520,9 @@ class WebViewTab(tab.AbstractTab):
view.load_status_changed.connect(self.load_status_changed) view.load_status_changed.connect(self.load_status_changed)
view.shutting_down.connect(self.shutting_down) view.shutting_down.connect(self.shutting_down)
# Make sure we emit an appropriate status when loading finished. # Make sure we emit an appropriate status when loading finished. While
# While Qt has a bool "ok" attribute for loadFinished, it always is True # Qt has a bool "ok" attribute for loadFinished, it always is True when
# when using error pages... # using error pages...
# See https://github.com/The-Compiler/qutebrowser/issues/84 # See https://github.com/The-Compiler/qutebrowser/issues/84
frame.loadFinished.connect(lambda: frame.loadFinished.connect(lambda:
self.load_finished.emit( self.load_finished.emit(

View File

@ -21,8 +21,7 @@
import functools import functools
from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, Qt, QUrl, QPoint, from PyQt5.QtCore import pyqtSlot, pyqtSignal, PYQT_VERSION, Qt, QUrl, QPoint
QTimer)
from PyQt5.QtGui import QDesktopServices from PyQt5.QtGui import QDesktopServices
from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest
from PyQt5.QtWidgets import QFileDialog from PyQt5.QtWidgets import QFileDialog
@ -31,7 +30,7 @@ from PyQt5.QtWebKitWidgets import QWebPage
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.browser import pdfjs from qutebrowser.browser import pdfjs
from qutebrowser.browser.webkit import http, tabhistory from qutebrowser.browser.webkit import http
from qutebrowser.browser.webkit.network import networkmanager from qutebrowser.browser.webkit.network import networkmanager
from qutebrowser.utils import (message, usertypes, log, jinja, qtutils, utils, from qutebrowser.utils import (message, usertypes, log, jinja, qtutils, utils,
objreg, debug, urlutils) objreg, debug, urlutils)

View File

@ -20,8 +20,6 @@
"""The main browser widgets.""" """The main browser widgets."""
import sys import sys
import itertools
import functools
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl, QPoint from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl, QPoint
from PyQt5.QtGui import QPalette from PyQt5.QtGui import QPalette
@ -38,9 +36,7 @@ from qutebrowser.browser.webkit import webpage, webelem
class WebView(QWebView): class WebView(QWebView):
"""One browser tab in TabbedBrowser. """Custom QWebView subclass with qutebrowser-specific features.
Our own subclass of a QWebView with some added bells and whistles.
Attributes: Attributes:
tab: The WebKitTab object for this WebView tab: The WebKitTab object for this WebView
@ -495,6 +491,7 @@ class WebView(QWebView):
"support that!") "support that!")
tabbed_browser = objreg.get('tabbed-browser', scope='window', tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=self.win_id) window=self.win_id)
# pylint: disable=protected-access
return tabbed_browser.tabopen(background=False)._widget return tabbed_browser.tabopen(background=False)._widget
def paintEvent(self, e): def paintEvent(self, e):

View File

@ -26,7 +26,7 @@ import tempfile
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QSocketNotifier from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QSocketNotifier
from qutebrowser.utils import message, log, objreg, standarddir from qutebrowser.utils import message, log, objreg, standarddir
from qutebrowser.commands import runners, cmdexc from qutebrowser.commands import runners
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.misc import guiprocess from qutebrowser.misc import guiprocess
from qutebrowser.browser.webkit import downloads from qutebrowser.browser.webkit import downloads

View File

@ -330,7 +330,7 @@ class StatusBar(QWidget):
self._command_active = val self._command_active = val
elif mode == usertypes.KeyMode.caret: elif mode == usertypes.KeyMode.caret:
tab = objreg.get('tabbed-browser', scope='window', tab = objreg.get('tabbed-browser', scope='window',
window=self._win_id).currentWidget() window=self._win_id).currentWidget()
log.statusbar.debug("Setting caret_mode - val {}, selection " log.statusbar.debug("Setting caret_mode - val {}, selection "
"{}".format(val, tab.caret.selection_enabled)) "{}".format(val, tab.caret.selection_enabled))
if val: if val:

View File

@ -381,7 +381,6 @@ class TabbedBrowser(tabwidget.TabWidget):
window=window.win_id) window=window.win_id)
return tabbed_browser.tabopen(url, background, explicit) return tabbed_browser.tabopen(url, background, explicit)
if objreg.get('args').backend == 'webengine': if objreg.get('args').backend == 'webengine':
tab_class = webenginetab.WebEngineViewTab tab_class = webenginetab.WebEngineViewTab
else: else:

View File

@ -29,7 +29,6 @@ from PyQt5.QtGui import QIcon, QPalette, QColor
from qutebrowser.utils import qtutils, objreg, utils, usertypes from qutebrowser.utils import qtutils, objreg, utils, usertypes
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.browser.webkit import webview
PixelMetrics = usertypes.enum('PixelMetrics', ['icon_padding'], PixelMetrics = usertypes.enum('PixelMetrics', ['icon_padding'],

View File

@ -251,8 +251,6 @@ LoadStatus = enum('LoadStatus', ['none', 'success', 'success_https', 'error',
'warn', 'loading']) 'warn', 'loading'])
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

@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
# pylint: disable=invalid-name # pylint: disable=invalid-name,abstract-method
"""Fake objects/stubs.""" """Fake objects/stubs."""
@ -27,7 +27,7 @@ from unittest import mock
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache, from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
QNetworkCacheMetaData) QNetworkCacheMetaData)
from PyQt5.QtWidgets import QCommonStyle, QWidget, QLineEdit from PyQt5.QtWidgets import QCommonStyle, QLineEdit
from qutebrowser.browser import tab from qutebrowser.browser import tab
from qutebrowser.browser.webkit import webview, history from qutebrowser.browser.webkit import webview, history
@ -227,6 +227,8 @@ def fake_qprocess():
class FakeWebTabScroller(tab.AbstractScroller): class FakeWebTabScroller(tab.AbstractScroller):
"""Fake AbstractScroller to use in tests."""
def __init__(self, pos_perc): def __init__(self, pos_perc):
super().__init__() super().__init__()
self._pos_perc = pos_perc self._pos_perc = pos_perc

View File

@ -86,13 +86,13 @@ class TestTabData:
def test_known_attr(self): def test_known_attr(self):
data = tab.TabData() data = tab.TabData()
assert data.keep_icon == False assert not data.keep_icon
data.keep_icon = True data.keep_icon = True
assert data.keep_icon == True assert data.keep_icon
def test_unknown_attr(self): def test_unknown_attr(self):
data = tab.TabData() data = tab.TabData()
with pytest.raises(AttributeError): with pytest.raises(AttributeError):
data.bar = 42 data.bar = 42
with pytest.raises(AttributeError): with pytest.raises(AttributeError):
data.bar data.bar # pylint: disable=pointless-statement

View File

@ -26,7 +26,7 @@ import signal
import pytest import pytest
from PyQt5.QtCore import QFileSystemWatcher from PyQt5.QtCore import QFileSystemWatcher
from qutebrowser.commands import userscripts, cmdexc from qutebrowser.commands import userscripts
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -235,5 +235,5 @@ def test_unsupported(monkeypatch, tabbed_browser_stubs):
monkeypatch.setattr(userscripts.os, 'name', 'toaster') monkeypatch.setattr(userscripts.os, 'name', 'toaster')
with pytest.raises(userscripts.UnsupportedError) as excinfo: with pytest.raises(userscripts.UnsupportedError) as excinfo:
userscripts.run_async(tab=None, cmd=None, win_id=0, env=None) userscripts.run_async(tab=None, cmd=None, win_id=0, env=None)
expected ="Userscripts are not supported on this platform!" expected = "Userscripts are not supported on this platform!"
assert str(excinfo.value) == expected assert str(excinfo.value) == expected