diff --git a/pylib/anki/sound.py b/pylib/anki/sound.py index 54f93a080..fad5b6789 100644 --- a/pylib/anki/sound.py +++ b/pylib/anki/sound.py @@ -40,25 +40,3 @@ class SoundOrVideoTag: # note this does not include image tags, which are handled with HTML. AVTag = Union[SoundOrVideoTag, TTSTag] - -# Legacy utils -########################################################################## -# these will be removed in the future - -_soundReg = r"\[sound:(.*?)\]" - - -def allSounds(text) -> List: - from aqt import mw # type: ignore # pylint: disable=import-error - - return [ - x.filename - for x in mw.col.backend.get_av_tags(text) - if isinstance(x, SoundOrVideoTag) - ] - - -def stripSounds(text) -> str: - from aqt import mw # type: ignore # pylint: disable=import-error - - return mw.col.backend.strip_av_tags(text) diff --git a/pylib/anki/utils.py b/pylib/anki/utils.py index 054a40919..2fdcac15c 100644 --- a/pylib/anki/utils.py +++ b/pylib/anki/utils.py @@ -226,14 +226,6 @@ def entsToTxt(html: str) -> str: return reEnts.sub(fixup, html) -# legacy function -def bodyClass(col, card) -> str: - from aqt.theme import theme_manager # type: ignore # pylint: disable=import-error - - print("bodyClass() deprecated") - return theme_manager.body_classes_for_card_ord(card.ord) - - # IDs ############################################################################## diff --git a/qt/aqt/legacy.py b/qt/aqt/legacy.py new file mode 100644 index 000000000..50cb959ce --- /dev/null +++ b/qt/aqt/legacy.py @@ -0,0 +1,43 @@ +# Copyright: Ankitects Pty Ltd and contributors +# -*- coding: utf-8 -*- +# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +""" +Legacy support +""" + +from typing import List + +import anki +import aqt +from anki.sound import SoundOrVideoTag +from aqt.theme import theme_manager + +# Routines removed from pylib/ +########################################################################## + + +def bodyClass(col, card) -> str: + print("bodyClass() deprecated") + return theme_manager.body_classes_for_card_ord(card.ord) + + +def allSounds(text) -> List: + print("allSounds() deprecated") + return [ + x.filename + for x in aqt.mw.col.backend.get_av_tags(text) + if isinstance(x, SoundOrVideoTag) + ] + + +def stripSounds(text) -> str: + print("stripSounds() deprecated") + return aqt.mw.col.backend.strip_av_tags(text) + + +def install_pylib_legacy(): + anki.utils.bodyClass = bodyClass + anki.sound._soundReg = r"\[sound:(.*?)\]" + anki.sound.allSounds = allSounds + anki.sound.stripSounds = stripSounds diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 27e1c0255..650ed215d 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -32,6 +32,7 @@ from anki.storage import Collection from anki.utils import devMode, ids2str, intTime, isMac, isWin, splitFields from aqt import gui_hooks from aqt.addons import DownloadLogEntry, check_and_prompt_for_updates, show_log_to_user +from aqt.legacy import install_pylib_legacy from aqt.profiles import ProfileManager as ProfileManagerType from aqt.qt import * from aqt.qt import sip @@ -53,6 +54,8 @@ from aqt.utils import ( tooltip, ) +install_pylib_legacy() + class AnkiQt(QMainWindow): col: _Collection