2 Commits 58527e9901 ... e011b2875c

Author SHA1 Message Date
  Maarten van den Berg e011b2875c piket_client: Remove dependency on `simpleaudio` 3 years ago
  Maarten van den Berg 4e9ae6afab piket_client: Remove use of `simpleaudio` 3 years ago
4 changed files with 12 additions and 26 deletions
  1. 11 7
      piket_client/gui.py
  2. 0 1
      piket_client/shell.nix
  3. 0 17
      piket_client/sound.py
  4. 1 1
      setup.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 - 1
piket_client/shell.nix

9
     pyside2
9
     pyside2
10
     qdarkstyle
10
     qdarkstyle
11
     requests
11
     requests
12
-    simpleaudio
13
     dbus-python
12
     dbus-python
14
 
13
 
15
     raven
14
     raven

+ 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. """

+ 1 - 1
setup.py

25
     extras_require={
25
     extras_require={
26
         "dev": ["black", "pylint"],
26
         "dev": ["black", "pylint"],
27
         "server": ["Flask", "SQLAlchemy", "Flask-SQLAlchemy", "alembic", "uwsgi"],
27
         "server": ["Flask", "SQLAlchemy", "Flask-SQLAlchemy", "alembic", "uwsgi"],
28
-        "client": ["PySide2", "qdarkstyle>=2.6.0", "requests", "simpleaudio"],
28
+        "client": ["PySide2", "qdarkstyle>=2.6.0", "requests"],
29
         "osk": ["dbus-python"],
29
         "osk": ["dbus-python"],
30
         "sentry": ["raven"],
30
         "sentry": ["raven"],
31
     },
31
     },