mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
inject legacy funcs referencing aqt in GUI load
This commit is contained in:
parent
7bb7d5391b
commit
406c58a109
4 changed files with 46 additions and 30 deletions
|
@ -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)
|
||||
|
|
|
@ -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
43
qt/aqt/legacy.py
Normal 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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue