mirror of
https://github.com/ankitects/anki.git
synced 2025-12-21 10:52:57 -05:00
fix: prevent <br> from appearing as text in error message (#4451)
* Update error text format to use RichText rather than PlainText * Set CardTypeError messages as rich text to allow HTML formatting * Use CardTypeError from anki.errors module
This commit is contained in:
parent
cb7a8dbc10
commit
4e8c992be1
1 changed files with 15 additions and 4 deletions
|
|
@ -14,7 +14,7 @@ from markdown import markdown
|
|||
|
||||
import aqt
|
||||
from anki.collection import HelpPage
|
||||
from anki.errors import BackendError, Interrupted
|
||||
from anki.errors import BackendError, CardTypeError, Interrupted
|
||||
from anki.utils import is_win
|
||||
from aqt.addons import AddonManager, AddonMeta
|
||||
from aqt.qt import *
|
||||
|
|
@ -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 isinstance(exception, 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.PlainText)
|
||||
_mbox.setTextFormat(text_format)
|
||||
|
||||
def show_help():
|
||||
openHelp(help_page)
|
||||
|
|
|
|||
Loading…
Reference in a new issue