]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131453: Add additional constants to winsound module (GH-131454)
authorAN Long <aisk@users.noreply.github.com>
Thu, 20 Mar 2025 16:35:52 +0000 (01:35 +0900)
committerGitHub <noreply@github.com>
Thu, 20 Mar 2025 16:35:52 +0000 (16:35 +0000)
Doc/library/winsound.rst
Lib/test/test_winsound.py
Misc/NEWS.d/next/Windows/2025-03-19-21-58-16.gh-issue-131453.qQ4J5H.rst [new file with mode: 0644]
PC/winsound.c

index 799fb3dea19501a82b4519b0855fad19fb1ee953..925984c3cdb0cb3dec8e2e6b3c5f4cdbda4cfb7d 100644 (file)
@@ -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.
@@ -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.
+
+   .. versionadded:: 3.14
index 870ab7bd41d8ce7038d5dbcd47ffeb8b75e1b070..9724d830ade0b414b93392679c6ff8f0ce1ac262 100644 (file)
@@ -82,6 +82,18 @@ class MessageBeepTest(unittest.TestCase):
     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)
 
@@ -161,6 +173,15 @@ class PlaySoundTest(unittest.TestCase):
         # 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()
diff --git a/Misc/NEWS.d/next/Windows/2025-03-19-21-58-16.gh-issue-131453.qQ4J5H.rst b/Misc/NEWS.d/next/Windows/2025-03-19-21-58-16.gh-issue-131453.qQ4J5H.rst
new file mode 100644 (file)
index 0000000..4f44c09
--- /dev/null
@@ -0,0 +1 @@
+Some :data:`!SND_*` and :data:`!MB_*` constants are added to :mod:`winsound`.
index 1cb42f2f3bdfc6ce8ca44a0c4d9ab5e2fd38ec98..f485c2c5972b01fe866eae6d113af5740bd90d57 100644 (file)
@@ -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.");
@@ -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