anki/qt/aqt/deckoptions.py
2021-04-22 10:59:16 +10:00

47 lines
1.4 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 aqt.qt import *
from aqt.utils import addCloseShortcut, disable_help_button, restoreGeom, saveGeom
from aqt.webview import AnkiWebView
class DeckOptionsDialog(QDialog):
"The new deck configuration screen."
TITLE = "deckOptions"
silentlyClose = True
def __init__(self, mw: aqt.main.AnkiQt) -> None:
QDialog.__init__(self, mw, Qt.Window)
self.mw = mw
self._setup_ui()
self.show()
def _setup_ui(self) -> None:
self.setWindowModality(Qt.ApplicationModal)
self.mw.garbage_collect_on_dialog_finish(self)
self.setMinimumWidth(400)
disable_help_button(self)
restoreGeom(self, self.TITLE)
addCloseShortcut(self)
self.web = AnkiWebView(title=self.TITLE)
self.web.setVisible(False)
self.web.load_ts_page("deckconfig")
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.web)
self.setLayout(layout)
deck_id = self.mw.col.decks.get_current_id()
self.web.eval(f"anki.deckConfig(document.getElementById('main'), {deck_id});")
def reject(self) -> None:
self.web = None
saveGeom(self, self.TITLE)
QDialog.reject(self)