Skip to content

gh-131453: Add missing constants to winsound module #131454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Doc/library/winsound.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ provided by Windows platforms. It includes functions and several constants.
to specify an application-defined sound alias.


.. data:: SND_SENTRY

Triggers a SoundSentry event when the sound is played.

.. versionadded:: 3.14


.. data:: SND_SYNC

The sound is played synchronously. This is the default behavior.

.. versionadded:: 3.14


.. data:: SND_SYSTEM

Assign the sound to the audio session for system notification sounds.

.. versionadded:: 3.14


.. data:: MB_ICONASTERISK

Play the ``SystemDefault`` sound.
Expand All @@ -166,3 +187,30 @@ provided by Windows platforms. It includes functions and several constants.

Play the ``SystemDefault`` sound.


.. data:: MB_ICONERROR

Play the ``SystemHand`` sound.

.. versionadded:: 3.14


.. data:: MB_ICONINFORMATION

Play the ``SystemDefault`` sound.

.. versionadded:: 3.14


.. data:: MB_ICONSTOP

Play the ``SystemHand`` sound.

.. versionadded:: 3.14


.. data:: MB_ICONWARNING

Play the ``SystemExclamation`` sound.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these could all use a ..versionadded:: next

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added!


.. versionadded:: 3.14
21 changes: 21 additions & 0 deletions Lib/test/test_winsound.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def test_hand(self):
def test_question(self):
safe_MessageBeep(winsound.MB_ICONQUESTION)

def test_error(self):
safe_MessageBeep(winsound.MB_ICONERROR)

def test_information(self):
safe_MessageBeep(winsound.MB_ICONINFORMATION)

def test_stop(self):
safe_MessageBeep(winsound.MB_ICONSTOP)

def test_warning(self):
safe_MessageBeep(winsound.MB_ICONWARNING)

def test_keyword_args(self):
safe_MessageBeep(type=winsound.MB_OK)

Expand Down Expand Up @@ -161,6 +173,15 @@ def test_stopasync(self):
# does not raise on systems without a sound card.
winsound.PlaySound(None, winsound.SND_PURGE)

def test_sound_sentry(self):
safe_PlaySound("SystemExit", winsound.SND_ALIAS | winsound.SND_SENTRY)

def test_sound_sync(self):
safe_PlaySound("SystemExit", winsound.SND_ALIAS | winsound.SND_SYNC)

def test_sound_system(self):
safe_PlaySound("SystemExit", winsound.SND_ALIAS | winsound.SND_SYSTEM)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some :data:`!SND_*` and :data:`!MB_*` constants are added to :mod:`winsound`.
12 changes: 11 additions & 1 deletion PC/winsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ PyDoc_STRVAR(sound_module_doc,
"SND_NODEFAULT - Do not play a default beep if the sound can not be found\n"
"SND_NOSTOP - Do not interrupt any sounds currently playing\n" // Raising RuntimeError if needed
"SND_NOWAIT - Return immediately if the sound driver is busy\n" // Without any errors
"SND_APPLICATION - sound is an application-specific alias in the registry."
"SND_APPLICATION - sound is an application-specific alias in the registry.\n"
"SND_SENTRY - Triggers a SoundSentry event when the sound is played.\n"
"SND_SYNC - Play the sound synchronously, default behavior.\n"
"SND_SYSTEM - Assign sound to the audio session for system notification sounds.\n"
"\n"
"Beep(frequency, duration) - Make a beep through the PC speaker.\n"
"MessageBeep(type) - Call Windows MessageBeep.");
Expand Down Expand Up @@ -232,12 +235,19 @@ exec_module(PyObject *module)
ADD_DEFINE(SND_PURGE);
ADD_DEFINE(SND_LOOP);
ADD_DEFINE(SND_APPLICATION);
ADD_DEFINE(SND_SENTRY);
ADD_DEFINE(SND_SYNC);
ADD_DEFINE(SND_SYSTEM);

ADD_DEFINE(MB_OK);
ADD_DEFINE(MB_ICONASTERISK);
ADD_DEFINE(MB_ICONEXCLAMATION);
ADD_DEFINE(MB_ICONHAND);
ADD_DEFINE(MB_ICONQUESTION);
ADD_DEFINE(MB_ICONERROR);
ADD_DEFINE(MB_ICONINFORMATION);
ADD_DEFINE(MB_ICONSTOP);
ADD_DEFINE(MB_ICONWARNING);

#undef ADD_DEFINE

Expand Down
Loading