Skip to content

Commit

Permalink
Fix graph not cleaned when moving to next question
Browse files Browse the repository at this point in the history
  • Loading branch information
itsupera committed Sep 23, 2021
1 parent 28e0de7 commit 94d736f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion onsei_anki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
from onsei_anki.api import get_graph_from_api
from onsei_anki.extract import get_sentence_transcript, get_sentence_audio_filepath
from onsei_anki.hooks import on_reviewer_did_show_question, on_replay_recorded, on_card_will_show, \
on_reviewer_did_answer_card
on_reviewer_did_answer_card, on_reviewer_did_show_question_cleanup
from onsei_anki.html import error_div, display_html, generate_addon_div, inject_addon_div, img_div


if CONFIG["show_in_preview"]:
gui_hooks.card_will_show.append(on_card_will_show)

if CONFIG["show_in_question"]:
gui_hooks.reviewer_did_show_question.append(on_reviewer_did_show_question)
else:
gui_hooks.reviewer_did_show_question.append(on_reviewer_did_show_question_cleanup)

gui_hooks.reviewer_did_answer_card.append(on_reviewer_did_answer_card)

Reviewer.onReplayRecorded = wrap(Reviewer.onReplayRecorded, on_replay_recorded)
12 changes: 12 additions & 0 deletions onsei_anki/hooks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from anki.cards import Card
from aqt import mw
from aqt.reviewer import Reviewer
from aqt.utils import showInfo

from onsei_anki import CONFIG
from onsei_anki.api import get_graph_from_api
Expand Down Expand Up @@ -42,6 +43,17 @@ def on_reviewer_did_show_question(card: Card):
inject_addon_div(div, web)


def on_reviewer_did_show_question_cleanup(card: Card):
""" Hook to display a simple graph when the question is shown during review """

deck_name = mw.col.decks.name(card.did)
if deck_name not in CONFIG["decks"]:
return

web = mw.reviewer.web
remove_addon_div(web)


def on_replay_recorded(self: Reviewer):
""" Hook to display a comparison graph when audio is recording by the user during a review """
deck_name = mw.col.decks.name(self.card.did)
Expand Down

0 comments on commit 94d736f

Please sign in to comment.