From 713c8f619d0234ab10c0a8aa5d4486f73f737a71 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Thu, 25 Mar 2021 02:28:01 +0100 Subject: [PATCH 1/4] Add three filtered deck dialog hooks Similar to deckconf hooks --- qt/aqt/filtered_deck.py | 6 ++++++ qt/tools/genhooks_gui.py | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/qt/aqt/filtered_deck.py b/qt/aqt/filtered_deck.py index b7030cebf..15c9cc134 100644 --- a/qt/aqt/filtered_deck.py +++ b/qt/aqt/filtered_deck.py @@ -10,6 +10,7 @@ from anki.errors import SearchError from anki.lang import without_unicode_isolation from anki.scheduler import FilteredDeckForUpdate from aqt import AnkiQt, colors +from aqt import gui_hooks from aqt.qt import * from aqt.scheduling_ops import add_or_update_filtered_deck from aqt.theme import theme_manager @@ -156,6 +157,8 @@ class FilteredDeckConfigDialog(QDialog): without_unicode_isolation(tr(TR.ACTIONS_OPTIONS_FOR, val=self.deck.name)) ) + gui_hooks.filtered_deck_dialog_did_load_deck(self, deck) + def reopen( self, _mw: AnkiQt, @@ -300,10 +303,13 @@ class FilteredDeckConfigDialog(QDialog): return def success(out: OpChangesWithCount) -> None: + gui_hooks.filtered_deck_dialog_did_add_or_update_deck(self, self.deck) saveGeom(self, self.GEOMETRY_KEY) aqt.dialogs.markClosed(self.DIALOG_KEY) QDialog.accept(self) + gui_hooks.filtered_deck_dialog_will_add_or_update_deck(self, self.deck) + add_or_update_filtered_deck(mw=self.mw, deck=self.deck, success=success) # Step load/save diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index ac469d976..36d0ca47c 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -284,6 +284,32 @@ hooks = [ ], doc="Called before config group is renamed", ), + # Filtered deck options + ################### + Hook( + name="filtered_deck_dialog_did_load_deck", + args=[ + "filtered_deck_dialog: aqt.filtered_deck.FilteredDeckConfigDialog", + "filtered_deck: anki.scheduler.FilteredDeckForUpdate", + ], + doc="Allows updating widget state once the filtered deck config is loaded", + ), + Hook( + name="filtered_deck_dialog_will_add_or_update_deck", + args=[ + "filtered_deck_dialog: aqt.filtered_deck.FilteredDeckConfigDialog", + "filtered_deck: anki.scheduler.FilteredDeckForUpdate", + ], + doc="Allows modifying the filtered deck config object before it is written", + ), + Hook( + name="filtered_deck_dialog_did_add_or_update_deck", + args=[ + "filtered_deck_dialog: aqt.filtered_deck.FilteredDeckConfigDialog", + "filtered_deck: anki.scheduler.FilteredDeckForUpdate", + ], + doc="Allows performing changes after a filtered deck has been added or updated", + ), # Browser ################### Hook( From e9b18c14f229c3b4b3c97b544d7d62467484f6a2 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Thu, 25 Mar 2021 02:28:58 +0100 Subject: [PATCH 2/4] Fix (?) operation output type hint --- qt/aqt/filtered_deck.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qt/aqt/filtered_deck.py b/qt/aqt/filtered_deck.py index 15c9cc134..658fcfe87 100644 --- a/qt/aqt/filtered_deck.py +++ b/qt/aqt/filtered_deck.py @@ -4,7 +4,7 @@ from typing import List, Optional, Tuple import aqt -from anki.collection import OpChangesWithCount, SearchNode +from anki.collection import OpChangesWithID, SearchNode from anki.decks import DeckDict, DeckID, FilteredDeckConfig from anki.errors import SearchError from anki.lang import without_unicode_isolation @@ -302,7 +302,7 @@ class FilteredDeckConfigDialog(QDialog): if not self._update_deck(): return - def success(out: OpChangesWithCount) -> None: + def success(out: OpChangesWithID) -> None: gui_hooks.filtered_deck_dialog_did_add_or_update_deck(self, self.deck) saveGeom(self, self.GEOMETRY_KEY) aqt.dialogs.markClosed(self.DIALOG_KEY) From feaa32b751b2f929dd33ff86b93a7f76b36063e7 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Thu, 25 Mar 2021 02:33:15 +0100 Subject: [PATCH 3/4] Supply deck ID in hook, so that add-ons may update deck config dict (for newly created filtered decks where the deck ID is not yet set in the FilteredDeckForUpdate object) --- qt/aqt/filtered_deck.py | 4 +++- qt/tools/genhooks_gui.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/qt/aqt/filtered_deck.py b/qt/aqt/filtered_deck.py index 658fcfe87..d5d921b80 100644 --- a/qt/aqt/filtered_deck.py +++ b/qt/aqt/filtered_deck.py @@ -303,7 +303,9 @@ class FilteredDeckConfigDialog(QDialog): return def success(out: OpChangesWithID) -> None: - gui_hooks.filtered_deck_dialog_did_add_or_update_deck(self, self.deck) + gui_hooks.filtered_deck_dialog_did_add_or_update_deck( + self, self.deck, out.id + ) saveGeom(self, self.GEOMETRY_KEY) aqt.dialogs.markClosed(self.DIALOG_KEY) QDialog.accept(self) diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index 36d0ca47c..cd9b540df 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -307,6 +307,7 @@ hooks = [ args=[ "filtered_deck_dialog: aqt.filtered_deck.FilteredDeckConfigDialog", "filtered_deck: anki.scheduler.FilteredDeckForUpdate", + "deck_id: int", ], doc="Allows performing changes after a filtered deck has been added or updated", ), From 6a1c85d62e4d0c79d58ee8a1bc786f9f5916c116 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Thu, 25 Mar 2021 04:46:22 +0100 Subject: [PATCH 4/4] Run isort --- qt/aqt/filtered_deck.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/qt/aqt/filtered_deck.py b/qt/aqt/filtered_deck.py index d5d921b80..5e10b5a51 100644 --- a/qt/aqt/filtered_deck.py +++ b/qt/aqt/filtered_deck.py @@ -9,8 +9,7 @@ from anki.decks import DeckDict, DeckID, FilteredDeckConfig from anki.errors import SearchError from anki.lang import without_unicode_isolation from anki.scheduler import FilteredDeckForUpdate -from aqt import AnkiQt, colors -from aqt import gui_hooks +from aqt import AnkiQt, colors, gui_hooks from aqt.qt import * from aqt.scheduling_ops import add_or_update_filtered_deck from aqt.theme import theme_manager