Display some messages immediately
This commit is contained in:
parent
bccf912958
commit
2c2c79af2e
@ -207,7 +207,7 @@ DATA = OrderedDict([
|
|||||||
"Whether to show vertical scrollbar for web content."),
|
"Whether to show vertical scrollbar for web content."),
|
||||||
|
|
||||||
('message-timeout',
|
('message-timeout',
|
||||||
SettingValue(types.Int(), '3000'),
|
SettingValue(types.Int(), '2000'),
|
||||||
"Time (in ms) to show messages in the statusbar for."),
|
"Time (in ms) to show messages in the statusbar for."),
|
||||||
)),
|
)),
|
||||||
|
|
||||||
|
@ -27,18 +27,30 @@ def instance():
|
|||||||
return QCoreApplication.instance().messagebridge
|
return QCoreApplication.instance().messagebridge
|
||||||
|
|
||||||
|
|
||||||
def error(message):
|
def error(message, immediate=False):
|
||||||
"""Display an error message in the statusbar."""
|
"""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)
|
message = str(message)
|
||||||
logging.error(message)
|
logging.error(message)
|
||||||
instance().error.emit(message)
|
instance().error.emit(message, immediate)
|
||||||
|
|
||||||
|
|
||||||
def info(message):
|
def info(message, immediate=False):
|
||||||
"""Display a temporary info message in the statusbar."""
|
"""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)
|
message = str(message)
|
||||||
logging.info(message)
|
logging.info(message)
|
||||||
instance().info.emit(message)
|
instance().info.emit(message, immediate)
|
||||||
|
|
||||||
|
|
||||||
def text(message):
|
def text(message):
|
||||||
@ -62,7 +74,7 @@ class MessageBridge(QObject):
|
|||||||
|
|
||||||
"""Bridge for messages to be shown in the statusbar."""
|
"""Bridge for messages to be shown in the statusbar."""
|
||||||
|
|
||||||
error = pyqtSignal(str)
|
error = pyqtSignal(str, bool)
|
||||||
info = pyqtSignal(str)
|
info = pyqtSignal(str, bool)
|
||||||
text = pyqtSignal(str)
|
text = pyqtSignal(str)
|
||||||
set_cmd_text = pyqtSignal(str)
|
set_cmd_text = pyqtSignal(str)
|
||||||
|
@ -181,9 +181,15 @@ class StatusBar(QWidget):
|
|||||||
self._text_pop_timer.start()
|
self._text_pop_timer.start()
|
||||||
self._stack.setCurrentWidget(self.txt)
|
self._stack.setCurrentWidget(self.txt)
|
||||||
|
|
||||||
@pyqtSlot(str)
|
def _disp_text(self, text, error, immediate):
|
||||||
def _disp_text(self, text, error):
|
"""Inner logic for disp_error and disp_temp_text.
|
||||||
"""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))
|
logging.debug("Displaying text: {} (error={})".format(text, error))
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
mindelta = config.get('general', 'message-timeout')
|
mindelta = config.get('general', 'message-timeout')
|
||||||
@ -191,8 +197,8 @@ class StatusBar(QWidget):
|
|||||||
else now - self._last_text_time)
|
else now - self._last_text_time)
|
||||||
self._last_text_time = now
|
self._last_text_time = now
|
||||||
logging.debug("queue: {} / delta: {}".format(self._text_queue, delta))
|
logging.debug("queue: {} / delta: {}".format(self._text_queue, delta))
|
||||||
if not self._text_queue and (
|
if immediate or (not self._text_queue and (
|
||||||
delta is None or delta.total_seconds() * 1000.0 > mindelta):
|
delta is None or delta.total_seconds() * 1000.0 > mindelta)):
|
||||||
# If the queue is empty and we didn't print messages for long
|
# If the queue is empty and we didn't print messages for long
|
||||||
# enough, we can take the short route and display the message
|
# enough, we can take the short route and display the message
|
||||||
# immediately. We then start the pop_timer only to restore the
|
# 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_queue.append((error, text))
|
||||||
self._text_pop_timer.start()
|
self._text_pop_timer.start()
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str, bool)
|
||||||
def disp_error(self, text):
|
def disp_error(self, text, immediate):
|
||||||
"""Display an error in the statusbar."""
|
"""Display an error in the statusbar.
|
||||||
self._disp_text(text, True)
|
|
||||||
|
|
||||||
@pyqtSlot(str)
|
Args:
|
||||||
def disp_temp_text(self, text):
|
text: The message to display.
|
||||||
"""Add a temporary text to the queue."""
|
immediate: If set, message gets displayed immediately rather than
|
||||||
self._disp_text(text, False)
|
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)
|
@pyqtSlot(str)
|
||||||
def set_text(self, val):
|
def set_text(self, val):
|
||||||
|
@ -309,7 +309,7 @@ class WebView(QWebView):
|
|||||||
if perc < 0:
|
if perc < 0:
|
||||||
raise CommandError("Can't zoom {}%!".format(perc))
|
raise CommandError("Can't zoom {}%!".format(perc))
|
||||||
self.setZoomFactor(float(perc) / 100)
|
self.setZoomFactor(float(perc) / 100)
|
||||||
message.info("Zoom level: {}%".format(perc))
|
message.info("Zoom level: {}%".format(perc), immediate=True)
|
||||||
|
|
||||||
def zoom(self, offset):
|
def zoom(self, offset):
|
||||||
"""Increase/Decrease the zoom level.
|
"""Increase/Decrease the zoom level.
|
||||||
|
Loading…
Reference in New Issue
Block a user