Browse Source

piket_client: Remove use of `simpleaudio`

Maarten van den Berg 3 years ago
parent
commit
4e9ae6afab
2 changed files with 11 additions and 24 deletions
  1. 11 7
      piket_client/gui.py
  2. 0 17
      piket_client/sound.py

+ 11 - 7
piket_client/gui.py

25
     QWidget,
25
     QWidget,
26
 )
26
 )
27
 from PySide2.QtGui import QIcon
27
 from PySide2.QtGui import QIcon
28
-from PySide2.QtCore import QObject, QSize, Qt, Signal, Slot
28
+from PySide2.QtMultimedia import QSoundEffect
29
+from PySide2.QtCore import QObject, QSize, Qt, Signal, Slot, QUrl
29
 
30
 
30
 # pylint: enable=E0611
31
 # pylint: enable=E0611
31
 
32
 
34
 except ImportError:
35
 except ImportError:
35
     dbus = None
36
     dbus = None
36
 
37
 
37
-from piket_client.sound import PLOP_WAVE, UNDO_WAVE
38
 from piket_client.model import (
38
 from piket_client.model import (
39
     Person,
39
     Person,
40
     ConsumptionType,
40
     ConsumptionType,
46
 
46
 
47
 LOG = logging.getLogger(__name__)
47
 LOG = logging.getLogger(__name__)
48
 
48
 
49
-
50
-def plop() -> None:
51
-    """ Asynchronously play the plop sound. """
52
-    PLOP_WAVE.play()
49
+PLOP_WAVE = QSoundEffect()
50
+UNDO_WAVE = QSoundEffect()
53
 
51
 
54
 
52
 
55
 class NameButton(QPushButton):
53
 class NameButton(QPushButton):
97
         LOG.debug("Button clicked.")
95
         LOG.debug("Button clicked.")
98
         result = self.person.add_consumption(self.active_id)
96
         result = self.person.add_consumption(self.active_id)
99
         if result:
97
         if result:
100
-            plop()
98
+            PLOP_WAVE.play()
101
             self.setText(self.current_label)
99
             self.setText(self.current_label)
102
             self.consumption_created.emit(result)
100
             self.consumption_created.emit(result)
103
         else:
101
         else:
423
     # Set dark theme
421
     # Set dark theme
424
     app.setStyleSheet(qdarkstyle.load_stylesheet_pyside2())
422
     app.setStyleSheet(qdarkstyle.load_stylesheet_pyside2())
425
 
423
 
424
+    # Load sounds
425
+    global PLOP_WAVE, UNDO_WAVE
426
+    sounds_dir = os.path.join(os.path.dirname(__file__), "sounds")
427
+    PLOP_WAVE.setSource(QUrl.fromLocalFile(os.path.join(sounds_dir, "plop.wav")))
428
+    UNDO_WAVE.setSource(QUrl.fromLocalFile(os.path.join(sounds_dir, "undo.wav")))
429
+
426
     # Enlarge font size
430
     # Enlarge font size
427
     font = app.font()
431
     font = app.font()
428
     size = font.pointSize()
432
     size = font.pointSize()

+ 0 - 17
piket_client/sound.py

1
-"""
2
-Provides functions related to playing sounds.
3
-"""
4
-
5
-import os
6
-
7
-import simpleaudio as sa
8
-
9
-
10
-SOUNDS_DIR = os.path.join(os.path.dirname(__file__), "sounds")
11
-""" Contains the absolute path to the sounds directory. """
12
-
13
-PLOP_WAVE = sa.WaveObject.from_wave_file(os.path.join(SOUNDS_DIR, "plop.wav"))
14
-""" SimpleAudio WaveObject containing the plop sound. """
15
-
16
-UNDO_WAVE = sa.WaveObject.from_wave_file(os.path.join(SOUNDS_DIR, "undo.wav"))
17
-""" SimpleAudio WaveObject containing the undo sound. """