From 6d1dcbb99a4d02945a3d9a82b5ecb15af4f0dac6 Mon Sep 17 00:00:00 2001 From: leedoughty <32392044+leedoughty@users.noreply.github.com> Date: Tue, 2 Dec 2025 18:04:22 +0000 Subject: [PATCH] Set CardTypeError messages as rich text to allow HTML formatting --- qt/aqt/errors.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/qt/aqt/errors.py b/qt/aqt/errors.py index 76ed1109c..a12d2950c 100644 --- a/qt/aqt/errors.py +++ b/qt/aqt/errors.py @@ -36,6 +36,14 @@ def show_exception(*, parent: QWidget, exception: Exception) -> None: global _mbox error_lines = [] help_page = HelpPage.TROUBLESHOOTING + + # default to PlainText + text_format = Qt.TextFormat.PlainText + + # set CardTypeError messages as rich text to allow HTML formatting + if type(exception).__name__ == "CardTypeError": + text_format = Qt.TextFormat.RichText + if isinstance(exception, BackendError): if exception.context: error_lines.append(exception.context) @@ -51,7 +59,7 @@ def show_exception(*, parent: QWidget, exception: Exception) -> None: ) error_text = "\n".join(error_lines) print(error_lines) - _mbox = _init_message_box(str(exception), error_text, help_page) + _mbox = _init_message_box(str(exception), error_text, help_page, text_format) _mbox.show() @@ -171,7 +179,10 @@ if not os.environ.get("DEBUG"): def _init_message_box( - user_text: str, debug_text: str, help_page=HelpPage.TROUBLESHOOTING + user_text: str, + debug_text: str, + help_page=HelpPage.TROUBLESHOOTING, + text_format=Qt.TextFormat.PlainText, ): global _mbox @@ -179,7 +190,7 @@ def _init_message_box( _mbox.setWindowTitle("Anki") _mbox.setText(user_text) _mbox.setIcon(QMessageBox.Icon.Warning) - _mbox.setTextFormat(Qt.TextFormat.RichText) + _mbox.setTextFormat(text_format) def show_help(): openHelp(help_page)