diff --git a/anki/sound.py b/anki/sound.py index 2d546e89a..16e8ccf87 100644 --- a/anki/sound.py +++ b/anki/sound.py @@ -5,7 +5,7 @@ import html import re, sys, threading, time, subprocess, os, atexit import random -from anki.hooks import addHook +from anki.hooks import addHook, runHook from anki.utils import tmpdir, isWin, isMac, isLin # Shared utils @@ -114,6 +114,9 @@ class MpvManager(MPV): def seekRelative(self, secs): self.command("seek", secs, "relative") + def on_idle(self): + runHook("mpvIdleHook") + mpvManager = None def setupMPV(): diff --git a/aqt/main.py b/aqt/main.py index 0ef9a3f71..a7364f189 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -958,12 +958,18 @@ Difference to correct time: %s.""") % diffText addHook("modSchema", self.onSchemaMod) addHook("remNotes", self.onRemNotes) addHook("odueInvalid", self.onOdueInvalid) + addHook("mpvIdleHook", self.onMpvIdle) def onOdueInvalid(self): showWarning(_("""\ Invalid property found on card. Please use Tools>Check Database, \ and if the problem comes up again, please ask on the support site.""")) + def onMpvIdle(self): + # when audio player finishes playing, restore focus to anki window + self.activateWindow() + self.raise_() + # Log note deletion ##########################################################################