From 591be310ba68d6b1eee48e0f3af70a467b94aabe Mon Sep 17 00:00:00 2001 From: Liquid369 Date: Sat, 26 Oct 2024 09:22:36 -0500 Subject: [PATCH] Adjust QMessageBox type hinting --- src/misc.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/misc.py b/src/misc.py index 4d62ddf..4a8a93b 100644 --- a/src/misc.py +++ b/src/misc.py @@ -26,7 +26,7 @@ def add_defaultKeys_to_dict(dictObj: Dict[str, Any], defaultObj: Dict[str, Any]) dictObj[key] = defaultObj[key] -QT_MESSAGE_TYPE: Dict[str, Type[QMessageBox.Icon]] = { +QT_MESSAGE_TYPE: Dict[str, QMessageBox.Icon] = { "info": QMessageBox.Information, "warn": QMessageBox.Warning, "crit": QMessageBox.Critical, @@ -258,7 +258,8 @@ def readCacheSettings() -> Dict[str, Any]: def redirect_print(what: str) -> None: - with redirect_stdout(WriteStream(wqueue)): + wrapped_stream = WrapperWriteStream(WriteStream(wqueue)) + with redirect_stdout(wrapped_stream): print(what) @@ -316,6 +317,17 @@ def flush(self) -> None: pass +class WrapperWriteStream: + def __init__(self, write_stream: WriteStream): + self.write_stream = write_stream + + def write(self, message: str) -> None: + self.write_stream.write(message) + + def flush(self) -> None: + self.write_stream.flush() + + # QObject (to be run in QThread) that blocks until data is available # and then emits a QtSignal to the main thread. class WriteStreamReceiver(QObject):