From f6a59ebdfa242daeda67e955d764ba98b553b6fa Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 22 Apr 2021 21:03:16 +1000 Subject: [PATCH] split deck description into separate screen linked from overview --- qt/aqt/deckconf.py | 6 ---- qt/aqt/deckdescription.py | 76 +++++++++++++++++++++++++++++++++++++++ qt/aqt/forms/dconf.ui | 43 ---------------------- qt/aqt/operations/deck.py | 6 +++- qt/aqt/overview.py | 7 ++++ 5 files changed, 88 insertions(+), 50 deletions(-) create mode 100644 qt/aqt/deckdescription.py diff --git a/qt/aqt/deckconf.py b/qt/aqt/deckconf.py index 691c0798e..d8028737c 100644 --- a/qt/aqt/deckconf.py +++ b/qt/aqt/deckconf.py @@ -233,9 +233,6 @@ class DeckConf(QDialog): f.showTimer.setChecked(c.get("timer", 0)) f.autoplaySounds.setChecked(c["autoplay"]) f.replayQuestion.setChecked(c.get("replayq", True)) - # description - f.enable_markdown.setChecked(self.deck.get("md", False)) - f.desc.setPlainText(self.deck["desc"]) gui_hooks.deck_conf_did_load_config(self, self.deck, self.conf) def onRestore(self) -> None: @@ -318,9 +315,6 @@ class DeckConf(QDialog): c["timer"] = f.showTimer.isChecked() and 1 or 0 c["autoplay"] = f.autoplaySounds.isChecked() c["replayq"] = f.replayQuestion.isChecked() - # description - self.deck["md"] = f.enable_markdown.isChecked() - self.deck["desc"] = f.desc.toPlainText() gui_hooks.deck_conf_will_save_config(self, self.deck, self.conf) self.mw.col.decks.save(self.deck) self.mw.col.decks.save(self.conf) diff --git a/qt/aqt/deckdescription.py b/qt/aqt/deckdescription.py new file mode 100644 index 000000000..2209c3215 --- /dev/null +++ b/qt/aqt/deckdescription.py @@ -0,0 +1,76 @@ +# 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.decks import Deck +from aqt.operations.deck import update_deck +from aqt.qt import * +from aqt.utils import addCloseShortcut, disable_help_button, restoreGeom, saveGeom, tr + + +class DeckDescriptionDialog(QDialog): + + TITLE = "deckDescription" + silentlyClose = True + + def __init__(self, mw: aqt.main.AnkiQt) -> None: + QDialog.__init__(self, mw, Qt.Window) + self.mw = mw + + # set on success + self.deck: Deck + + mw.query_op(mw.col.decks.get_current, success=self._setup_and_show) + + def _setup_and_show(self, deck: Deck) -> None: + if deck.WhichOneof("kind") != "normal": + return + + self.deck = deck + self._setup_ui() + self.show() + + def _setup_ui(self) -> None: + self.setWindowTitle(tr.scheduling_description()) + 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) + + box = QVBoxLayout() + + label = QLabel(tr.scheduling_description_to_show_on_overview_screen()) + box.addWidget(label) + + self.enable_markdown = QCheckBox(tr.deck_config_description_markdown()) + self.enable_markdown.setToolTip(tr.deck_config_description_markdown_hint()) + self.enable_markdown.setChecked(self.deck.normal.markdown_description) + box.addWidget(self.enable_markdown) + + self.description = QPlainTextEdit() + self.description.setPlainText(self.deck.normal.description) + box.addWidget(self.description) + + button_box = QDialogButtonBox() + ok = button_box.addButton(QDialogButtonBox.Ok) + qconnect(ok.clicked, self.save_and_accept) + box.addWidget(button_box) + + self.setLayout(box) + self.show() + + def save_and_accept(self) -> None: + self.deck.normal.description = self.description.toPlainText() + self.deck.normal.markdown_description = self.enable_markdown.isChecked() + + update_deck(parent=self, deck=self.deck).success( + lambda _: self.accept() + ).run_in_background() + + def accept(self) -> None: + saveGeom(self, self.TITLE) + QDialog.accept(self) diff --git a/qt/aqt/forms/dconf.ui b/qt/aqt/forms/dconf.ui index 77f42104f..1fef52366 100644 --- a/qt/aqt/forms/dconf.ui +++ b/qt/aqt/forms/dconf.ui @@ -643,48 +643,6 @@ - - - scheduling_description - - - - 12 - - - 12 - - - 12 - - - 12 - - - 12 - - - - - scheduling_description_to_show_on_overview_screen - - - - - - - deck_config_description_markdown_hint - - - deck_config_description_markdown - - - - - - - - @@ -725,7 +683,6 @@ showTimer autoplaySounds replayQuestion - desc diff --git a/qt/aqt/operations/deck.py b/qt/aqt/operations/deck.py index 52e4aa148..867f3992a 100644 --- a/qt/aqt/operations/deck.py +++ b/qt/aqt/operations/deck.py @@ -6,7 +6,7 @@ from __future__ import annotations from typing import Optional, Sequence from anki.collection import OpChanges, OpChangesWithCount, OpChangesWithId -from anki.decks import DeckCollapseScope, DeckId, UpdateDeckConfigs +from anki.decks import Deck, DeckCollapseScope, DeckId, UpdateDeckConfigs from aqt import QWidget from aqt.operations import CollectionOp from aqt.utils import getOnlyText, tooltip, tr @@ -86,3 +86,7 @@ def update_deck_configs( *, parent: QWidget, input: UpdateDeckConfigs ) -> CollectionOp[OpChanges]: return CollectionOp(parent, lambda col: col.decks.update_deck_configs(input)) + + +def update_deck(*, parent: QWidget, deck: Deck) -> CollectionOp[OpChanges]: + return CollectionOp(parent, lambda col: col.update_deck(deck)) diff --git a/qt/aqt/overview.py b/qt/aqt/overview.py index bdb2078c4..e87a267a8 100644 --- a/qt/aqt/overview.py +++ b/qt/aqt/overview.py @@ -8,6 +8,7 @@ from typing import Any, Callable, Dict, List, Optional, Tuple import aqt from anki.collection import OpChanges from aqt import gui_hooks +from aqt.deckdescription import DeckDescriptionDialog from aqt.operations.scheduling import empty_filtered_deck, rebuild_filtered_deck from aqt.sound import av_player from aqt.toolbar import BottomBar @@ -102,6 +103,8 @@ class Overview: self.onStudyMore() elif url == "unbury": self.onUnbury() + elif url == "description": + self.edit_description() elif url.lower().startswith("http"): openLink(url) return False @@ -242,6 +245,9 @@ class Overview: """ + def edit_description(self) -> None: + DeckDescriptionDialog(self.mw) + # Bottom area ###################################################################### @@ -257,6 +263,7 @@ class Overview: # links.append(["F", "cram", _("Filter/Cram")]) if self.mw.col.sched.haveBuried(): links.append(["U", "unbury", tr.studying_unbury()]) + links.append(["", "description", tr.scheduling_description()]) buf = "" for b in links: if b[0]: