Move show_invalid_search_error to utils

This commit is contained in:
RumovZ 2021-01-25 23:19:19 +01:00
parent 31a3add848
commit 060fdc824b
2 changed files with 12 additions and 11 deletions

View File

@ -10,8 +10,6 @@ from dataclasses import dataclass
from operator import itemgetter from operator import itemgetter
from typing import List, Sequence, Tuple, cast from typing import List, Sequence, Tuple, cast
from markdown import markdown
import aqt import aqt
import aqt.forms import aqt.forms
from anki.cards import Card from anki.cards import Card
@ -64,6 +62,7 @@ from aqt.utils import (
saveSplitter, saveSplitter,
saveState, saveState,
shortcut, shortcut,
show_invalid_search_error,
showInfo, showInfo,
showWarning, showWarning,
tooltip, tooltip,
@ -91,14 +90,6 @@ class SearchContext:
card_ids: Optional[Sequence[int]] = None card_ids: Optional[Sequence[int]] = None
def show_invalid_search_error(err: Exception):
"Render search errors in markdown, then display a warning."
text = str(err)
if isinstance(err, InvalidInput):
text = markdown(text)
showWarning(text)
# Data model # Data model
########################################################################## ##########################################################################

View File

@ -9,9 +9,11 @@ import subprocess
import sys import sys
from typing import TYPE_CHECKING, Any, List, Optional, Union, cast from typing import TYPE_CHECKING, Any, List, Optional, Union, cast
from markdown import markdown
import anki import anki
import aqt import aqt
from anki.rsbackend import TR # pylint: disable=unused-import from anki.rsbackend import TR, InvalidInput # pylint: disable=unused-import
from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
from aqt.qt import * from aqt.qt import *
from aqt.theme import theme_manager from aqt.theme import theme_manager
@ -67,6 +69,14 @@ def showCritical(text, parent=None, help="", title="Anki", textFormat=None):
return showInfo(text, parent, help, "critical", title=title, textFormat=textFormat) return showInfo(text, parent, help, "critical", title=title, textFormat=textFormat)
def show_invalid_search_error(err: Exception):
"Render search errors in markdown, then display a warning."
text = str(err)
if isinstance(err, InvalidInput):
text = markdown(text)
showWarning(text)
def showInfo( def showInfo(
text, text,
parent=False, parent=False,