need to record active window prior to playing in mpv

This commit is contained in:
Damien Elmes 2018-05-31 13:20:10 +10:00
parent 9b7c701f25
commit e6fcfb7379
2 changed files with 14 additions and 3 deletions

View file

@ -102,6 +102,8 @@ class MpvManager(MPV):
super().__init__(window_id=None, debug=False)
def queueFile(self, file):
runHook("mpvWillPlay")
path = os.path.join(os.getcwd(), file)
self.command("loadfile", path, "append-play")

View file

@ -960,17 +960,26 @@ Difference to correct time: %s.""") % diffText
addHook("modSchema", self.onSchemaMod)
addHook("remNotes", self.onRemNotes)
addHook("odueInvalid", self.onOdueInvalid)
addHook("mpvWillPlay", self.onMpvWillPlay)
addHook("mpvIdleHook", self.onMpvIdle)
self._activeWindowOnPlay = None
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 onMpvWillPlay(self):
if not self._activeWindowOnPlay:
self._activeWindowOnPlay = self.app.activeWindow()
def onMpvIdle(self):
# when audio player finishes playing, restore focus to anki window
self.activateWindow()
self.raise_()
w = self._activeWindowOnPlay
if w and not sip.isdeleted(w) and w.isVisible():
w.activateWindow()
w.raise_()
self._activeWindowOnPlay = None
# Log note deletion
##########################################################################