Fix javascript statusbar messages

This commit is contained in:
Florian Bruhin 2014-06-03 17:59:15 +02:00
parent 4fd31811d8
commit 62908e97c1
5 changed files with 42 additions and 14 deletions

1
TODO
View File

@ -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
=====

View File

@ -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)

View File

@ -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."""

View File

@ -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

View File

@ -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