Get qutebrowser to run
This commit is contained in:
parent
048f7dcaf5
commit
b0a391932a
@ -19,11 +19,17 @@
|
||||
|
||||
"""Base class for a wrapper over QWebView/QWebEngineView."""
|
||||
|
||||
import itertools
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QWidget, QLayout
|
||||
|
||||
|
||||
tab_id_gen = itertools.count(0)
|
||||
|
||||
|
||||
|
||||
class WrapperLayout(QLayout):
|
||||
|
||||
def __init__(self, widget, parent=None):
|
||||
@ -52,6 +58,12 @@ class AbstractTab(QWidget):
|
||||
|
||||
We use this to unify QWebView and QWebEngineView.
|
||||
|
||||
Attributes:
|
||||
keep_icon: Whether the (e.g. cloned) icon should not be cleared on page
|
||||
load.
|
||||
|
||||
for properties, see WebView/WebEngineView docs.
|
||||
|
||||
Signals:
|
||||
See related Qt signals.
|
||||
"""
|
||||
@ -63,12 +75,19 @@ class AbstractTab(QWidget):
|
||||
load_finished = pyqtSignal(bool)
|
||||
scroll_pos_changed = pyqtSignal(int, int)
|
||||
icon_changed = pyqtSignal(QIcon)
|
||||
url_text_changed = pyqtSignal(str) # FIXME get rid of this altogether?
|
||||
# FIXME:refactor get rid of this altogether?
|
||||
url_text_changed = pyqtSignal(str)
|
||||
title_changed = pyqtSignal(str)
|
||||
load_status_changed = pyqtSignal(str)
|
||||
|
||||
def __init__(self, widget, parent=None):
|
||||
def __init__(self, parent=None):
|
||||
self.tab_id = next(tab_id_gen)
|
||||
super().__init__(parent)
|
||||
self._layout = None
|
||||
self._widget = None
|
||||
self.keep_icon = False # FIXME:refactor get rid of this?
|
||||
|
||||
def _set_widget(self, widget):
|
||||
self._layout = WrapperLayout(widget, self)
|
||||
self._widget = widget
|
||||
widget.setParent(self)
|
||||
@ -88,3 +107,6 @@ class AbstractTab(QWidget):
|
||||
@property
|
||||
def scroll_pos(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def openurl(self, url):
|
||||
raise NotImplementedError
|
||||
|
@ -28,10 +28,30 @@ from qutebrowser.browser.webkit.webview import WebView
|
||||
class WebViewTab(AbstractTab):
|
||||
|
||||
def __init__(self, win_id, parent=None):
|
||||
widget = WebView(win_id)
|
||||
super().__init__(widget)
|
||||
super().__init__()
|
||||
widget = WebView(win_id, self.tab_id)
|
||||
self._set_widget(widget)
|
||||
self._connect_signals()
|
||||
|
||||
def openurl(self, url):
|
||||
self._widget.openurl(url)
|
||||
|
||||
@property
|
||||
def cur_url(self):
|
||||
return self._widget.cur_url
|
||||
|
||||
@property
|
||||
def progress(self):
|
||||
return self._widget.progress
|
||||
|
||||
@property
|
||||
def load_status(self):
|
||||
return self._widget.load_status
|
||||
|
||||
@property
|
||||
def scroll_pos(self):
|
||||
return self._widget.scroll_pos
|
||||
|
||||
def _connect_signals(self):
|
||||
view = self._widget
|
||||
page = view.page()
|
||||
@ -51,7 +71,7 @@ class WebViewTab(AbstractTab):
|
||||
# See https://github.com/The-Compiler/qutebrowser/issues/84
|
||||
frame.loadFinished.connect(lambda:
|
||||
self.load_finished.emit(
|
||||
not self._widget.page().error_occured))
|
||||
not self._widget.page().error_occurred))
|
||||
|
||||
# Emit iconChanged with a QIcon like QWebEngineView does.
|
||||
view.iconChanged.connect(lambda:
|
||||
|
@ -40,9 +40,6 @@ LoadStatus = usertypes.enum('LoadStatus', ['none', 'success', 'success_https',
|
||||
'error', 'warn', 'loading'])
|
||||
|
||||
|
||||
tab_id_gen = itertools.count(0)
|
||||
|
||||
|
||||
class WebView(QWebView):
|
||||
|
||||
"""One browser tab in TabbedBrowser.
|
||||
@ -58,13 +55,11 @@ class WebView(QWebView):
|
||||
load_status: loading status of this page (index into LoadStatus)
|
||||
viewing_source: Whether the webview is currently displaying source
|
||||
code.
|
||||
keep_icon: Whether the (e.g. cloned) icon should not be cleared on page
|
||||
load.
|
||||
registry: The ObjectRegistry associated with this tab.
|
||||
tab_id: The tab ID of the view.
|
||||
win_id: The window ID of the view.
|
||||
search_text: The text of the last search.
|
||||
search_flags: The search flags of the last search.
|
||||
_tab_id: The tab ID of the view.
|
||||
_has_ssl_errors: Whether SSL errors occurred during loading.
|
||||
_zoom: A NeighborList with the zoom levels.
|
||||
_old_scroll_pos: The old scroll position.
|
||||
@ -90,7 +85,7 @@ class WebView(QWebView):
|
||||
url_text_changed = pyqtSignal(str)
|
||||
shutting_down = pyqtSignal()
|
||||
|
||||
def __init__(self, win_id, parent=None):
|
||||
def __init__(self, win_id, tab_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
|
||||
@ -122,13 +117,14 @@ class WebView(QWebView):
|
||||
self.cur_url = QUrl()
|
||||
self.progress = 0
|
||||
self.registry = objreg.ObjectRegistry()
|
||||
self.tab_id = next(tab_id_gen)
|
||||
self._tab_id = tab_id
|
||||
# FIXME:refactor stop registering it here
|
||||
tab_registry = objreg.get('tab-registry', scope='window',
|
||||
window=win_id)
|
||||
tab_registry[self.tab_id] = self
|
||||
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 = 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)
|
||||
@ -161,7 +157,7 @@ class WebView(QWebView):
|
||||
|
||||
def _init_page(self):
|
||||
"""Initialize the QWebPage used by this view."""
|
||||
page = webpage.BrowserPage(self.win_id, self.tab_id, self)
|
||||
page = webpage.BrowserPage(self.win_id, self._tab_id, self)
|
||||
self.setPage(page)
|
||||
page.linkHovered.connect(self.linkHovered)
|
||||
page.mainFrame().loadStarted.connect(self.on_load_started)
|
||||
@ -176,7 +172,7 @@ class WebView(QWebView):
|
||||
|
||||
def __repr__(self):
|
||||
url = utils.elide(self.url().toDisplayString(QUrl.EncodeUnicode), 100)
|
||||
return utils.get_repr(self, tab_id=self.tab_id, url=url)
|
||||
return utils.get_repr(self, tab_id=self._tab_id, url=url)
|
||||
|
||||
def __del__(self):
|
||||
# Explicitly releasing the page here seems to prevent some segfaults
|
||||
|
@ -345,7 +345,6 @@ class MainWindow(QWidget):
|
||||
|
||||
tabs.tab_index_changed.connect(status.tabindex.on_tab_index_changed)
|
||||
|
||||
tabs.current_tab_changed.connect(status.txt.on_tab_changed)
|
||||
tabs.cur_statusbar_message.connect(status.txt.on_statusbar_message)
|
||||
tabs.cur_load_started.connect(status.txt.on_load_started)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user