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
-
#gui_add_cards(note = nil) ⇒ Integer
Opens Add Cards dialog with preset values.
-
#gui_add_note_set_data(note, append: false) ⇒ Boolean, Hash
Sets fields/tags/deck/model in open Add Note dialog.
-
#gui_answer_card(ease) ⇒ Boolean
Answers the current card.
-
#gui_browse(query = nil, reorder_cards: nil) ⇒ Array<Integer>
Opens Card Browser dialog and searches for query.
-
#gui_check_database ⇒ Boolean
Requests database check.
-
#gui_current_card ⇒ Hash
Gets information about current card in review.
-
#gui_deck_browser ⇒ nil
Opens Deck Browser dialog.
-
#gui_deck_overview(name) ⇒ Boolean
Opens Deck Overview dialog for a deck.
-
#gui_deck_review(name) ⇒ Boolean
Starts review for a deck.
-
#gui_edit_note(note_id) ⇒ nil
Opens Edit dialog for a note.
-
#gui_exit_anki ⇒ nil
Schedules graceful Anki shutdown.
-
#gui_import_file(path: nil) ⇒ nil
Opens Import dialog with optional file path.
-
#gui_play_audio ⇒ Boolean
Plays audio for current card side.
-
#gui_review_active? ⇒ Boolean
Checks whether the review screen has an active card.
-
#gui_select_card(card_id) ⇒ Boolean
Selects a card in the open Card Browser.
-
#gui_selected_notes ⇒ Array<Integer>
Gets selected notes from open Card Browser.
-
#gui_show_answer ⇒ Boolean
Shows answer side of current card.
-
#gui_show_question ⇒ Boolean
Shows question side of current card.
-
#gui_start_card_timer ⇒ Boolean
Starts/resets timer for current card.
-
#gui_undo ⇒ Boolean
Undoes last action/card.
Instance Method Details
#gui_add_cards(note = nil) ⇒ Integer
Opens Add Cards dialog with preset values. Multiple invocations close old window and reopen with new values.
52 53 54 55 56 |
# File 'lib/anki_connect/graphical.rb', line 52 def gui_add_cards(note = nil) params = {} params[:note] = normalize_gui_note(note) unless note.nil? request(:guiAddCards, **params) end |
#gui_add_note_set_data(note, append: false) ⇒ Boolean, Hash
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.
73 74 75 |
# File 'lib/anki_connect/graphical.rb', line 73 def gui_add_note_set_data(note, append: false) request(:guiAddNoteSetData, note: normalize_gui_note(note), append: append) end |
#gui_answer_card(ease) ⇒ Boolean
Answers the current card. Answer must be displayed before answering.
119 120 121 |
# File 'lib/anki_connect/graphical.rb', line 119 def gui_answer_card(ease) request(:guiAnswerCard, ease: ease) end |
#gui_browse(query = nil, reorder_cards: nil) ⇒ Array<Integer>
Opens Card Browser dialog and searches for query.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/anki_connect/graphical.rb', line 19 def gui_browse(query = nil, reorder_cards: nil) params = {} params[:query] = query unless query.nil? if reorder_cards normalized = normalize_keys(reorder_cards, REORDER_CARD_KEYS, name: 'reorder_cards') missing_keys = REORDER_CARD_KEYS.values.reject { |key| normalized.key?(key) } raise ArgumentError, "missing reorder_cards keys: #{missing_keys.join(', ')}" unless missing_keys.empty? params[:reorderCards] = normalized end request(:guiBrowse, **params) end |
#gui_check_database ⇒ Boolean
Requests database check. Returns immediately without waiting for check to complete.
176 177 178 |
# File 'lib/anki_connect/graphical.rb', line 176 def gui_check_database request(:guiCheckDatabase) end |
#gui_current_card ⇒ Hash
Gets information about current card in review.
88 89 90 |
# File 'lib/anki_connect/graphical.rb', line 88 def gui_current_card request(:guiCurrentCard) end |
#gui_deck_browser ⇒ nil
Opens Deck Browser dialog.
141 142 143 |
# File 'lib/anki_connect/graphical.rb', line 141 def gui_deck_browser request(:guiDeckBrowser) end |
#gui_deck_overview(name) ⇒ Boolean
Opens Deck Overview dialog for a deck.
134 135 136 |
# File 'lib/anki_connect/graphical.rb', line 134 def gui_deck_overview(name) request(:guiDeckOverview, name: name) end |
#gui_deck_review(name) ⇒ Boolean
Starts review for a deck.
149 150 151 |
# File 'lib/anki_connect/graphical.rb', line 149 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.
63 64 65 |
# File 'lib/anki_connect/graphical.rb', line 63 def gui_edit_note(note_id) request(:guiEditNote, note: note_id) end |
#gui_exit_anki ⇒ nil
Schedules graceful Anki shutdown. Asynchronous - returns immediately without waiting for termination.
168 169 170 |
# File 'lib/anki_connect/graphical.rb', line 168 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.
158 159 160 161 162 |
# File 'lib/anki_connect/graphical.rb', line 158 def gui_import_file(path: nil) params = {} params[:path] = path if path request(:guiImportFile, **params) end |
#gui_play_audio ⇒ Boolean
Plays audio for current card side.
183 184 185 |
# File 'lib/anki_connect/graphical.rb', line 183 def gui_play_audio request(:guiPlayAudio) end |
#gui_review_active? ⇒ Boolean
Checks whether the review screen has an active card.
80 81 82 |
# File 'lib/anki_connect/graphical.rb', line 80 def gui_review_active? request(:guiReviewActive) end |
#gui_select_card(card_id) ⇒ Boolean
Selects a card in the open Card Browser.
36 37 38 |
# File 'lib/anki_connect/graphical.rb', line 36 def gui_select_card(card_id) request(:guiSelectCard, card: card_id) end |
#gui_selected_notes ⇒ Array<Integer>
Gets selected notes from open Card Browser.
43 44 45 |
# File 'lib/anki_connect/graphical.rb', line 43 def gui_selected_notes request(:guiSelectedNotes) end |
#gui_show_answer ⇒ Boolean
Shows answer side of current card.
110 111 112 |
# File 'lib/anki_connect/graphical.rb', line 110 def gui_show_answer request(:guiShowAnswer) end |
#gui_show_question ⇒ Boolean
Shows question side of current card.
103 104 105 |
# File 'lib/anki_connect/graphical.rb', line 103 def gui_show_question request(:guiShowQuestion) end |
#gui_start_card_timer ⇒ Boolean
Starts/resets timer for current card. Useful for accurate time tracking when displaying cards via API.
96 97 98 |
# File 'lib/anki_connect/graphical.rb', line 96 def gui_start_card_timer request(:guiStartCardTimer) end |
#gui_undo ⇒ Boolean
Undoes last action/card.
126 127 128 |
# File 'lib/anki_connect/graphical.rb', line 126 def gui_undo request(:guiUndo) end |