hook new deck config screen up behind an env var

This commit is contained in:
Damien Elmes 2021-04-22 10:55:32 +10:00
parent e3a7d1a9e3
commit 30f5269304
9 changed files with 68 additions and 11 deletions

46
qt/aqt/deckoptions.py Normal file
View file

@ -0,0 +1,46 @@
# 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)

View file

@ -1171,6 +1171,11 @@ title="%s" %s>%s</button>""" % (
deck = self.col.decks.current()
if deck["dyn"]:
aqt.dialogs.open("FilteredDeckConfigDialog", self, deck_id=deck["id"])
else:
if os.getenv("NEW_DECKCONF"):
from aqt.deckoptions import DeckOptionsDialog
DeckOptionsDialog(self)
else:
aqt.deckconf.DeckConf(self, deck)

View file

@ -23,6 +23,7 @@ from anki import hooks
from anki.collection import GraphPreferences, OpChanges
from anki.decks import UpdateDeckConfigs
from anki.utils import devMode, from_json_bytes
from aqt.deckoptions import DeckOptionsDialog
from aqt.operations.deck import update_deck_configs
from aqt.qt import *
from aqt.utils import aqt_data_folder
@ -294,7 +295,8 @@ def update_deck_configs_request() -> bytes:
input.ParseFromString(request.data)
def on_success(changes: OpChanges) -> None:
print("done", changes)
if isinstance(window := aqt.mw.app.activeWindow(), DeckOptionsDialog):
window.reject()
def handle_on_main() -> None:
update_deck_configs(parent=aqt.mw, input=input).success(

View file

@ -1535,6 +1535,7 @@ message OpChanges {
bool tag = 4;
bool notetype = 5;
bool config = 6;
bool deck_config = 11;
bool browser_table = 7;
bool browser_sidebar = 8;

View file

@ -17,6 +17,7 @@ impl From<OpChanges> for pb::OpChanges {
tag: c.changes.tag,
notetype: c.changes.notetype,
config: c.changes.config,
deck_config: c.changes.deck_config,
browser_table: c.requires_browser_table_redraw(),
browser_sidebar: c.requires_browser_sidebar_redraw(),
editor: c.requires_editor_redraw(),

View file

@ -86,8 +86,6 @@ pub struct StateChanges {
pub notetype: bool,
pub config: bool,
pub deck_config: bool,
/// covers schema change (and last_sync in the future), but not mtime
pub collection: bool,
}
#[derive(Debug, Clone, Copy)]
@ -148,5 +146,6 @@ impl OpChanges {
c.card
|| (c.deck && self.op != Op::ExpandCollapse)
|| (c.config && matches!(self.op, Op::SetCurrentDeck))
|| c.deck_config
}
}

View file

@ -142,7 +142,7 @@ impl UndoManager {
UndoableChange::Queue(_) => {}
UndoableChange::Config(_) => changes.config = true,
UndoableChange::DeckConfig(_) => changes.deck_config = true,
UndoableChange::Collection(_) => changes.collection = true,
UndoableChange::Collection(_) => {}
}
}

View file

@ -17,10 +17,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
? `Daily limit will be capped to parent limit of ${$parentLimits.newCards}.`
: "";
$: reviewsGreaterThanParent =
$config.reviewsPerDay > $parentLimits.reviews
? `Daily limit will be capped to parent limit of ${$parentLimits.reviews}.`
: "";
// with the v2 scheduler, this no longer applies
// $: reviewsGreaterThanParent =
// $config.reviewsPerDay > $parentLimits.reviews
// ? `Daily limit will be capped to parent limit of ${$parentLimits.reviews}.`
// : "";
$: reviewsTooLow =
$config.newPerDay * 10 > $config.reviewsPerDay
@ -47,7 +48,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
label={tr.schedulingMaximumReviewsday()}
subLabel="The maximum number of reviews cards to show in a day."
min={0}
warnings={[reviewsTooLow, reviewsGreaterThanParent]}
warnings={[reviewsTooLow]}
defaultValue={defaults.reviewsPerDay}
bind:value={$config.reviewsPerDay} />
</div>

View file

@ -13,7 +13,9 @@
<div id="main"></div>
<script>
if (window.location.hash.startsWith("#test")) {
anki.deckConfig(document.getElementById("main"), 1);
}
</script>
</body>
</html>