fix replay audio again, and decouple the code from the reviewer
This commit is contained in:
parent
e838769d02
commit
10eb947402
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user