Anki/qt/aqt/browser/card_info.py
RumovZ 3672b0fe73
Switch CardInfoDialog to ts page (#1414)
* Only collect card stats on the backend ...

... instead of rendering an HTML string using askama.

* Add ts page Card Info

* Update test for new `col.card_stats()`

* Remove obsolete CardStats code

* Use new ts page in `CardInfoDialog`

* Align start and end instead of left and right

Curiously, `text-align: start` does not work for `th` tags if assigned
via classes.

* Adopt ts refactorings after rebase

#1405 and #1409

* Clean up `ts/card-info/BUILD.bazel`

* Port card info logic from Rust to TS

* Move repeated field to the top

https://github.com/ankitects/anki/pull/1414#discussion_r725402730

* Convert pseudo classes to interfaces

* CardInfoPage -> CardInfo

* Make revlog in card info optional

* Add legacy support for old card stats

* Check for undefined instead of falsy

* Make Revlog separate component

* drop askama dependency (dae)

* Fix nightmode for legacy card stats
2021-10-14 19:22:47 +10:00

56 lines
1.6 KiB
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
import aqt
from anki.cards import Card, CardId
from aqt.qt import *
from aqt.utils import (
addCloseShortcut,
disable_help_button,
qconnect,
restoreGeom,
saveGeom,
)
from aqt.webview import AnkiWebView
class CardInfoDialog(QDialog):
TITLE = "browser card info"
GEOMETRY_KEY = "revlog"
silentlyClose = True
def __init__(self, parent: QWidget, mw: aqt.AnkiQt, card: Card) -> None:
super().__init__(parent)
self.mw = mw
self._setup_ui(card.id)
self.show()
def _setup_ui(self, card_id: CardId) -> None:
self.setWindowModality(Qt.ApplicationModal)
self.mw.garbage_collect_on_dialog_finish(self)
disable_help_button(self)
restoreGeom(self, self.GEOMETRY_KEY)
addCloseShortcut(self)
self.web = AnkiWebView(title=self.TITLE)
self.web.setVisible(False)
self.web.load_ts_page("card-info")
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.web)
buttons = QDialogButtonBox(QDialogButtonBox.Close)
buttons.setContentsMargins(10, 0, 10, 10)
layout.addWidget(buttons)
qconnect(buttons.rejected, self.reject)
self.setLayout(layout)
self.web.eval(
f"anki.cardInfo(document.getElementById('main'), {card_id}, true);"
)
def reject(self) -> None:
self.web = None
saveGeom(self, self.GEOMETRY_KEY)
return QDialog.reject(self)