anki/qt/aqt/legacy.py
Damien Elmes b9251290ca run pyupgrade over codebase [python upgrade required]
This adds Python 3.9 and 3.10 typing syntax to files that import
attributions from __future___. Python 3.9 should be able to cope with
the 3.10 syntax, but Python 3.8 will no longer work.

On Windows/Mac, install the latest Python 3.9 version from python.org.
There are currently no orjson wheels for Python 3.10 on Windows/Mac,
which will break the build unless you have Rust installed separately.

On Linux, modern distros should have Python 3.9 available already. If
you're on an older distro, you'll need to build Python from source first.
2021-10-04 15:05:48 +10:00

53 lines
1.3 KiB
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
"""
Legacy support
"""
from __future__ import annotations
from typing import Any
import anki
import aqt
from aqt.theme import theme_manager
# Routines removed from pylib/
##########################################################################
def bodyClass(col, card) -> str: # type: ignore
print("bodyClass() deprecated")
return theme_manager.body_classes_for_card_ord(card.ord)
def allSounds(text) -> list: # type: ignore
print("allSounds() deprecated")
return aqt.mw.col.media._extract_filenames(text)
def stripSounds(text) -> str: # type: ignore
print("stripSounds() deprecated")
return aqt.mw.col.media.strip_av_tags(text)
def fmtTimeSpan(
time: Any,
pad: Any = 0,
point: Any = 0,
short: Any = False,
inTime: Any = False,
unit: Any = 99,
) -> Any:
print("fmtTimeSpan() has become col.format_timespan()")
return aqt.mw.col.format_timespan(time)
def install_pylib_legacy() -> None:
anki.utils.bodyClass = bodyClass # type: ignore
anki.utils.fmtTimeSpan = fmtTimeSpan # type: ignore
anki.sound._soundReg = r"\[sound:(.+?)\]" # type: ignore
anki.sound.allSounds = allSounds # type: ignore
anki.sound.stripSounds = stripSounds # type: ignore