mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
need to record active window prior to playing in mpv
This commit is contained in:
parent
9b7c701f25
commit
e6fcfb7379
2 changed files with 14 additions and 3 deletions
|
@ -102,6 +102,8 @@ class MpvManager(MPV):
|
||||||
super().__init__(window_id=None, debug=False)
|
super().__init__(window_id=None, debug=False)
|
||||||
|
|
||||||
def queueFile(self, file):
|
def queueFile(self, file):
|
||||||
|
runHook("mpvWillPlay")
|
||||||
|
|
||||||
path = os.path.join(os.getcwd(), file)
|
path = os.path.join(os.getcwd(), file)
|
||||||
self.command("loadfile", path, "append-play")
|
self.command("loadfile", path, "append-play")
|
||||||
|
|
||||||
|
|
15
aqt/main.py
15
aqt/main.py
|
@ -960,17 +960,26 @@ Difference to correct time: %s.""") % diffText
|
||||||
addHook("modSchema", self.onSchemaMod)
|
addHook("modSchema", self.onSchemaMod)
|
||||||
addHook("remNotes", self.onRemNotes)
|
addHook("remNotes", self.onRemNotes)
|
||||||
addHook("odueInvalid", self.onOdueInvalid)
|
addHook("odueInvalid", self.onOdueInvalid)
|
||||||
|
|
||||||
|
addHook("mpvWillPlay", self.onMpvWillPlay)
|
||||||
addHook("mpvIdleHook", self.onMpvIdle)
|
addHook("mpvIdleHook", self.onMpvIdle)
|
||||||
|
self._activeWindowOnPlay = None
|
||||||
|
|
||||||
def onOdueInvalid(self):
|
def onOdueInvalid(self):
|
||||||
showWarning(_("""\
|
showWarning(_("""\
|
||||||
Invalid property found on card. Please use Tools>Check Database, \
|
Invalid property found on card. Please use Tools>Check Database, \
|
||||||
and if the problem comes up again, please ask on the support site."""))
|
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):
|
def onMpvIdle(self):
|
||||||
# when audio player finishes playing, restore focus to anki window
|
w = self._activeWindowOnPlay
|
||||||
self.activateWindow()
|
if w and not sip.isdeleted(w) and w.isVisible():
|
||||||
self.raise_()
|
w.activateWindow()
|
||||||
|
w.raise_()
|
||||||
|
self._activeWindowOnPlay = None
|
||||||
|
|
||||||
# Log note deletion
|
# Log note deletion
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
Loading…
Reference in a new issue