From 064fbef41382c01fe8f8d02dfcfdbe9c0bc46fed Mon Sep 17 00:00:00 2001 From: penginsan <94757468+penginsan@users.noreply.github.com> Date: Mon, 6 Dec 2021 16:59:10 +0000 Subject: [PATCH] Add guiSelectedNotes action (#292) --- README.md | 21 +++++++++++++++++++++ plugin/__init__.py | 6 ++++++ tests/test_graphical.py | 3 +++ 3 files changed, 30 insertions(+) diff --git a/README.md b/README.md index 7a52ec9..b970205 100644 --- a/README.md +++ b/README.md @@ -1018,6 +1018,27 @@ corresponding to when the API was available for use. } ``` +* **guiSelectedNotes** + + Finds the open instance of the *Card Browser* dialog and returns an array of identifiers of the notes that are + selected. Returns an empty list if the browser is not open. + + *Sample request*: + ```json + { + "action": "guiSelectedNotes", + "version": 6 + } + ``` + + *Sample result*: + ```json + { + "result": [1494723142483, 1494703460437, 1494703479525], + "error": null + } + ``` + * **guiAddCards** Invokes the *Add Cards* dialog, presets the note using the given deck and model, with the provided field values and tags. diff --git a/plugin/__init__.py b/plugin/__init__.py index 864d3b3..682f297 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -1354,6 +1354,12 @@ class AnkiConnect: return self.findCards(query) + @util.api() + def guiSelectedNotes(self): + (creator, instance) = aqt.dialogs._dialogs['Browser'] + if instance is None: + return [] + return instance.selectedNotes() @util.api() def guiAddCards(self, note=None): diff --git a/tests/test_graphical.py b/tests/test_graphical.py index 033e920..d42f2ea 100755 --- a/tests/test_graphical.py +++ b/tests/test_graphical.py @@ -9,6 +9,9 @@ class TestGui(unittest.TestCase): # guiBrowse util.invoke('guiBrowse', query='deck:Default') + # guiSelectedNotes + util.invoke('guiSelectedNotes') + # guiAddCards util.invoke('guiAddCards')