From 6ae232d8fc2880e1c97c59079f30fa9cfe667c93 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 11 Jul 2016 11:31:59 +0200 Subject: [PATCH] Move 'progress' to AbstractTab This makes load progress work with QtWebEngine. --- qutebrowser/browser/browsertab.py | 9 ++++++++- qutebrowser/browser/webengine/webenginetab.py | 6 +----- qutebrowser/browser/webkit/webkittab.py | 5 +---- qutebrowser/browser/webkit/webview.py | 4 ---- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 2032d680e..8a7701402 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -466,6 +466,7 @@ class AbstractTab(QWidget): self.data = TabData() self._layout = None self._widget = None + self._progress = 0 self.backend = None def _set_widget(self, widget): @@ -483,14 +484,20 @@ class AbstractTab(QWidget): @pyqtSlot() def _on_load_started(self): + self._progress = 0 self.data.viewing_source = False self.load_started.emit() + @pyqtSlot(int) + def _on_load_progress(self, perc): + self._progress = perc + self.load_progress.emit(perc) + def url(self): raise NotImplementedError def progress(self): - raise NotImplementedError + return self._progress def load_status(self): raise NotImplementedError diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 2d4ac4d89..70ffa3a95 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -266,10 +266,6 @@ class WebEngineTab(browsertab.AbstractTab): def url(self): return self._widget.url() - def progress(self): - log.stub() - return 0 - def load_status(self): log.stub() return usertypes.LoadStatus.success @@ -321,7 +317,7 @@ class WebEngineTab(browsertab.AbstractTab): page = view.page() page.windowCloseRequested.connect(self.window_close_requested) page.linkHovered.connect(self.link_hovered) - page.loadProgress.connect(self.load_progress) + page.loadProgress.connect(self._on_load_progress) page.loadStarted.connect(self._on_load_started) view.titleChanged.connect(self.title_changed) page.loadFinished.connect(self.load_finished) diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index aa6b5a4b7..6629c33de 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -472,9 +472,6 @@ class WebKitTab(browsertab.AbstractTab): def url(self): return self._widget.cur_url - def progress(self): - return self._widget.progress - def load_status(self): return self._widget.load_status @@ -522,7 +519,7 @@ class WebKitTab(browsertab.AbstractTab): frame = page.mainFrame() page.windowCloseRequested.connect(self.window_close_requested) page.linkHovered.connect(self.link_hovered) - page.loadProgress.connect(self.load_progress) + page.loadProgress.connect(self._on_load_progress) frame.loadStarted.connect(self._on_load_started) view.scroll_pos_changed.connect(self.scroll.perc_changed) view.titleChanged.connect(self.title_changed) diff --git a/qutebrowser/browser/webkit/webview.py b/qutebrowser/browser/webkit/webview.py index 845c40f3f..f86cfa99c 100644 --- a/qutebrowser/browser/webkit/webview.py +++ b/qutebrowser/browser/webkit/webview.py @@ -41,7 +41,6 @@ class WebView(QWebView): Attributes: tab: The WebKitTab object for this WebView hintmanager: The HintManager instance for this view. - progress: loading progress of this page. scroll_pos: The current scroll position as (x%, y%) tuple. statusbar_message: The current javascript statusbar message. load_status: loading status of this page (index into LoadStatus) @@ -91,7 +90,6 @@ class WebView(QWebView): self._ignore_wheel_event = False self._set_bg_color() self.cur_url = QUrl() - self.progress = 0 self._tab_id = tab_id page = self._init_page() @@ -108,7 +106,6 @@ class WebView(QWebView): if config.get('input', 'rocker-gestures'): self.setContextMenuPolicy(Qt.PreventContextMenu) self.urlChanged.connect(self.on_url_changed) - self.loadProgress.connect(lambda p: setattr(self, 'progress', p)) objreg.get('config').changed.connect(self.on_config_changed) @pyqtSlot() @@ -355,7 +352,6 @@ class WebView(QWebView): @pyqtSlot() def on_load_started(self): """Leave insert/hint mode and set vars when a new page is loading.""" - self.progress = 0 self._has_ssl_errors = False self._set_load_status(usertypes.LoadStatus.loading)