add option in prefs to hide replay audio buttons

This commit is contained in:
Damien Elmes 2020-01-21 21:00:17 +10:00
parent fd95336933
commit f92bb55c25
5 changed files with 24 additions and 16 deletions

View file

@ -396,6 +396,15 @@ close the profile or restart Anki."""
def setupSound(self) -> None:
aqt.sound.setup_audio(self.taskman, self.pm.base)
def process_av_tags(self, text: str) -> Tuple[str, List[AVTag]]:
"Return card text with play buttons added, and the extracted AV tags."
tags = self.col.backend.get_av_tags(text)
if self.pm.profile.get("showPlayButtons", True):
text = aqt.sound.av_flags_to_html(self.col.backend.flag_av_tags(text))
else:
text = self.col.backend.strip_av_tags(text)
return (text, tags)
# Collection load/unload
##########################################################################

View file

@ -226,6 +226,7 @@ Not currently enabled; click the sync button in the main window to enable."""
self.form.pastePNG.setChecked(self.prof.get("pastePNG", False))
self.form.uiScale.setValue(self.mw.pm.uiScale() * 100)
self.form.pasteInvert.setChecked(self.prof.get("pasteInvert", False))
self.form.showPlayButtons.setChecked(self.prof.get("showPlayButtons", True))
def updateOptions(self):
self.prof["pastePNG"] = self.form.pastePNG.isChecked()
@ -234,3 +235,4 @@ Not currently enabled; click the sync button in the main window to enable."""
if newScale != self.mw.pm.uiScale():
self.mw.pm.setUiScale(newScale)
showInfo(_("Changes will take effect when you restart Anki."))
self.prof["showPlayButtons"] = self.form.showPlayButtons.isChecked()

View file

@ -18,7 +18,7 @@ from anki.sound import AVTag
from anki.utils import bodyClass, stripHTML
from aqt import AnkiQt, gui_hooks
from aqt.qt import *
from aqt.sound import av_player, getAudio, process_av_tags
from aqt.sound import av_player, getAudio
from aqt.utils import (
askUserDialog,
downArrow,
@ -192,7 +192,7 @@ The front of this card is empty. Please run Tools>Empty Cards."""
else:
q = c.q()
q, self._current_side_audio = process_av_tags(self.mw.col, q)
q, self._current_side_audio = self.mw.process_av_tags(q)
if self.autoplay(c):
av_player.play_tags(self._current_side_audio)
@ -236,7 +236,7 @@ The front of this card is empty. Please run Tools>Empty Cards."""
c = self.card
a = c.a()
# play audio?
a, self._current_side_audio = process_av_tags(self.mw.col, a)
a, self._current_side_audio = self.mw.process_av_tags(a)
if self.autoplay(c):
av_player.play_tags(self._current_side_audio)
a = self._mungeQA(a)

View file

@ -585,17 +585,6 @@ for (k, v) in _exports:
# Tag handling
##########################################################################
def process_av_tags(
col: anki.storage._Collection, text: str
) -> Tuple[str, List[AVTag]]:
"Return card text with play buttons added, and the extracted AV tags."
return (
av_flags_to_html(col.backend.flag_av_tags(text)),
col.backend.get_av_tags(text),
)
AV_FLAG_RE = re.compile(r"\[anki:play\](\d+)\[/anki:play]")

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<height>508</height>
<width>422</width>
<height>579</height>
</rect>
</property>
<property name="windowTitle">
@ -87,6 +87,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showPlayButtons">
<property name="text">
<string>Show play buttons on cards with audio</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="pastePNG">
<property name="text">
@ -514,6 +521,7 @@
<tabstop>hwAccel</tabstop>
<tabstop>showEstimates</tabstop>
<tabstop>showProgress</tabstop>
<tabstop>showPlayButtons</tabstop>
<tabstop>pastePNG</tabstop>
<tabstop>pasteInvert</tabstop>
<tabstop>nightMode</tabstop>