Display some messages immediately

This commit is contained in:
Florian Bruhin 2014-05-16 17:21:43 +02:00
parent bccf912958
commit 2c2c79af2e
4 changed files with 53 additions and 23 deletions

View File

@ -207,7 +207,7 @@ DATA = OrderedDict([
"Whether to show vertical scrollbar for web content."),
('message-timeout',
SettingValue(types.Int(), '3000'),
SettingValue(types.Int(), '2000'),
"Time (in ms) to show messages in the statusbar for."),
)),

View File

@ -27,18 +27,30 @@ def instance():
return QCoreApplication.instance().messagebridge
def error(message):
"""Display an error message in the statusbar."""
def error(message, immediate=False):
"""Display an error message in the statusbar.
Args:
message: The message to display.
immediate: If set, message gets displayed immediately rather than
getting queued.
"""
message = str(message)
logging.error(message)
instance().error.emit(message)
instance().error.emit(message, immediate)
def info(message):
"""Display a temporary info message in the statusbar."""
def info(message, immediate=False):
"""Display a temporary info message in the statusbar.
Args:
message: The message to display.
immediate: If set, message gets displayed immediately rather than
getting queued.
"""
message = str(message)
logging.info(message)
instance().info.emit(message)
instance().info.emit(message, immediate)
def text(message):
@ -62,7 +74,7 @@ class MessageBridge(QObject):
"""Bridge for messages to be shown in the statusbar."""
error = pyqtSignal(str)
info = pyqtSignal(str)
error = pyqtSignal(str, bool)
info = pyqtSignal(str, bool)
text = pyqtSignal(str)
set_cmd_text = pyqtSignal(str)

View File

@ -181,9 +181,15 @@ class StatusBar(QWidget):
self._text_pop_timer.start()
self._stack.setCurrentWidget(self.txt)
@pyqtSlot(str)
def _disp_text(self, text, error):
"""Inner logic for disp_error and disp_temp_text."""
def _disp_text(self, text, error, immediate):
"""Inner logic for disp_error and disp_temp_text.
Args:
text: The message to display.
error: Whether it's an error message (True) or normal text (False)
immediate: If set, message gets displayed immediately rather than
getting queued.
"""
logging.debug("Displaying text: {} (error={})".format(text, error))
now = datetime.now()
mindelta = config.get('general', 'message-timeout')
@ -191,8 +197,8 @@ class StatusBar(QWidget):
else now - self._last_text_time)
self._last_text_time = now
logging.debug("queue: {} / delta: {}".format(self._text_queue, delta))
if not self._text_queue and (
delta is None or delta.total_seconds() * 1000.0 > mindelta):
if immediate or (not self._text_queue and (
delta is None or delta.total_seconds() * 1000.0 > mindelta)):
# If the queue is empty and we didn't print messages for long
# enough, we can take the short route and display the message
# immediately. We then start the pop_timer only to restore the
@ -212,15 +218,27 @@ class StatusBar(QWidget):
self._text_queue.append((error, text))
self._text_pop_timer.start()
@pyqtSlot(str)
def disp_error(self, text):
"""Display an error in the statusbar."""
self._disp_text(text, True)
@pyqtSlot(str, bool)
def disp_error(self, text, immediate):
"""Display an error in the statusbar.
@pyqtSlot(str)
def disp_temp_text(self, text):
"""Add a temporary text to the queue."""
self._disp_text(text, False)
Args:
text: The message to display.
immediate: If set, message gets displayed immediately rather than
getting queued.
"""
self._disp_text(text, True, immediate)
@pyqtSlot(str, bool)
def disp_temp_text(self, text, immediate):
"""Display a temporary text in the statusbar.
Args:
text: The message to display.
immediate: If set, message gets displayed immediately rather than
getting queued.
"""
self._disp_text(text, False, immediate)
@pyqtSlot(str)
def set_text(self, val):

View File

@ -309,7 +309,7 @@ class WebView(QWebView):
if perc < 0:
raise CommandError("Can't zoom {}%!".format(perc))
self.setZoomFactor(float(perc) / 100)
message.info("Zoom level: {}%".format(perc))
message.info("Zoom level: {}%".format(perc), immediate=True)
def zoom(self, offset):
"""Increase/Decrease the zoom level.