anki/qt/aqt/deckoptions.py

56 lines
1.7 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.lang import without_unicode_isolation
from aqt import gui_hooks
from aqt.qt import *
from aqt.utils import addCloseShortcut, disable_help_button, restoreGeom, saveGeom, tr
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("deckoptions")
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.web)
self.setLayout(layout)
deck = self.mw.col.decks.get_current()
self.web.eval(
f"""const $deckOptions = anki.deckOptions(
document.getElementById('main'), {deck.id});"""
)
self.setWindowTitle(
without_unicode_isolation(tr.actions_options_for(val=deck.name))
)
gui_hooks.deck_options_did_load(self)
def reject(self) -> None:
self.web = None
saveGeom(self, self.TITLE)
QDialog.reject(self)