From 62908e97c158b1b74ec85799b5f866186eb2f7e2 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 3 Jun 2014 17:59:15 +0200 Subject: [PATCH] Fix javascript statusbar messages --- TODO | 1 - qutebrowser/app.py | 6 ++++- qutebrowser/widgets/statusbar/bar.py | 11 --------- qutebrowser/widgets/statusbar/text.py | 34 ++++++++++++++++++++++++++- qutebrowser/widgets/webview.py | 4 ++++ 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index d22f8ac44..4a4d1fe8f 100644 --- a/TODO +++ b/TODO @@ -14,7 +14,6 @@ Before 0.1 - ssl-strict=ask - SSL-symbol in statusbar? - Downloads (at least calling a handler) -- How long should javascript statusbar messages be displayed?! Style ===== diff --git a/qutebrowser/app.py b/qutebrowser/app.py index c4950df36..f73daaa5a 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -392,6 +392,8 @@ class QuteBrowser(QApplication): self.config.changed.connect(obj.on_config_changed) # statusbar + # FIXME some of these probably only should be triggered on mainframe + # loadStarted. tabs.currentChanged.connect(status.prog.on_tab_changed) tabs.cur_progress.connect(status.prog.setValue) tabs.cur_load_finished.connect(status.prog.hide) @@ -400,7 +402,9 @@ class QuteBrowser(QApplication): tabs.currentChanged.connect(status.percentage.on_tab_changed) tabs.cur_scroll_perc_changed.connect(status.percentage.set_perc) - tabs.cur_statusbar_message.connect(status.on_statusbar_message) + tabs.currentChanged.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) tabs.currentChanged.connect(status.url.on_tab_changed) tabs.cur_url_text_changed.connect(status.url.set_url) diff --git a/qutebrowser/widgets/statusbar/bar.py b/qutebrowser/widgets/statusbar/bar.py index bdbb52269..ea16cb5b4 100644 --- a/qutebrowser/widgets/statusbar/bar.py +++ b/qutebrowser/widgets/statusbar/bar.py @@ -329,17 +329,6 @@ class StatusBar(QWidget): if mode in modeman.instance().passthrough: self.txt.normaltext = "" - @pyqtSlot(str) - def on_statusbar_message(self, val): - """Called when javascript tries to set a statusbar message. - - For some reason, this is emitted a lot with an empty string during page - load, so we currently ignore these and thus don't support clearing the - message, which is a bit unfortunate... - """ - if val: - self.txt.temptext = val - @pyqtSlot(str, str) def on_config_changed(self, section, option): """Update message timeout when config changed.""" diff --git a/qutebrowser/widgets/statusbar/text.py b/qutebrowser/widgets/statusbar/text.py index fbc76ee19..08a684217 100644 --- a/qutebrowser/widgets/statusbar/text.py +++ b/qutebrowser/widgets/statusbar/text.py @@ -17,6 +17,8 @@ """Text displayed in the statusbar.""" +from PyQt5.QtCore import pyqtSlot + from qutebrowser.widgets.statusbar.textbase import TextBase @@ -29,6 +31,8 @@ class Text(TextBase): Accessed via normaltext property. _temptext: The temporary text to display. Accessed via temptext property. + _jstext: The text javascript wants to display. + Accessed via jstext property. The temptext is shown from StatusBar when a temporary text or error is available. If not, the permanent text is shown. @@ -38,6 +42,7 @@ class Text(TextBase): super().__init__(parent) self._normaltext = '' self._temptext = '' + self._jstext = '' @property def normaltext(self): @@ -61,11 +66,38 @@ class Text(TextBase): self._temptext = val self._update_text() + @property + def jstext(self): + """Getter for jstext so we can define a setter.""" + return self._jstext + + @jstext.setter + def jstext(self, val): + """Setter for jstext to update text display after setting.""" + self._jstext = val + self._update_text() + def _update_text(self): """Update QLabel text when needed.""" - for text in [self.temptext, self.normaltext]: + for text in [self.temptext, self.jstext, self.normaltext]: if text: self.setText(text) break else: self.setText('') + + @pyqtSlot(str) + def on_statusbar_message(self, val): + """Called when javascript tries to set a statusbar message.""" + self.jstext = val + + @pyqtSlot() + def on_load_started(self): + """Clear jstext when page loading started.""" + self.jstext = '' + + @pyqtSlot(int) + def on_tab_changed(self, idx): + """Set the correct jstext when the current tab changed.""" + tab = self.sender().widget(idx) + self.jstext = tab.statusbar_message diff --git a/qutebrowser/widgets/webview.py b/qutebrowser/widgets/webview.py index cae0eb337..fb39bddfc 100644 --- a/qutebrowser/widgets/webview.py +++ b/qutebrowser/widgets/webview.py @@ -54,6 +54,7 @@ class WebView(QWebView): work. progress: loading progress of this page. scroll_pos: The current scroll position as (x%, y%) tuple. + statusbar_message: The current javscript statusbar message. inspector: The QWebInspector used for this webview. _page: The QWebPage behind the view _url_text: The current URL as string. @@ -89,6 +90,7 @@ class WebView(QWebView): self.tabbedbrowser = parent self.inspector = None self.scroll_pos = (-1, -1) + self.statusbar_message = '' self._old_scroll_pos = (-1, -1) self._shutdown_callback = None self._open_target = Target.normal @@ -111,6 +113,8 @@ class WebView(QWebView): self.urlChanged.connect(self.on_url_changed) self.loadFinished.connect(self.on_load_finished) self.loadProgress.connect(lambda p: setattr(self, 'progress', p)) + self.page().statusBarMessage.connect( + lambda msg: setattr(self, 'statusbar_message', msg)) self.page().networkAccessManager().sslErrors.connect( lambda *args: setattr(self, '_has_ssl_errors', True)) # FIXME find some way to hide scrollbars without setScrollBarPolicy