From 9e6d963b1aa33be6ad1aa618359da8a650c7d0e7 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sat, 27 May 2017 14:14:40 +0200 Subject: [PATCH 1/4] Add API for controlling Anki's GUI --- AnkiConnect.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/AnkiConnect.py b/AnkiConnect.py index 274bc77..e000233 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -417,6 +417,22 @@ class AnkiBridge: return collection.decks.allNames() + def launchBrowser(self, query): + browser = aqt.dialogs.open("Browser", self.window()) + browser.activateWindow() + if query: + query = u'"{}"'.format(query) + browser.form.searchEdit.lineEdit().setText(query) + browser.onSearch() + return browser.model.cards + + + def launchAddCards(self): + addcards = aqt.dialogs.open("AddCards", self.window()) + addcards.activateWindow() + return 0 + + # # AnkiConnect # @@ -516,6 +532,13 @@ class AnkiConnect: return API_VERSION + def api_guiSearch(self, query): + return self.anki.launchBrowser(query) + + + def api_guiAdd(self): + return self.anki.launchAddCards() + # # Entry # From 36c9528153de2a1aac1112478cb2fc26b604ce73 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sun, 28 May 2017 22:21:20 +0200 Subject: [PATCH 2/4] Fix issues pointed out in the PR. More consistent API function names. --- AnkiConnect.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/AnkiConnect.py b/AnkiConnect.py index e000233..c6d03f1 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -417,20 +417,19 @@ class AnkiBridge: return collection.decks.allNames() - def launchBrowser(self, query): + def guiBrowse(self, query): browser = aqt.dialogs.open("Browser", self.window()) browser.activateWindow() if query: - query = u'"{}"'.format(query) + query = unicode('"{}"'.format(query)) browser.form.searchEdit.lineEdit().setText(query) browser.onSearch() return browser.model.cards - def launchAddCards(self): + def guiAddCards(self): addcards = aqt.dialogs.open("AddCards", self.window()) addcards.activateWindow() - return 0 # @@ -532,12 +531,12 @@ class AnkiConnect: return API_VERSION - def api_guiSearch(self, query): - return self.anki.launchBrowser(query) + def api_guiBrowse(self, query): + return self.anki.guiBrowse(query) - def api_guiAdd(self): - return self.anki.launchAddCards() + def api_guiAddCards(self): + return self.anki.guiAddCards() # # Entry From d7e58c519ae1ae7a53bb5adcb47122462feccbf9 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sun, 28 May 2017 22:22:21 +0200 Subject: [PATCH 3/4] Document guiBrowse() and guiAddCards() --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index a76bcfb..b43aa23 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,47 @@ rather than raw JSON. If you are writing raw requests be sure to send valid JSON ] ``` +* **guiBrowse** + + Invokes the card browser and searches for a given query. Returns an array of identifiers of the cards that were found. + + *Sample request*: + ``` + { + action: 'guiBrowse', + params: { + query: 'deck:current' + } + } + ``` + + *Sample response*: + ``` + [ + 1494723142483, + 1494703460437, + 1494703479525, + /* ... */ + ] + ``` + +* **guiAddCards** + + Invokes the AddCards dialog. + + *Sample request*: + ``` + { + action: 'guiAddCards', + params: {} + } + ``` + + *Sample response*: + ``` + None + ``` + * **upgrade** Displays a confirmation dialog box in Anki asking the user if they wish to upgrade AnkiConnect to the latest version From 94cad0c322d1aefc8bd66aa06bc5ac02e977fb5f Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sun, 28 May 2017 22:55:24 +0200 Subject: [PATCH 4/4] Fix parens typo and JSON response --- AnkiConnect.py | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AnkiConnect.py b/AnkiConnect.py index c6d03f1..f54a4ee 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -421,7 +421,7 @@ class AnkiBridge: browser = aqt.dialogs.open("Browser", self.window()) browser.activateWindow() if query: - query = unicode('"{}"'.format(query)) + query = unicode('"{}"').format(query) browser.form.searchEdit.lineEdit().setText(query) browser.onSearch() return browser.model.cards diff --git a/README.md b/README.md index b43aa23..fb0fb62 100644 --- a/README.md +++ b/README.md @@ -330,7 +330,7 @@ rather than raw JSON. If you are writing raw requests be sure to send valid JSON *Sample response*: ``` - None + null ``` * **upgrade**