Skip to content

Commit

Permalink
Remove winsound.PlaySound from NVDA (#17543)
Browse files Browse the repository at this point in the history
Summary of the issue:
NVDA currently uses winsound.PlaySound in a few places, which is part of the winmm API.

Description of user facing changes
None.

Description of development approach
Replaced these calls with calls to winsound.MessageBeep, as they are all calls to play system sounds.
  • Loading branch information
SaschaCowley authored Dec 30, 2024
1 parent 400facc commit 4bab722
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ logger-objects = ["logHandler.log"]
"sconstruct" = ["F821"]
"*sconscript" = ["F821"]

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"winsound.PlaySound".msg= "PlaySound uses winmm, which is deprecated in favor of the Windows core audio APIs."

[tool.licensecheck]
using = "requirements:requirements.txt"
only_licenses = ["BSD", "MIT", "Python", "LGPLV3+", "Apache"]
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/window/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ def event_typedCharacter(self, ch):
and controlTypes.State.UNLOCKED not in self.states
and controlTypes.State.PROTECTED in self.parent.states
):
winsound.PlaySound("Default", winsound.SND_ALIAS | winsound.SND_NOWAIT | winsound.SND_ASYNC)
winsound.MessageBeep()
return
super(ExcelCell, self).event_typedCharacter(ch)

Expand Down
2 changes: 1 addition & 1 deletion source/browseMode.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def _get_shouldTrapNonCommandGestures(self):
return config.conf["virtualBuffers"]["trapNonCommandGestures"]

def script_trapNonCommandGesture(self, gesture):
winsound.PlaySound("default", 1)
winsound.MessageBeep()

singleLetterNavEnabled = True #: Whether single letter navigation scripts should be active (true) or if these letters should fall to the application.

Expand Down
5 changes: 1 addition & 4 deletions source/logHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,7 @@ def emit(self, record):
class FileHandler(logging.FileHandler):
def handle(self, record):
if record.levelno >= logging.CRITICAL:
try:
winsound.PlaySound("SystemHand", winsound.SND_ALIAS | winsound.SND_ASYNC)
except: # noqa: E722
pass
winsound.MessageBeep(winsound.MB_ICONHAND)
elif record.levelno >= logging.ERROR and shouldPlayErrorSound():
getOnErrorSoundRequested().notify()
return super().handle(record)
Expand Down

0 comments on commit 4bab722

Please sign in to comment.