inject legacy funcs referencing aqt in GUI load

This commit is contained in:
Damien Elmes 2020-01-23 18:19:54 +10:00
parent 7bb7d5391b
commit 406c58a109
4 changed files with 46 additions and 30 deletions

View file

@ -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)

View file

@ -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
##############################################################################

43
qt/aqt/legacy.py Normal file
View file

@ -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

View file

@ -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