mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
hook new deck config screen up behind an env var
This commit is contained in:
parent
e3a7d1a9e3
commit
30f5269304
9 changed files with 68 additions and 11 deletions
46
qt/aqt/deckoptions.py
Normal file
46
qt/aqt/deckoptions.py
Normal 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)
|
|
@ -1171,6 +1171,11 @@ title="%s" %s>%s</button>""" % (
|
||||||
deck = self.col.decks.current()
|
deck = self.col.decks.current()
|
||||||
if deck["dyn"]:
|
if deck["dyn"]:
|
||||||
aqt.dialogs.open("FilteredDeckConfigDialog", self, deck_id=deck["id"])
|
aqt.dialogs.open("FilteredDeckConfigDialog", self, deck_id=deck["id"])
|
||||||
|
else:
|
||||||
|
if os.getenv("NEW_DECKCONF"):
|
||||||
|
from aqt.deckoptions import DeckOptionsDialog
|
||||||
|
|
||||||
|
DeckOptionsDialog(self)
|
||||||
else:
|
else:
|
||||||
aqt.deckconf.DeckConf(self, deck)
|
aqt.deckconf.DeckConf(self, deck)
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ from anki import hooks
|
||||||
from anki.collection import GraphPreferences, OpChanges
|
from anki.collection import GraphPreferences, OpChanges
|
||||||
from anki.decks import UpdateDeckConfigs
|
from anki.decks import UpdateDeckConfigs
|
||||||
from anki.utils import devMode, from_json_bytes
|
from anki.utils import devMode, from_json_bytes
|
||||||
|
from aqt.deckoptions import DeckOptionsDialog
|
||||||
from aqt.operations.deck import update_deck_configs
|
from aqt.operations.deck import update_deck_configs
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import aqt_data_folder
|
from aqt.utils import aqt_data_folder
|
||||||
|
@ -294,7 +295,8 @@ def update_deck_configs_request() -> bytes:
|
||||||
input.ParseFromString(request.data)
|
input.ParseFromString(request.data)
|
||||||
|
|
||||||
def on_success(changes: OpChanges) -> None:
|
def on_success(changes: OpChanges) -> None:
|
||||||
print("done", changes)
|
if isinstance(window := aqt.mw.app.activeWindow(), DeckOptionsDialog):
|
||||||
|
window.reject()
|
||||||
|
|
||||||
def handle_on_main() -> None:
|
def handle_on_main() -> None:
|
||||||
update_deck_configs(parent=aqt.mw, input=input).success(
|
update_deck_configs(parent=aqt.mw, input=input).success(
|
||||||
|
|
|
@ -1535,6 +1535,7 @@ message OpChanges {
|
||||||
bool tag = 4;
|
bool tag = 4;
|
||||||
bool notetype = 5;
|
bool notetype = 5;
|
||||||
bool config = 6;
|
bool config = 6;
|
||||||
|
bool deck_config = 11;
|
||||||
|
|
||||||
bool browser_table = 7;
|
bool browser_table = 7;
|
||||||
bool browser_sidebar = 8;
|
bool browser_sidebar = 8;
|
||||||
|
|
|
@ -17,6 +17,7 @@ impl From<OpChanges> for pb::OpChanges {
|
||||||
tag: c.changes.tag,
|
tag: c.changes.tag,
|
||||||
notetype: c.changes.notetype,
|
notetype: c.changes.notetype,
|
||||||
config: c.changes.config,
|
config: c.changes.config,
|
||||||
|
deck_config: c.changes.deck_config,
|
||||||
browser_table: c.requires_browser_table_redraw(),
|
browser_table: c.requires_browser_table_redraw(),
|
||||||
browser_sidebar: c.requires_browser_sidebar_redraw(),
|
browser_sidebar: c.requires_browser_sidebar_redraw(),
|
||||||
editor: c.requires_editor_redraw(),
|
editor: c.requires_editor_redraw(),
|
||||||
|
|
|
@ -86,8 +86,6 @@ pub struct StateChanges {
|
||||||
pub notetype: bool,
|
pub notetype: bool,
|
||||||
pub config: bool,
|
pub config: bool,
|
||||||
pub deck_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)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
@ -148,5 +146,6 @@ impl OpChanges {
|
||||||
c.card
|
c.card
|
||||||
|| (c.deck && self.op != Op::ExpandCollapse)
|
|| (c.deck && self.op != Op::ExpandCollapse)
|
||||||
|| (c.config && matches!(self.op, Op::SetCurrentDeck))
|
|| (c.config && matches!(self.op, Op::SetCurrentDeck))
|
||||||
|
|| c.deck_config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ impl UndoManager {
|
||||||
UndoableChange::Queue(_) => {}
|
UndoableChange::Queue(_) => {}
|
||||||
UndoableChange::Config(_) => changes.config = true,
|
UndoableChange::Config(_) => changes.config = true,
|
||||||
UndoableChange::DeckConfig(_) => changes.deck_config = true,
|
UndoableChange::DeckConfig(_) => changes.deck_config = true,
|
||||||
UndoableChange::Collection(_) => changes.collection = true,
|
UndoableChange::Collection(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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}.`
|
? `Daily limit will be capped to parent limit of ${$parentLimits.newCards}.`
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
$: reviewsGreaterThanParent =
|
// with the v2 scheduler, this no longer applies
|
||||||
$config.reviewsPerDay > $parentLimits.reviews
|
// $: reviewsGreaterThanParent =
|
||||||
? `Daily limit will be capped to parent limit of ${$parentLimits.reviews}.`
|
// $config.reviewsPerDay > $parentLimits.reviews
|
||||||
: "";
|
// ? `Daily limit will be capped to parent limit of ${$parentLimits.reviews}.`
|
||||||
|
// : "";
|
||||||
|
|
||||||
$: reviewsTooLow =
|
$: reviewsTooLow =
|
||||||
$config.newPerDay * 10 > $config.reviewsPerDay
|
$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()}
|
label={tr.schedulingMaximumReviewsday()}
|
||||||
subLabel="The maximum number of reviews cards to show in a day."
|
subLabel="The maximum number of reviews cards to show in a day."
|
||||||
min={0}
|
min={0}
|
||||||
warnings={[reviewsTooLow, reviewsGreaterThanParent]}
|
warnings={[reviewsTooLow]}
|
||||||
defaultValue={defaults.reviewsPerDay}
|
defaultValue={defaults.reviewsPerDay}
|
||||||
bind:value={$config.reviewsPerDay} />
|
bind:value={$config.reviewsPerDay} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
<div id="main"></div>
|
<div id="main"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
if (window.location.hash.startsWith("#test")) {
|
||||||
anki.deckConfig(document.getElementById("main"), 1);
|
anki.deckConfig(document.getElementById("main"), 1);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue