~foosoft/anki-connect

d33a5af837a9d864705f6a36e78de18905720b2a — Alex Yatskov 7 years ago 6b5d50b + 94cad0c
Merge pull request #8 from glutanimate/gui-controls

Add API for controlling Anki's GUI
2 files changed, 63 insertions(+), 0 deletions(-)

M AnkiConnect.py
M README.md
M AnkiConnect.py => AnkiConnect.py +22 -0
@@ 417,6 417,21 @@ class AnkiBridge:
            return collection.decks.allNames()


    def guiBrowse(self, query):
        browser = aqt.dialogs.open("Browser", self.window())
        browser.activateWindow()
        if query:
            query = unicode('"{}"').format(query)
            browser.form.searchEdit.lineEdit().setText(query)
            browser.onSearch()
        return browser.model.cards


    def guiAddCards(self):
        addcards = aqt.dialogs.open("AddCards", self.window())
        addcards.activateWindow()


#
# AnkiConnect
#


@@ 516,6 531,13 @@ class AnkiConnect:
        return API_VERSION


    def api_guiBrowse(self, query):
        return self.anki.guiBrowse(query)


    def api_guiAddCards(self):
        return self.anki.guiAddCards()

#
#   Entry
#

M README.md => README.md +41 -0
@@ 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*:
    ```
    null
    ```

*   **upgrade**

    Displays a confirmation dialog box in Anki asking the user if they wish to upgrade AnkiConnect to the latest version

Do not follow this link