Don't lose warnings shown in early init phases
This commit is contained in:
parent
cd2c547b6b
commit
6004bfa72f
@ -437,6 +437,7 @@ class MainWindow(QWidget):
|
|||||||
# messages
|
# messages
|
||||||
message.global_bridge.show_message.connect(
|
message.global_bridge.show_message.connect(
|
||||||
self._messageview.show_message)
|
self._messageview.show_message)
|
||||||
|
message.global_bridge.flush()
|
||||||
|
|
||||||
message_bridge.s_set_text.connect(status.set_text)
|
message_bridge.s_set_text.connect(status.set_text)
|
||||||
message_bridge.s_maybe_reset_text.connect(status.txt.maybe_reset_text)
|
message_bridge.s_maybe_reset_text.connect(status.txt.maybe_reset_text)
|
||||||
|
@ -61,8 +61,7 @@ def error(message, *, stack=None, replace=False):
|
|||||||
typ = 'error (from exception)'
|
typ = 'error (from exception)'
|
||||||
_log_stack(typ, stack)
|
_log_stack(typ, stack)
|
||||||
log.message.error(message)
|
log.message.error(message)
|
||||||
global_bridge.show_message.emit(usertypes.MessageLevel.error, message,
|
global_bridge.show(usertypes.MessageLevel.error, message, replace)
|
||||||
replace)
|
|
||||||
|
|
||||||
|
|
||||||
def warning(message, *, replace=False):
|
def warning(message, *, replace=False):
|
||||||
@ -74,8 +73,7 @@ def warning(message, *, replace=False):
|
|||||||
"""
|
"""
|
||||||
_log_stack('warning', traceback.format_stack())
|
_log_stack('warning', traceback.format_stack())
|
||||||
log.message.warning(message)
|
log.message.warning(message)
|
||||||
global_bridge.show_message.emit(usertypes.MessageLevel.warning, message,
|
global_bridge.show(usertypes.MessageLevel.warning, message, replace)
|
||||||
replace)
|
|
||||||
|
|
||||||
|
|
||||||
def info(message, *, replace=False):
|
def info(message, *, replace=False):
|
||||||
@ -86,8 +84,7 @@ def info(message, *, replace=False):
|
|||||||
replace: Replace existing messages with replace=True
|
replace: Replace existing messages with replace=True
|
||||||
"""
|
"""
|
||||||
log.message.info(message)
|
log.message.info(message)
|
||||||
global_bridge.show_message.emit(usertypes.MessageLevel.info, message,
|
global_bridge.show(usertypes.MessageLevel.info, message, replace)
|
||||||
replace)
|
|
||||||
|
|
||||||
|
|
||||||
def _build_question(title, text=None, *, mode, default=None, abort_on=()):
|
def _build_question(title, text=None, *, mode, default=None, abort_on=()):
|
||||||
@ -173,6 +170,10 @@ class GlobalMessageBridge(QObject):
|
|||||||
|
|
||||||
"""Global (not per-window) message bridge for errors/infos/warnings.
|
"""Global (not per-window) message bridge for errors/infos/warnings.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
_connected: Whether a slot is connected and we can show messages.
|
||||||
|
_cache: Messages shown while we were not connected.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
show_message: Show a message
|
show_message: Show a message
|
||||||
arg 0: A MessageLevel member
|
arg 0: A MessageLevel member
|
||||||
@ -194,6 +195,11 @@ class GlobalMessageBridge(QObject):
|
|||||||
ask_question = pyqtSignal(usertypes.Question, bool)
|
ask_question = pyqtSignal(usertypes.Question, bool)
|
||||||
mode_left = pyqtSignal(usertypes.KeyMode)
|
mode_left = pyqtSignal(usertypes.KeyMode)
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self._connected = False
|
||||||
|
self._cache = []
|
||||||
|
|
||||||
def ask(self, question, blocking, *, log_stack=False):
|
def ask(self, question, blocking, *, log_stack=False):
|
||||||
"""Ask a question to the user.
|
"""Ask a question to the user.
|
||||||
|
|
||||||
@ -208,6 +214,23 @@ class GlobalMessageBridge(QObject):
|
|||||||
"""
|
"""
|
||||||
self.ask_question.emit(question, blocking)
|
self.ask_question.emit(question, blocking)
|
||||||
|
|
||||||
|
def show(self, level, text, replace=False):
|
||||||
|
if self._connected:
|
||||||
|
self.show_message.emit(level, text, replace)
|
||||||
|
else:
|
||||||
|
self._cache.append((level, text, replace))
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
"""Flush messages which accumulated while no handler was connected.
|
||||||
|
|
||||||
|
This is so we don't miss messages shown during some early init phase.
|
||||||
|
It needs to be called once the show_message signal is connected.
|
||||||
|
"""
|
||||||
|
self._connected = True
|
||||||
|
for args in self._cache:
|
||||||
|
self.show(*args)
|
||||||
|
self._cache = []
|
||||||
|
|
||||||
|
|
||||||
class MessageBridge(QObject):
|
class MessageBridge(QObject):
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ class MessageMock:
|
|||||||
def patch(self):
|
def patch(self):
|
||||||
"""Start recording messages."""
|
"""Start recording messages."""
|
||||||
message.global_bridge.show_message.connect(self._record_message)
|
message.global_bridge.show_message.connect(self._record_message)
|
||||||
|
message.global_bridge._connected = True
|
||||||
|
|
||||||
def unpatch(self):
|
def unpatch(self):
|
||||||
"""Stop recording messages."""
|
"""Stop recording messages."""
|
||||||
|
Loading…
Reference in New Issue
Block a user