@@ -407,95 +407,96 @@ def _play_sound(self, sound: Optional[Dict[str, Any]]) -> bool:
407
407
self ._last_time = sound_time
408
408
return True
409
409
410
+ def play_sound_type (self , sound_type : str ) -> 'Sound' :
411
+ """
412
+ Play a sound based on its type.
413
+
414
+ :param sound_type: The type of sound to play.
415
+ :return: Self reference.
416
+ """
417
+ if sound_type in self ._sound :
418
+ self ._play_sound (self ._sound [sound_type ])
419
+ return self
420
+
410
421
def play_click_mouse (self ) -> 'Sound' :
411
422
"""
412
423
Play click mouse sound.
413
424
414
425
:return: Self reference
415
426
"""
416
- self ._play_sound (self ._sound [SOUND_TYPE_CLICK_MOUSE ])
417
- return self
427
+ return self .play_sound_type (SOUND_TYPE_CLICK_MOUSE )
418
428
419
429
def play_click_touch (self ) -> 'Sound' :
420
430
"""
421
431
Play click touch sound.
422
432
423
433
:return: Self reference
424
434
"""
425
- self ._play_sound (self ._sound [SOUND_TYPE_CLICK_TOUCH ])
426
- return self
435
+ return self .play_sound_type (SOUND_TYPE_CLICK_TOUCH )
427
436
428
437
def play_error (self ) -> 'Sound' :
429
438
"""
430
439
Play error sound.
431
440
432
441
:return: Self reference
433
442
"""
434
- self ._play_sound (self ._sound [SOUND_TYPE_ERROR ])
435
- return self
443
+ return self .play_sound_type (SOUND_TYPE_ERROR )
436
444
437
445
def play_event (self ) -> 'Sound' :
438
446
"""
439
447
Play event sound.
440
448
441
449
:return: Self reference
442
450
"""
443
- self ._play_sound (self ._sound [SOUND_TYPE_EVENT ])
444
- return self
451
+ return self .play_sound_type (SOUND_TYPE_EVENT )
445
452
446
453
def play_event_error (self ) -> 'Sound' :
447
454
"""
448
455
Play event error sound.
449
456
450
457
:return: Self reference
451
458
"""
452
- self ._play_sound (self ._sound [SOUND_TYPE_EVENT_ERROR ])
453
- return self
459
+ return self .play_sound_type (SOUND_TYPE_EVENT_ERROR )
454
460
455
461
def play_key_add (self ) -> 'Sound' :
456
462
"""
457
463
Play key addition sound.
458
464
459
465
:return: Self reference
460
466
"""
461
- self ._play_sound (self ._sound [SOUND_TYPE_KEY_ADDITION ])
462
- return self
467
+ return self .play_sound_type (SOUND_TYPE_KEY_ADDITION )
463
468
464
469
def play_key_del (self ) -> 'Sound' :
465
470
"""
466
471
Play key deletion sound.
467
472
468
473
:return: Self reference
469
474
"""
470
- self ._play_sound (self ._sound [SOUND_TYPE_KEY_DELETION ])
471
- return self
475
+ return self .play_sound_type (SOUND_TYPE_KEY_DELETION )
472
476
473
477
def play_open_menu (self ) -> 'Sound' :
474
478
"""
475
479
Play open Menu sound.
476
480
477
481
:return: Self reference
478
482
"""
479
- self ._play_sound (self ._sound [SOUND_TYPE_OPEN_MENU ])
480
- return self
483
+ return self .play_sound_type (SOUND_TYPE_OPEN_MENU )
481
484
482
485
def play_close_menu (self ) -> 'Sound' :
483
486
"""
484
487
Play close Menu sound.
485
488
486
489
:return: Self reference
487
490
"""
488
- self ._play_sound (self ._sound [SOUND_TYPE_CLOSE_MENU ])
489
- return self
491
+ return self .play_sound_type (SOUND_TYPE_CLOSE_MENU )
490
492
491
493
def play_widget_selection (self ) -> 'Sound' :
492
494
"""
493
495
Play widget selection sound.
494
496
495
497
:return: Self reference
496
498
"""
497
- self ._play_sound (self ._sound [SOUND_TYPE_WIDGET_SELECTION ])
498
- return self
499
+ return self .play_sound_type (SOUND_TYPE_WIDGET_SELECTION )
499
500
500
501
def stop (self ) -> 'Sound' :
501
502
"""
@@ -558,3 +559,20 @@ def get_channel_info(self) -> Dict[str, Any]:
558
559
data ['sound' ] = channel .get_sound ()
559
560
data ['volume' ] = channel .get_volume ()
560
561
return data
562
+
563
+ def set_sound_volume (self , sound_type : str , volume : float ) -> bool :
564
+ """
565
+ Set the volume of a specific sound type.
566
+
567
+ :param sound_type: Sound type
568
+ :param volume: Volume of the sound, from ``0.0`` to ``1.0``
569
+ :return: ``True`` if the volume was set, ``False`` otherwise
570
+ """
571
+ if sound_type not in SOUND_TYPES :
572
+ return False
573
+ sound_data = self ._sound .get (sound_type )
574
+ if sound_data :
575
+ sound_data ['file' ].set_volume (volume )
576
+ sound_data ['volume' ] = volume
577
+ return True
578
+ return False
0 commit comments