update qt/ to use the new API
This commit is contained in:
parent
caac4527e9
commit
02ec3f149c
@ -12,7 +12,7 @@ from anki.notes import Note
|
|||||||
from anki.utils import htmlToTextLine, isMac
|
from anki.utils import htmlToTextLine, isMac
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.sound import clearAudioQueue
|
from aqt.sound import av_player
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
addCloseShortcut,
|
addCloseShortcut,
|
||||||
askUser,
|
askUser,
|
||||||
@ -207,8 +207,7 @@ question on all cards."""
|
|||||||
if not self.addNote(self.editor.note):
|
if not self.addNote(self.editor.note):
|
||||||
return
|
return
|
||||||
tooltip(_("Added"), period=500)
|
tooltip(_("Added"), period=500)
|
||||||
# stop anything playing
|
av_player.stop_and_clear_queue()
|
||||||
clearAudioQueue()
|
|
||||||
self.onReset(keep=True)
|
self.onReset(keep=True)
|
||||||
self.mw.col.autosave()
|
self.mw.col.autosave()
|
||||||
|
|
||||||
@ -225,7 +224,7 @@ question on all cards."""
|
|||||||
def _reject(self) -> None:
|
def _reject(self) -> None:
|
||||||
gui_hooks.state_did_reset.remove(self.onReset)
|
gui_hooks.state_did_reset.remove(self.onReset)
|
||||||
gui_hooks.current_note_type_did_change.remove(self.onModelChange)
|
gui_hooks.current_note_type_did_change.remove(self.onModelChange)
|
||||||
clearAudioQueue()
|
av_player.stop_and_clear_queue()
|
||||||
self.removeTempNote(self.editor.note)
|
self.removeTempNote(self.editor.note)
|
||||||
self.editor.cleanup()
|
self.editor.cleanup()
|
||||||
self.modelChooser.cleanup()
|
self.modelChooser.cleanup()
|
||||||
|
@ -32,7 +32,7 @@ from anki.utils import (
|
|||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
from aqt.editor import Editor
|
from aqt.editor import Editor
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.sound import allSounds, clearAudioQueue, play
|
from aqt.sound import av_player
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
MenuList,
|
MenuList,
|
||||||
SubMenu,
|
SubMenu,
|
||||||
@ -1703,7 +1703,7 @@ where id in %s"""
|
|||||||
|
|
||||||
questionAudio = []
|
questionAudio = []
|
||||||
if self._previewBothSides:
|
if self._previewBothSides:
|
||||||
questionAudio = allSounds(txt)
|
questionAudio = self.mw.col.backend.get_av_tags(txt)
|
||||||
if self._previewState == "answer":
|
if self._previewState == "answer":
|
||||||
func = "_showAnswer"
|
func = "_showAnswer"
|
||||||
txt = c.a()
|
txt = c.a()
|
||||||
@ -1711,15 +1711,13 @@ where id in %s"""
|
|||||||
|
|
||||||
bodyclass = bodyClass(self.mw.col, c)
|
bodyclass = bodyClass(self.mw.col, c)
|
||||||
|
|
||||||
clearAudioQueue()
|
|
||||||
if self.mw.reviewer.autoplay(c):
|
if self.mw.reviewer.autoplay(c):
|
||||||
# if we're showing both sides at once, play question audio first
|
# if we're showing both sides at once, play question audio first
|
||||||
for audio in questionAudio:
|
av_player.play_tags(questionAudio)
|
||||||
play(audio)
|
|
||||||
# then play any audio that hasn't already been played
|
# then play any audio that hasn't already been played
|
||||||
for audio in allSounds(txt):
|
answer_audio = self.mw.col.backend.get_av_tags(txt)
|
||||||
if audio not in questionAudio:
|
unplayed_audio = [x for x in answer_audio if x not in questionAudio]
|
||||||
play(audio)
|
av_player.extend_and_play(unplayed_audio)
|
||||||
|
|
||||||
txt = mungeQA(self.col, txt)
|
txt = mungeQA(self.col, txt)
|
||||||
gui_hooks.card_will_show(
|
gui_hooks.card_will_show(
|
||||||
|
@ -12,7 +12,7 @@ from anki.lang import _, ngettext
|
|||||||
from anki.utils import bodyClass, isMac, isWin, joinFields
|
from anki.utils import bodyClass, isMac, isWin, joinFields
|
||||||
from aqt import gui_hooks
|
from aqt import gui_hooks
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.sound import clearAudioQueue, playFromText
|
from aqt.sound import av_player
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
askUser,
|
askUser,
|
||||||
downArrow,
|
downArrow,
|
||||||
@ -344,10 +344,8 @@ Please create a new card type first."""
|
|||||||
self.pform.frontWeb.eval("_showAnswer(%s,'%s');" % (json.dumps(q), bodyclass))
|
self.pform.frontWeb.eval("_showAnswer(%s,'%s');" % (json.dumps(q), bodyclass))
|
||||||
self.pform.backWeb.eval("_showAnswer(%s, '%s');" % (json.dumps(a), bodyclass))
|
self.pform.backWeb.eval("_showAnswer(%s, '%s');" % (json.dumps(a), bodyclass))
|
||||||
|
|
||||||
clearAudioQueue()
|
|
||||||
if c.id not in self.playedAudio:
|
if c.id not in self.playedAudio:
|
||||||
playFromText(c.q())
|
av_player.play_from_text(self.mw.col, c.q() + c.a())
|
||||||
playFromText(c.a())
|
|
||||||
self.playedAudio[c.id] = True
|
self.playedAudio[c.id] = True
|
||||||
|
|
||||||
self.updateCardNames()
|
self.updateCardNames()
|
||||||
@ -593,7 +591,7 @@ Enter deck to place new %s cards in, or leave blank:"""
|
|||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
self.cancelPreviewTimer()
|
self.cancelPreviewTimer()
|
||||||
clearAudioQueue()
|
av_player.stop_and_clear_queue()
|
||||||
if self.addMode:
|
if self.addMode:
|
||||||
# remove the filler fields we added
|
# remove the filler fields we added
|
||||||
for name in self.emptyFields:
|
for name in self.emptyFields:
|
||||||
|
@ -10,7 +10,7 @@ from anki.lang import _, ngettext
|
|||||||
from anki.utils import fmtTimeSpan, ids2str
|
from anki.utils import fmtTimeSpan, ids2str
|
||||||
from aqt import gui_hooks
|
from aqt import gui_hooks
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.sound import clearAudioQueue
|
from aqt.sound import av_player
|
||||||
from aqt.utils import askUser, getOnlyText, openHelp, openLink, shortcut, showWarning
|
from aqt.utils import askUser, getOnlyText, openHelp, openLink, shortcut, showWarning
|
||||||
|
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class DeckBrowser:
|
|||||||
self.scrollPos = QPoint(0, 0)
|
self.scrollPos = QPoint(0, 0)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
clearAudioQueue()
|
av_player.stop_and_clear_queue()
|
||||||
self.web.resetHandlers()
|
self.web.resetHandlers()
|
||||||
self.web.onBridgeCmd = self._linkHandler
|
self.web.onBridgeCmd = self._linkHandler
|
||||||
self._renderPage()
|
self._renderPage()
|
||||||
|
@ -26,7 +26,7 @@ from anki.notes import Note
|
|||||||
from anki.utils import checksum, isWin, namedtmp, stripHTMLMedia
|
from anki.utils import checksum, isWin, namedtmp, stripHTMLMedia
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.sound import getAudio
|
from aqt.sound import av_player, getAudio
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
getFile,
|
getFile,
|
||||||
openHelp,
|
openHelp,
|
||||||
@ -702,8 +702,7 @@ to a cloze type first, via Edit>Change Note Type."""
|
|||||||
name = urllib.parse.quote(fname.encode("utf8"))
|
name = urllib.parse.quote(fname.encode("utf8"))
|
||||||
return '<img src="%s">' % name
|
return '<img src="%s">' % name
|
||||||
else:
|
else:
|
||||||
aqt.sound.clearAudioQueue()
|
av_player.play_file(fname)
|
||||||
aqt.sound.play(fname)
|
|
||||||
return "[sound:%s]" % fname
|
return "[sound:%s]" % fname
|
||||||
|
|
||||||
def urlToFile(self, url):
|
def urlToFile(self, url):
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from aqt.sound import clearAudioQueue
|
from aqt.sound import av_player
|
||||||
from aqt.utils import askUserDialog, openLink, shortcut, tooltip
|
from aqt.utils import askUserDialog, openLink, shortcut, tooltip
|
||||||
|
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ class Overview:
|
|||||||
self.bottom = aqt.toolbar.BottomBar(mw, mw.bottomWeb)
|
self.bottom = aqt.toolbar.BottomBar(mw, mw.bottomWeb)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
clearAudioQueue()
|
av_player.stop_and_clear_queue()
|
||||||
self.web.resetHandlers()
|
self.web.resetHandlers()
|
||||||
self.web.onBridgeCmd = self._linkHandler
|
self.web.onBridgeCmd = self._linkHandler
|
||||||
self.mw.setStateShortcuts(self._shortcutKeys())
|
self.mw.setStateShortcuts(self._shortcutKeys())
|
||||||
|
@ -17,7 +17,7 @@ from anki.lang import _, ngettext
|
|||||||
from anki.utils import bodyClass, stripHTML
|
from anki.utils import bodyClass, stripHTML
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.sound import clearAudioQueue, getAudio, play, playFromText
|
from aqt.sound import av_player, getAudio
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
askUserDialog,
|
askUserDialog,
|
||||||
downArrow,
|
downArrow,
|
||||||
@ -95,7 +95,6 @@ class Reviewer:
|
|||||||
self.hadCardQueue = False
|
self.hadCardQueue = False
|
||||||
c = self.mw.col.sched.getCard()
|
c = self.mw.col.sched.getCard()
|
||||||
self.card = c
|
self.card = c
|
||||||
clearAudioQueue()
|
|
||||||
if not c:
|
if not c:
|
||||||
self.mw.moveToState("overview")
|
self.mw.moveToState("overview")
|
||||||
return
|
return
|
||||||
@ -114,15 +113,14 @@ class Reviewer:
|
|||||||
else:
|
else:
|
||||||
state = self.state
|
state = self.state
|
||||||
c = self.card
|
c = self.card
|
||||||
clearAudioQueue()
|
|
||||||
if state == "question":
|
if state == "question":
|
||||||
playFromText(c.q())
|
av_player.play_from_text(self.mw.col, c.q())
|
||||||
elif state == "answer":
|
elif state == "answer":
|
||||||
txt = ""
|
txt = ""
|
||||||
if self._replayq(c, previewer):
|
if self._replayq(c, previewer):
|
||||||
txt = c.q()
|
txt = c.q()
|
||||||
txt += c.a()
|
txt += c.a()
|
||||||
playFromText(txt)
|
av_player.play_from_text(self.mw.col, txt)
|
||||||
|
|
||||||
# Initializing the webview
|
# Initializing the webview
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@ -184,7 +182,7 @@ The front of this card is empty. Please run Tools>Empty Cards."""
|
|||||||
else:
|
else:
|
||||||
q = c.q()
|
q = c.q()
|
||||||
if self.autoplay(c):
|
if self.autoplay(c):
|
||||||
playFromText(q)
|
av_player.play_from_text(self.mw.col, q)
|
||||||
# render & update bottom
|
# render & update bottom
|
||||||
q = self._mungeQA(q)
|
q = self._mungeQA(q)
|
||||||
q = gui_hooks.card_will_show(q, c, "reviewQuestion")
|
q = gui_hooks.card_will_show(q, c, "reviewQuestion")
|
||||||
@ -225,9 +223,8 @@ The front of this card is empty. Please run Tools>Empty Cards."""
|
|||||||
c = self.card
|
c = self.card
|
||||||
a = c.a()
|
a = c.a()
|
||||||
# play audio?
|
# play audio?
|
||||||
clearAudioQueue()
|
|
||||||
if self.autoplay(c):
|
if self.autoplay(c):
|
||||||
playFromText(a)
|
av_player.play_from_text(self.mw.col, a)
|
||||||
a = self._mungeQA(a)
|
a = self._mungeQA(a)
|
||||||
a = gui_hooks.card_will_show(a, c, "reviewAnswer")
|
a = gui_hooks.card_will_show(a, c, "reviewAnswer")
|
||||||
# render and update bottom
|
# render and update bottom
|
||||||
@ -788,5 +785,4 @@ time = %(time)d;
|
|||||||
def onReplayRecorded(self):
|
def onReplayRecorded(self):
|
||||||
if not self._recordedAudio:
|
if not self._recordedAudio:
|
||||||
return tooltip(_("You haven't recorded your voice yet."))
|
return tooltip(_("You haven't recorded your voice yet."))
|
||||||
clearAudioQueue()
|
av_player.play_file(self._recordedAudio)
|
||||||
play(self._recordedAudio)
|
|
||||||
|
@ -9,7 +9,6 @@ from typing import Optional
|
|||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from anki.sound import stripSounds
|
|
||||||
from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
|
from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
|
||||||
@ -481,7 +480,7 @@ def restoreHeader(widget, key):
|
|||||||
|
|
||||||
def mungeQA(col, txt):
|
def mungeQA(col, txt):
|
||||||
txt = col.media.escapeImages(txt)
|
txt = col.media.escapeImages(txt)
|
||||||
txt = stripSounds(txt)
|
txt = col.backend.strip_av_tags(txt)
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user