Module: AnkiConnect::Client::Graphical

Included in:
AnkiConnect::Client
Defined in:
lib/anki_connect/graphical.rb

Overview

Methods to interact with Anki’s GUI windows and dialogs (card browser, review screen, editing interfaces).

Instance Method Summary collapse

Instance Method Details

#gui_add_cards(note) ⇒ Integer

Opens Add Cards dialog with preset values. Multiple invocations close old window and reopen with new values.

Parameters:

  • note (Hash)

    Note object with deckName, modelName, fields, tags, and optional audio/video/picture

Returns:

  • (Integer)

    Note ID that would be created if user confirms



39
40
41
# File 'lib/anki_connect/graphical.rb', line 39

def gui_add_cards(note)
  request(:guiAddCards, note: note)
end

#gui_add_note_set_data(note, append: false) ⇒ Boolean

Sets fields/tags/deck/model in open Add Note dialog. Returns error if Add Note dialog not open. Deck/model always replace; fields/tags respect append flag.

Parameters:

  • note (Hash)

    Note object with optional deckName, modelName, fields, tags

  • append (Boolean) (defaults to: false)

    If true, appends to fields/tags; otherwise replaces (default: false)

Returns:

  • (Boolean)

    true on success



58
59
60
# File 'lib/anki_connect/graphical.rb', line 58

def gui_add_note_set_data(note, append: false)
  request(:guiAddNoteSetData, note: note, append: append)
end

#gui_answer_card(ease) ⇒ Boolean

Answers the current card. Answer must be displayed before answering.

Parameters:

  • ease (Integer)

    Answer button (1-4)

Returns:

  • (Boolean)

    true on success, false otherwise



96
97
98
# File 'lib/anki_connect/graphical.rb', line 96

def gui_answer_card(ease)
  request(:guiAnswerCard, ease: ease)
end

#gui_browse(query, reorder_cards: nil) ⇒ Array<Integer>

Opens Card Browser dialog and searches for query.

Parameters:

  • query (String)

    Search query string

  • reorder_cards (Hash, nil) (defaults to: nil)

    (optional) Object with order (ascending/descending) and columnId

Returns:

  • (Array<Integer>)

    Array of card IDs found



13
14
15
16
17
# File 'lib/anki_connect/graphical.rb', line 13

def gui_browse(query, reorder_cards: nil)
  params = { query: query }
  params[:reorderCards] = reorder_cards if reorder_cards
  request(:guiBrowse, **params)
end

#gui_check_databaseBoolean

Requests database check. Returns immediately without waiting for check to complete.

Returns:

  • (Boolean)

    true (always)



153
154
155
# File 'lib/anki_connect/graphical.rb', line 153

def gui_check_database
  request(:guiCheckDatabase)
end

#gui_current_cardHash?

Gets information about current card in review.

Returns:

  • (Hash, nil)

    Object with card info, or nil if not in review mode



65
66
67
# File 'lib/anki_connect/graphical.rb', line 65

def gui_current_card
  request(:guiCurrentCard)
end

#gui_deck_browsernil

Opens Deck Browser dialog.

Returns:

  • (nil)


118
119
120
# File 'lib/anki_connect/graphical.rb', line 118

def gui_deck_browser
  request(:guiDeckBrowser)
end

#gui_deck_overview(name) ⇒ Boolean

Opens Deck Overview dialog for a deck.

Parameters:

  • name (String)

    Deck name

Returns:

  • (Boolean)

    true on success, false otherwise



111
112
113
# File 'lib/anki_connect/graphical.rb', line 111

def gui_deck_overview(name)
  request(:guiDeckOverview, name: name)
end

#gui_deck_review(name) ⇒ Boolean

Starts review for a deck.

Parameters:

  • name (String)

    Deck name

Returns:

  • (Boolean)

    true on success, false otherwise



126
127
128
# File 'lib/anki_connect/graphical.rb', line 126

def gui_deck_review(name)
  request(:guiDeckReview, name: name)
end

#gui_edit_note(note_id) ⇒ nil

Opens Edit dialog for a note. Opens edit dialog with Preview, Browse, and navigation buttons.

Parameters:

  • note_id (Integer)

    Note ID

Returns:

  • (nil)


48
49
50
# File 'lib/anki_connect/graphical.rb', line 48

def gui_edit_note(note_id)
  request(:guiEditNote, note: note_id)
end

#gui_exit_ankinil

Schedules graceful Anki shutdown. Asynchronous - returns immediately without waiting for termination.

Returns:

  • (nil)


145
146
147
# File 'lib/anki_connect/graphical.rb', line 145

def gui_exit_anki
  request(:guiExitAnki)
end

#gui_import_file(path: nil) ⇒ nil

Opens Import dialog with optional file path. Opens file dialog if no path provided. Forward slashes required on Windows. Anki 2.1.52+ only.

Parameters:

  • path (String, nil) (defaults to: nil)

    File path to import (optional)

Returns:

  • (nil)


135
136
137
138
139
# File 'lib/anki_connect/graphical.rb', line 135

def gui_import_file(path: nil)
  params = {}
  params[:path] = path if path
  request(:guiImportFile, **params)
end

#gui_play_audioBoolean

Plays audio for current card side.

Returns:

  • (Boolean)

    true on success, false otherwise



160
161
162
# File 'lib/anki_connect/graphical.rb', line 160

def gui_play_audio
  request(:guiPlayAudio)
end

#gui_select_card(card_id) ⇒ Boolean

Selects a card in the open Card Browser.

Parameters:

  • card_id (Integer)

    Card ID

Returns:

  • (Boolean)

    true if browser is open, false otherwise



23
24
25
# File 'lib/anki_connect/graphical.rb', line 23

def gui_select_card(card_id)
  request(:guiSelectCard, card: card_id)
end

#gui_selected_notesArray<Integer>

Gets selected notes from open Card Browser.

Returns:

  • (Array<Integer>)

    Array of note IDs (empty if browser not open)



30
31
32
# File 'lib/anki_connect/graphical.rb', line 30

def gui_selected_notes
  request(:guiSelectedNotes)
end

#gui_show_answerBoolean

Shows answer side of current card.

Returns:

  • (Boolean)

    true if in review mode, false otherwise



87
88
89
# File 'lib/anki_connect/graphical.rb', line 87

def gui_show_answer
  request(:guiShowAnswer)
end

#gui_show_questionBoolean

Shows question side of current card.

Returns:

  • (Boolean)

    true if in review mode, false otherwise



80
81
82
# File 'lib/anki_connect/graphical.rb', line 80

def gui_show_question
  request(:guiShowQuestion)
end

#gui_start_card_timerBoolean

Starts/resets timer for current card. Useful for accurate time tracking when displaying cards via API.

Returns:

  • (Boolean)

    true



73
74
75
# File 'lib/anki_connect/graphical.rb', line 73

def gui_start_card_timer
  request(:guiStartCardTimer)
end

#gui_undoBoolean

Undoes last action/card.

Returns:

  • (Boolean)

    true on success, false otherwise



103
104
105
# File 'lib/anki_connect/graphical.rb', line 103

def gui_undo
  request(:guiUndo)
end