From ae88f7e5935b352a1081baea8077fee666ef2bf1 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Tue, 23 Feb 2021 23:12:39 +0100 Subject: [PATCH] Add clickable hint to dyndeckconf --- ftl/core/decks.ftl | 1 + qt/aqt/dyndeckconf.py | 49 ++++++++++++++++++++++++++++++++++++++++ qt/aqt/forms/dyndconf.ui | 19 ++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/ftl/core/decks.ftl b/ftl/core/decks.ftl index 222a993c2..22175d3e7 100644 --- a/ftl/core/decks.ftl +++ b/ftl/core/decks.ftl @@ -31,6 +31,7 @@ decks-reschedule-cards-based-on-my-answers = Reschedule cards based on my answer decks-study = Study decks-study-deck = Study Deck decks-the-provided-search-did-not-match = The provided search did not match any cards. Would you like to revise it? +decks-unmovable-cards = Some cards may be excluded despite matching the search. decks-it-has-card = { $count -> [one] It has { $count } card. diff --git a/qt/aqt/dyndeckconf.py b/qt/aqt/dyndeckconf.py index c05d28337..f64f82bd0 100644 --- a/qt/aqt/dyndeckconf.py +++ b/qt/aqt/dyndeckconf.py @@ -70,6 +70,7 @@ class DeckConf(QDialog): self.set_custom_searches(search, search_2) qconnect(self.form.search_button.clicked, self.on_search_button) qconnect(self.form.search_button_2.clicked, self.on_search_button_2) + qconnect(self.form.hint_button.clicked, self.on_hint_button) color = theme_manager.color(colors.LINK) self.setStyleSheet( f"""QPushButton[flat=true] {{ text-align: left; color: {color}; padding: 0; border: 0 }} @@ -161,6 +162,54 @@ class DeckConf(QDialog): else: aqt.dialogs.open("Browser", self.mw, search=(search,)) + def on_hint_button(self) -> None: + """Open the browser to show cards that match the typed-in filters but cannot be included + due to internal limitations. + """ + manual_filters = [self.form.search.text()] + if self.form.secondFilter.isChecked(): + manual_filters.append(self.form.search_2.text()) + + implicit_filters = [ + SearchNode(card_state=SearchNode.CARD_STATE_SUSPENDED), + SearchNode(card_state=SearchNode.CARD_STATE_BURIED), + ] + + if self.col.schedVer() == 1: + # v1 scheduler cannot include learning cards + if self.did is None: + # rebuild will reset learning cards from this deck so they can be included + implicit_filters.append( + self.col.group_searches( + SearchNode(card_state=SearchNode.CARD_STATE_LEARN), + SearchNode(negated=SearchNode(deck=self.deck["name"])), + ) + ) + else: + implicit_filters.append( + SearchNode(card_state=SearchNode.CARD_STATE_LEARN) + ) + + if self.did is None: + # rebuild; old filtered deck will be emptied, so cards can be included + implicit_filters.append( + self.col.group_searches( + SearchNode(deck="filtered"), + SearchNode(negated=SearchNode(deck=self.deck["name"])), + ) + ) + else: + implicit_filters.append(SearchNode(deck="filtered")) + + manual_filter = self.col.group_searches(*manual_filters, joiner="OR") + implicit_filter = self.col.group_searches(*implicit_filters, joiner="OR") + try: + search = self.col.build_search_string(manual_filter, implicit_filter) + except InvalidInput as err: + show_invalid_search_error(err) + else: + aqt.dialogs.open("Browser", self.mw, search=(search,)) + def _onReschedToggled(self, _state: int) -> None: self.form.previewDelayWidget.setVisible( not self.form.resched.isChecked() and self.col.schedVer() > 1 diff --git a/qt/aqt/forms/dyndconf.ui b/qt/aqt/forms/dyndconf.ui index 6e9eaa441..be2925ce9 100644 --- a/qt/aqt/forms/dyndconf.ui +++ b/qt/aqt/forms/dyndconf.ui @@ -250,6 +250,25 @@ + + + + Qt::NoFocus + + + SEARCH_VIEW_IN_BROWSER + + + DECKS_UNMOVABLE_CARDS + + + false + + + true + + +