From 10eb947402a25540b9afff83480244d5b326bbd5 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 13 Apr 2020 08:59:36 +1000 Subject: [PATCH] fix replay audio again, and decouple the code from the reviewer --- pylib/anki/cards.py | 4 ++++ qt/aqt/previewer.py | 6 +++++- qt/aqt/reviewer.py | 33 +++++++++++++-------------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/pylib/anki/cards.py b/pylib/anki/cards.py index b229f17d5..b32e44826 100644 --- a/pylib/anki/cards.py +++ b/pylib/anki/cards.py @@ -166,6 +166,10 @@ class Card: conf = self.col.decks.confForDid(self.odid or self.did) return conf["timer"] + def replay_question_audio_on_answer_side(self) -> bool: + conf = self.col.decks.confForDid(self.odid or self.did) + return conf.get("replayq", True) + def timeTaken(self) -> int: "Time taken to answer card, in integer MS." total = int((time.time() - self.timerStarted) * 1000) diff --git a/qt/aqt/previewer.py b/qt/aqt/previewer.py index 184b6aaa0..0c25cf9ab 100644 --- a/qt/aqt/previewer.py +++ b/qt/aqt/previewer.py @@ -21,6 +21,7 @@ from aqt.qt import ( QWidget, qconnect, ) +from aqt.reviewer import replay_audio from aqt.sound import av_player, play_clicked_audio from aqt.theme import theme_manager from aqt.utils import restoreGeom, saveGeom @@ -88,7 +89,10 @@ class Previewer(QDialog): self.mw.progress.timer(100, self._on_close, False) def _on_replay_audio(self): - self.mw.reviewer.replayAudio(self) + if self._state == "question": + replay_audio(self.card(), True) + elif self._state == "answer": + replay_audio(self.card(), False) def close(self): self._on_close() diff --git a/qt/aqt/reviewer.py b/qt/aqt/reviewer.py index 7cc92488f..b6ad94b35 100644 --- a/qt/aqt/reviewer.py +++ b/qt/aqt/reviewer.py @@ -29,6 +29,14 @@ class ReviewerBottomBar: def __init__(self, reviewer: Reviewer) -> None: self.reviewer = reviewer +def replay_audio(card: Card, question_side: bool) -> None: + if question_side: + av_player.play_tags(card.question_av_tags()) + else: + tags = card.answer_av_tags() + if card.replay_question_audio_on_answer_side(): + tags = card.question_av_tags() + tags + av_player.play_tags(tags) class Reviewer: "Manage reviews. Maintains a separate state." @@ -110,20 +118,11 @@ class Reviewer: # Audio ########################################################################## - def replayAudio(self, previewer=None): - if previewer: - state = previewer.state() - c = previewer.card() - else: - state = self.state - c = self.card - if state == "question": - av_player.play_tags(c.question_av_tags()) - elif state == "answer": - tags = c.answer_av_tags() - if self._replayq(c, previewer): - tags = c.question_av_tags() + tags - av_player.play_tags(tags) + def replayAudio(self) -> None: + if self.state == "question": + replay_audio(self.card, True) + elif self.state == "answer": + replay_audio(self.card, False) # Initializing the webview ########################################################################## @@ -212,12 +211,6 @@ The front of this card is empty. Please run Tools>Empty Cards.""" def autoplay(self, card: Card) -> bool: return self.mw.col.decks.confForDid(card.odid or card.did)["autoplay"] - def _replayq(self, card, previewer=None): - s = previewer if previewer else self - return s.mw.col.decks.confForDid(s.card().odid or s.card().did).get( - "replayq", True - ) - def _drawFlag(self) -> None: self.web.eval("_drawFlag(%s);" % self.card.userFlag())