From eb0e2a62d33df0b518d9204a27b09e97966ce82a Mon Sep 17 00:00:00 2001 From: RumovZ Date: Fri, 8 Jul 2022 23:16:17 +0200 Subject: [PATCH] Add DeckLimitsDialog --- ftl/core/decks.ftl | 1 + qt/aqt/deck_limits.py | 51 ++++++++++++ qt/aqt/deckbrowser.py | 10 ++- qt/aqt/forms/__init__.py | 89 ++++++++++---------- qt/aqt/forms/deck_limits.py | 6 ++ qt/aqt/forms/deck_limits.ui | 141 ++++++++++++++++++++++++++++++++ qt/aqt/forms/deck_limits_qt6.py | 1 + 7 files changed, 255 insertions(+), 44 deletions(-) create mode 100644 qt/aqt/deck_limits.py create mode 100644 qt/aqt/forms/deck_limits.py create mode 100644 qt/aqt/forms/deck_limits.ui create mode 100644 qt/aqt/forms/deck_limits_qt6.py diff --git a/ftl/core/decks.ftl b/ftl/core/decks.ftl index 56ff0a783..24d64262f 100644 --- a/ftl/core/decks.ftl +++ b/ftl/core/decks.ftl @@ -30,3 +30,4 @@ decks-study = Study decks-study-deck = Study Deck decks-filtered-deck-search-empty = No cards matched the provided search. Some cards may have been excluded because they are in a different filtered deck, or suspended. decks-unmovable-cards = Show any excluded cards +decks-override-preset-limits = Override preset limits diff --git a/qt/aqt/deck_limits.py b/qt/aqt/deck_limits.py new file mode 100644 index 000000000..8adcbc3e2 --- /dev/null +++ b/qt/aqt/deck_limits.py @@ -0,0 +1,51 @@ +# 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.forms +import aqt.main +from anki.decks import DeckDict +from aqt.operations.deck import update_deck_dict +from aqt.qt import * +from aqt.utils import disable_help_button + + +class DeckLimitsDialog(QDialog): + def __init__(self, mw: aqt.main.AnkiQt, deck: DeckDict): + super().__init__(parent=mw) + self.mw = mw + self.col = mw.col + self.deck = deck + self.frm = aqt.forms.deck_limits.Ui_Dialog() + self.frm.setupUi(self) + disable_help_button(self) + self._setup() + self.open() + + def _setup(self) -> None: + review_limit = self.deck["reviewLimit"] + new_limit = self.deck["newLimit"] + self.frm.review_limit.setValue(review_limit or 0) + self.frm.new_limit.setValue(new_limit or 0) + + enabled = None not in (review_limit, new_limit) + self.frm.enable_override.setChecked(enabled) + self.frm.review_limit.setEnabled(enabled) + self.frm.new_limit.setEnabled(enabled) + + qconnect(self.frm.enable_override.toggled, self._on_override_toggled) + + def _on_override_toggled(self) -> None: + enabled = self.frm.enable_override.isChecked() + self.frm.review_limit.setEnabled(enabled) + self.frm.new_limit.setEnabled(enabled) + + def accept(self) -> None: + if self.frm.enable_override.isChecked(): + self.deck["reviewLimit"] = self.frm.review_limit.value() + self.deck["newLimit"] = self.frm.new_limit.value() + else: + self.deck["reviewLimit"] = self.deck["newLimit"] = None + update_deck_dict(parent=self.mw, deck=self.deck).run_in_background() + super().accept() diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py index 752f88ba2..3e43692dd 100644 --- a/qt/aqt/deckbrowser.py +++ b/qt/aqt/deckbrowser.py @@ -10,8 +10,9 @@ from typing import Any import aqt import aqt.operations from anki.collection import OpChanges -from anki.decks import DeckCollapseScope, DeckId, DeckTreeNode +from anki.decks import DeckCollapseScope, DeckDict, DeckId, DeckTreeNode from aqt import AnkiQt, gui_hooks +from aqt.deck_limits import DeckLimitsDialog from aqt.deckoptions import display_options_for_deck_id from aqt.operations import QueryOp from aqt.operations.deck import ( @@ -264,11 +265,15 @@ class DeckBrowser: ########################################################################## def _showOptions(self, did: str) -> None: + deck = self.mw.col.decks.get(did) m = QMenu(self.mw) a = m.addAction(tr.actions_rename()) qconnect(a.triggered, lambda b, did=did: self._rename(DeckId(int(did)))) a = m.addAction(tr.actions_options()) qconnect(a.triggered, lambda b, did=did: self._options(DeckId(int(did)))) + if not deck["dyn"]: + a = m.addAction(tr.deck_config_daily_limits()) + qconnect(a.triggered, lambda _: self._limits(deck)) a = m.addAction(tr.actions_export()) qconnect(a.triggered, lambda b, did=did: self._export(DeckId(int(did)))) a = m.addAction(tr.actions_delete()) @@ -296,6 +301,9 @@ class DeckBrowser: def _options(self, did: DeckId) -> None: display_options_for_deck_id(did) + def _limits(self, deck: DeckDict) -> None: + DeckLimitsDialog(self.mw, deck) + def _collapse(self, did: DeckId) -> None: node = self.mw.col.decks.find_deck_in_tree(self._dueTree, did) if node: diff --git a/qt/aqt/forms/__init__.py b/qt/aqt/forms/__init__.py index d304d6956..597d0623f 100644 --- a/qt/aqt/forms/__init__.py +++ b/qt/aqt/forms/__init__.py @@ -1,43 +1,46 @@ -from . import about -from . import addcards -from . import addfield -from . import addmodel -from . import addonconf -from . import addons -from . import browser -from . import browserdisp -from . import browseropts -from . import changemap -from . import changemodel -from . import clayout_top -from . import customstudy -from . import dconf -from . import debug -from . import filtered_deck -from . import forget -from . import editaddon -from . import editcurrent -from . import edithtml -from . import emptycards -from . import exporting -from . import fields -from . import fields_web -from . import finddupes -from . import findreplace -from . import getaddons -from . import importing -from . import main -from . import modelopts -from . import models -from . import preferences -from . import preview -from . import profiles -from . import progress -from . import reposition -from . import setgroup -from . import setlang -from . import stats -from . import studydeck -from . import synclog -from . import taglimit -from . import template +from . import ( + about, + addcards, + addfield, + addmodel, + addonconf, + addons, + browser, + browserdisp, + browseropts, + changemap, + changemodel, + clayout_top, + customstudy, + dconf, + debug, + deck_limits, + editaddon, + editcurrent, + edithtml, + emptycards, + exporting, + fields, + fields_web, + filtered_deck, + finddupes, + findreplace, + forget, + getaddons, + importing, + main, + modelopts, + models, + preferences, + preview, + profiles, + progress, + reposition, + setgroup, + setlang, + stats, + studydeck, + synclog, + taglimit, + template, +) diff --git a/qt/aqt/forms/deck_limits.py b/qt/aqt/forms/deck_limits.py new file mode 100644 index 000000000..4a3f7879a --- /dev/null +++ b/qt/aqt/forms/deck_limits.py @@ -0,0 +1,6 @@ +from aqt.qt import qtmajor + +if qtmajor > 5: + from .deck_limits_qt6 import * +else: + from .deck_limits_qt5 import * # type: ignore diff --git a/qt/aqt/forms/deck_limits.ui b/qt/aqt/forms/deck_limits.ui new file mode 100644 index 000000000..890a85402 --- /dev/null +++ b/qt/aqt/forms/deck_limits.ui @@ -0,0 +1,141 @@ + + + Dialog + + + + 0 + 0 + 273 + 134 + + + + Anki + + + + + + decks_override_preset_limits + + + + + + + + + scheduling_maximum_reviewsday + + + + + + + + 0 + 0 + + + + 9999 + + + + + + + + + + + scheduling_new_cardsday + + + + + + + + 0 + 0 + + + + true + + + 0 + + + 9999 + + + 0 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/qt/aqt/forms/deck_limits_qt6.py b/qt/aqt/forms/deck_limits_qt6.py new file mode 100644 index 000000000..5912fd46f --- /dev/null +++ b/qt/aqt/forms/deck_limits_qt6.py @@ -0,0 +1 @@ +../../../.bazel/bin/qt/aqt/forms/deck_limits_qt6.py \ No newline at end of file