瀏覽代碼

piket_client: Remove use of `simpleaudio`

Maarten van den Berg 3 年之前
父節點
當前提交
4e9ae6afab
共有 2 個文件被更改,包括 11 次插入24 次删除
  1. 11 7
      piket_client/gui.py
  2. 0 17
      piket_client/sound.py

+ 11 - 7
piket_client/gui.py

@@ -25,7 +25,8 @@ from PySide2.QtWidgets import (
25 25
     QWidget,
26 26
 )
27 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 31
 # pylint: enable=E0611
31 32
 
@@ -34,7 +35,6 @@ try:
34 35
 except ImportError:
35 36
     dbus = None
36 37
 
37
-from piket_client.sound import PLOP_WAVE, UNDO_WAVE
38 38
 from piket_client.model import (
39 39
     Person,
40 40
     ConsumptionType,
@@ -46,10 +46,8 @@ import piket_client.logger
46 46
 
47 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 53
 class NameButton(QPushButton):
@@ -97,7 +95,7 @@ class NameButton(QPushButton):
97 95
         LOG.debug("Button clicked.")
98 96
         result = self.person.add_consumption(self.active_id)
99 97
         if result:
100
-            plop()
98
+            PLOP_WAVE.play()
101 99
             self.setText(self.current_label)
102 100
             self.consumption_created.emit(result)
103 101
         else:
@@ -423,6 +421,12 @@ def main() -> None:
423 421
     # Set dark theme
424 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 430
     # Enlarge font size
427 431
     font = app.font()
428 432
     size = font.pointSize()

+ 0 - 17
piket_client/sound.py

@@ -1,17 +0,0 @@
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. """