2021-05-08 07:08:45 +02:00
|
|
|
# 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
|
2021-10-14 11:22:47 +02:00
|
|
|
from anki.cards import Card, CardId
|
2021-05-08 07:08:45 +02:00
|
|
|
from aqt.qt import *
|
2021-10-14 11:22:47 +02:00
|
|
|
from aqt.utils import (
|
|
|
|
addCloseShortcut,
|
|
|
|
disable_help_button,
|
|
|
|
qconnect,
|
|
|
|
restoreGeom,
|
|
|
|
saveGeom,
|
|
|
|
)
|
2021-05-08 07:08:45 +02:00
|
|
|
from aqt.webview import AnkiWebView
|
|
|
|
|
|
|
|
|
|
|
|
class CardInfoDialog(QDialog):
|
2021-10-14 11:22:47 +02:00
|
|
|
TITLE = "browser card info"
|
|
|
|
GEOMETRY_KEY = "revlog"
|
2021-05-08 07:08:45 +02:00
|
|
|
silentlyClose = True
|
|
|
|
|
|
|
|
def __init__(self, parent: QWidget, mw: aqt.AnkiQt, card: Card) -> None:
|
|
|
|
super().__init__(parent)
|
2021-10-14 11:22:47 +02:00
|
|
|
self.mw = mw
|
|
|
|
self._setup_ui(card.id)
|
2021-05-08 07:08:45 +02:00
|
|
|
self.show()
|
|
|
|
|
2021-10-14 11:22:47 +02:00
|
|
|
def _setup_ui(self, card_id: CardId) -> None:
|
2021-10-05 05:53:01 +02:00
|
|
|
self.setWindowModality(Qt.WindowModality.ApplicationModal)
|
2021-10-14 11:22:47 +02:00
|
|
|
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)
|
2021-10-05 05:53:01 +02:00
|
|
|
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
|
2021-10-14 11:22:47 +02:00
|
|
|
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);"
|
|
|
|
)
|
|
|
|
|
2021-05-08 07:08:45 +02:00
|
|
|
def reject(self) -> None:
|
2021-10-14 11:22:47 +02:00
|
|
|
self.web = None
|
|
|
|
saveGeom(self, self.GEOMETRY_KEY)
|
2021-05-08 07:08:45 +02:00
|
|
|
return QDialog.reject(self)
|