mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
Merge pull request #945 from RumovZ/dyndeck-search
Normalize dyndeck search and handle exception
This commit is contained in:
commit
0a0de2ce7b
3 changed files with 22 additions and 17 deletions
|
@ -10,8 +10,6 @@ from dataclasses import dataclass
|
|||
from operator import itemgetter
|
||||
from typing import List, Sequence, Tuple, cast
|
||||
|
||||
from markdown import markdown
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
from anki.cards import Card
|
||||
|
@ -64,6 +62,7 @@ from aqt.utils import (
|
|||
saveSplitter,
|
||||
saveState,
|
||||
shortcut,
|
||||
show_invalid_search_error,
|
||||
showInfo,
|
||||
showWarning,
|
||||
tooltip,
|
||||
|
@ -91,14 +90,6 @@ class SearchContext:
|
|||
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
|
||||
##########################################################################
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from typing import List, Optional
|
|||
|
||||
import aqt
|
||||
from anki.lang import without_unicode_isolation
|
||||
from anki.rsbackend import InvalidInput
|
||||
from aqt.qt import *
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
|
@ -13,6 +14,7 @@ from aqt.utils import (
|
|||
openHelp,
|
||||
restoreGeom,
|
||||
saveGeom,
|
||||
show_invalid_search_error,
|
||||
showWarning,
|
||||
tr,
|
||||
)
|
||||
|
@ -114,25 +116,27 @@ class DeckConf(QDialog):
|
|||
else:
|
||||
d["delays"] = None
|
||||
|
||||
terms = [[f.search.text(), f.limit.value(), f.order.currentIndex()]]
|
||||
search = self.mw.col.backend.normalize_search(f.search.text())
|
||||
terms = [[search, f.limit.value(), f.order.currentIndex()]]
|
||||
|
||||
if f.secondFilter.isChecked():
|
||||
terms.append(
|
||||
[f.search_2.text(), f.limit_2.value(), f.order_2.currentIndex()]
|
||||
)
|
||||
search_2 = self.mw.col.backend.normalize_search(f.search_2.text())
|
||||
terms.append([search_2, f.limit_2.value(), f.order_2.currentIndex()])
|
||||
|
||||
d["terms"] = terms
|
||||
d["previewDelay"] = f.previewDelay.value()
|
||||
|
||||
self.mw.col.decks.save(d)
|
||||
return True
|
||||
|
||||
def reject(self):
|
||||
self.ok = False
|
||||
QDialog.reject(self)
|
||||
|
||||
def accept(self):
|
||||
if not self.saveConf():
|
||||
try:
|
||||
self.saveConf()
|
||||
except InvalidInput as err:
|
||||
show_invalid_search_error(err)
|
||||
return
|
||||
if not self.mw.col.sched.rebuild_filtered_deck(self.deck["id"]):
|
||||
if askUser(tr(TR.DECKS_THE_PROVIDED_SEARCH_DID_NOT_MATCH)):
|
||||
|
|
|
@ -9,9 +9,11 @@ import subprocess
|
|||
import sys
|
||||
from typing import TYPE_CHECKING, Any, List, Optional, Union, cast
|
||||
|
||||
from markdown import markdown
|
||||
|
||||
import anki
|
||||
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 aqt.qt import *
|
||||
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)
|
||||
|
||||
|
||||
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(
|
||||
text,
|
||||
parent=False,
|
||||
|
|
Loading…
Reference in a new issue