split deck description into separate screen linked from overview

This commit is contained in:
Damien Elmes 2021-04-22 21:03:16 +10:00
parent 1ddfd73da6
commit f6a59ebdfa
5 changed files with 88 additions and 50 deletions

View File

@ -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)

76
qt/aqt/deckdescription.py Normal file
View File

@ -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)

View File

@ -643,48 +643,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>scheduling_description</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>12</number>
</property>
<property name="leftMargin">
<number>12</number>
</property>
<property name="topMargin">
<number>12</number>
</property>
<property name="rightMargin">
<number>12</number>
</property>
<property name="bottomMargin">
<number>12</number>
</property>
<item>
<widget class="QLabel" name="label_22">
<property name="text">
<string>scheduling_description_to_show_on_overview_screen</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enable_markdown">
<property name="toolTip">
<string>deck_config_description_markdown_hint</string>
</property>
<property name="text">
<string>deck_config_description_markdown</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="desc"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
@ -725,7 +683,6 @@
<tabstop>showTimer</tabstop>
<tabstop>autoplaySounds</tabstop>
<tabstop>replayQuestion</tabstop>
<tabstop>desc</tabstop>
</tabstops>
<resources>
<include location="icons.qrc"/>

View File

@ -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))

View File

@ -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:
</center>
"""
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]: