View Source AnkiConnect.Actions.Graphical (anki_connect v0.1.1)

Graphical actions.

All functions are delegated inside AnkiConnect module, so you should import them from there.

Link to this section Summary

Functions

Invokes the Add Cards dialog, presets the note using the given deck and model, with the provided field values and tags.

Answers the current card.

Invokes the Card Browser dialog and searches for a given query. Returns an array of identifiers of the cards that were found.

Requests a database check.

Returns information about the current card or error if not in review mode.

Opens the Deck Browser dialog.

Opens the Deck Overview dialog for the deck with the given name.

Starts review for the deck with the given name. Returns error if failed.

Opens the Edit dialog with a note corresponding to given note ID.

Schedules a request to gracefully close Anki.

Finds the open instance of the Card Browser dialog and returns an array of identifiers of the notes that are selected.

Shows answer text for the current card. Returns error if not in review mode.

Shows question text for the current card. Returns error if not in review mode.

Starts or resets the timerStarted value for the current card.

Link to this section Functions

@spec gui_add_cards(%{note: map()}) :: {:ok, [integer()]} | {:error, any()}

Invokes the Add Cards dialog, presets the note using the given deck and model, with the provided field values and tags.

Invoking it multiple times closes the old window and reopen the window with the new provided values.

Audio, video, and picture files can be embedded into the fields via the audio, video, and picture keys, respectively. Refer to the documentation of add_note and store_media_file for an explanation of these fields.

The result is the ID of the note which would be added, if the user chose to confirm the Add Cards dialogue.

sample-param

Sample param:

%{
  note: %{
    deck_name: "Default",
    model_name: "Cloze",
    fields: %{
      Text: "The capital of Romania is {{c1::Bucharest}}",
      Extra: "Romania is a country in Europe"
    },
    tags: ["countries"],
    picture: [%{
      url: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/13/EU-Romania.svg/285px-EU-Romania.svg.png",
      filename: "romania.png",
      fields: ["Extra"]
    }]
  }
}

sample-result

Sample result:

{:ok, 1496198395707}
@spec gui_answer_card(%{ease: integer()}) :: {:ok, nil} | {:error, any()}

Answers the current card.

Note that the answer for the current card must be displayed before before any answer can be accepted by Anki.

@spec gui_browse(%{query: String.t()}) :: {:ok, [integer()]} | {:error, any()}

Invokes the Card Browser dialog and searches for a given query. Returns an array of identifiers of the cards that were found.

Query syntax is documented here.

sample-result

Sample result:

{:ok, [1494723142483, 1494703460437, 1494703479525]}
@spec gui_check_database() :: {:ok, nil} | {:error, any()}

Requests a database check.

It returns immediately without waiting for the check to complete. Therefore, the action will always return {:ok, nil} even if errors are detected during the database check.

@spec gui_current_card() :: {:ok, map()} | {:error, any()}

Returns information about the current card or error if not in review mode.

sample-result

Sample result:

{:ok, %{
  "answer" => "back content",
  "question" => "front content",
  "deckName" => "Default",
  "modelName" => "Basic",
  "fieldOrder" => 0,
  "fields" => %{
    "Front" => %{"value" => "front content", "order" => 0},
    "Back" => %{"value" => "back content", "order" => 1}
  },
  "template" => "Forward",
  "cardId" => 1498938915662,
  "buttons" => [1, 2, 3],
  "nextReviews" => ["<1m", "<10m", "4d"]
}}
@spec gui_deck_browser() :: {:ok, nil} | {:error, any()}

Opens the Deck Browser dialog.

@spec gui_deck_overview(%{name: String.t()}) :: {:ok, nil} | {:error, any()}

Opens the Deck Overview dialog for the deck with the given name.

Returns error if failed.

@spec gui_deck_review(%{name: String.t()}) :: {:ok, nil} | {:error, any()}

Starts review for the deck with the given name. Returns error if failed.

@spec gui_edit_note(%{note: map()}) :: {:ok, nil} | {:error, any()}

Opens the Edit dialog with a note corresponding to given note ID.

The dialog is similar to the Edit Current dialog, but:

  • has a Preview button to preview the cards for the note
  • has a Browse button to open the browser with these cards
  • has Previous/Back buttons to navigate the history of the dialog
  • has no bar with the Close button
@spec gui_exit_anki() :: {:ok, nil} | {:error, any()}

Schedules a request to gracefully close Anki.

This operation is asynchronous, so it will return immediately and won’t wait until the Anki process actually terminates.

@spec gui_selected_notes() :: {:ok, [integer()]} | {:error, any()}

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-result

Sample result:

{:ok, [1494723142483, 1494703460437, 1494703479525]}
@spec gui_show_answer() :: {:ok, nil} | {:error, any()}

Shows answer text for the current card. Returns error if not in review mode.

@spec gui_show_question() :: {:ok, nil} | {:error, any()}

Shows question text for the current card. Returns error if not in review mode.

@spec gui_start_card_timer() :: {:ok, nil} | {:error, any()}

Starts or resets the timerStarted value for the current card.

This is useful for deferring the start time to when it is displayed via the API, allowing the recorded time taken to answer the card to be more accurate when calling guiAnswerCard.