mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
fix audio displaying console window on Windows
This commit is contained in:
parent
982aca0c99
commit
5a79bc69b8
3 changed files with 40 additions and 40 deletions
|
@ -25,7 +25,7 @@ from aqt import gui_hooks
|
||||||
from aqt.mpv import MPV, MPVBase
|
from aqt.mpv import MPV, MPVBase
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.taskman import TaskManager
|
from aqt.taskman import TaskManager
|
||||||
from aqt.utils import restoreGeom, saveGeom
|
from aqt.utils import restoreGeom, saveGeom, startup_info
|
||||||
|
|
||||||
# AV player protocol
|
# AV player protocol
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -209,6 +209,21 @@ def _packagedCmd(cmd) -> Tuple[Any, Dict[str, str]]:
|
||||||
return cmd, env
|
return cmd, env
|
||||||
|
|
||||||
|
|
||||||
|
# Platform hacks
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
# legacy global for add-ons
|
||||||
|
si = startup_info()
|
||||||
|
|
||||||
|
# osx throws interrupted system call errors frequently
|
||||||
|
def retryWait(proc) -> Any:
|
||||||
|
while 1:
|
||||||
|
try:
|
||||||
|
return proc.wait()
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
# Simple player implementations
|
# Simple player implementations
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -242,7 +257,9 @@ class SimpleProcessPlayer(Player): # pylint: disable=abstract-method
|
||||||
|
|
||||||
def _play(self, tag: AVTag) -> None:
|
def _play(self, tag: AVTag) -> None:
|
||||||
assert isinstance(tag, SoundOrVideoTag)
|
assert isinstance(tag, SoundOrVideoTag)
|
||||||
self._process = subprocess.Popen(self.args + [tag.filename], env=self.env)
|
self._process = subprocess.Popen(
|
||||||
|
self.args + [tag.filename], env=self.env, startupinfo=startup_info()
|
||||||
|
)
|
||||||
self._wait_for_termination(tag)
|
self._wait_for_termination(tag)
|
||||||
|
|
||||||
def _wait_for_termination(self, tag: AVTag):
|
def _wait_for_termination(self, tag: AVTag):
|
||||||
|
@ -301,34 +318,6 @@ class SimpleMplayerPlayer(SimpleProcessPlayer, SoundOrVideoPlayer):
|
||||||
args += ["-ao", "win32"]
|
args += ["-ao", "win32"]
|
||||||
|
|
||||||
|
|
||||||
# Platform hacks
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
# don't show box on windows
|
|
||||||
si: Optional[Any]
|
|
||||||
if sys.platform == "win32":
|
|
||||||
si = subprocess.STARTUPINFO() # pytype: disable=module-attr
|
|
||||||
try:
|
|
||||||
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW # pytype: disable=module-attr
|
|
||||||
except:
|
|
||||||
# pylint: disable=no-member
|
|
||||||
# python2.7+
|
|
||||||
si.dwFlags |= (
|
|
||||||
subprocess._subprocess.STARTF_USESHOWWINDOW
|
|
||||||
) # pytype: disable=module-attr
|
|
||||||
else:
|
|
||||||
si = None
|
|
||||||
|
|
||||||
|
|
||||||
# osx throws interrupted system call errors frequently
|
|
||||||
def retryWait(proc) -> Any:
|
|
||||||
while 1:
|
|
||||||
try:
|
|
||||||
return proc.wait()
|
|
||||||
except OSError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
# MPV
|
# MPV
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -396,7 +385,10 @@ class SimpleMplayerSlaveModePlayer(SimpleMplayerPlayer):
|
||||||
def _play(self, tag: AVTag) -> None:
|
def _play(self, tag: AVTag) -> None:
|
||||||
assert isinstance(tag, SoundOrVideoTag)
|
assert isinstance(tag, SoundOrVideoTag)
|
||||||
self._process = subprocess.Popen(
|
self._process = subprocess.Popen(
|
||||||
self.args + [tag.filename], env=self.env, stdin=subprocess.PIPE
|
self.args + [tag.filename],
|
||||||
|
env=self.env,
|
||||||
|
stdin=subprocess.PIPE,
|
||||||
|
startupinfo=startup_info(),
|
||||||
)
|
)
|
||||||
self._wait_for_termination(tag)
|
self._wait_for_termination(tag)
|
||||||
|
|
||||||
|
@ -441,7 +433,9 @@ class _Recorder:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
cmd, env = _packagedCmd(c)
|
cmd, env = _packagedCmd(c)
|
||||||
ret = retryWait(subprocess.Popen(cmd, startupinfo=si, env=env))
|
ret = retryWait(
|
||||||
|
subprocess.Popen(cmd, startupinfo=startup_info(), env=env)
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
ret = True
|
ret = True
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -5,7 +5,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from typing import Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
|
@ -759,3 +759,15 @@ def opengl_vendor():
|
||||||
def gfxDriverIsBroken():
|
def gfxDriverIsBroken():
|
||||||
driver = opengl_vendor()
|
driver = opengl_vendor()
|
||||||
return driver == "nouveau"
|
return driver == "nouveau"
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def startup_info() -> Any:
|
||||||
|
"Use subprocess.Popen(startupinfo=...) to avoid opening a console window."
|
||||||
|
if not sys.platform == "win32":
|
||||||
|
return None
|
||||||
|
si = subprocess.STARTUPINFO() # pytype: disable=module-attr
|
||||||
|
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW # pytype: disable=module-attr
|
||||||
|
return si
|
||||||
|
|
|
@ -328,13 +328,7 @@ body {{ zoom: {}; {} }}
|
||||||
|
|
||||||
<body class="{}">{}</body>
|
<body class="{}">{}</body>
|
||||||
</html>""".format(
|
</html>""".format(
|
||||||
self.title,
|
self.title, self.zoomFactor(), fontspec, widgetspec, head, body_class, body,
|
||||||
self.zoomFactor(),
|
|
||||||
fontspec,
|
|
||||||
widgetspec,
|
|
||||||
head,
|
|
||||||
body_class,
|
|
||||||
body,
|
|
||||||
)
|
)
|
||||||
# print(html)
|
# print(html)
|
||||||
self.setHtml(html)
|
self.setHtml(html)
|
||||||
|
|
Loading…
Reference in a new issue