Skip to content

Commit

Permalink
added looping option to event sound effects
Browse files Browse the repository at this point in the history
  • Loading branch information
bogind committed Aug 8, 2024
1 parent c8cd6f0 commit 9501493
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 37 deletions.
72 changes: 44 additions & 28 deletions qgs_sound_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import json
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, QTimer, QDateTime, QUrl, QMetaMethod
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QCheckBox, QToolButton, QComboBox, QDoubleSpinBox
from qgis.PyQt.QtWidgets import QAction, QCheckBox, QToolButton, QComboBox, QDoubleSpinBox, QSpinBox
from qgis.gui import QgsGui
from qgis.core import QgsSettings, QgsApplication, QgsMessageLog, Qgis
from PyQt5.QtMultimedia import QSoundEffect
Expand Down Expand Up @@ -166,8 +166,10 @@ def configure(self):
eventConfig = self.config.get(event, {})
soundID = eventConfig.get('sound', 'success')
volume = eventConfig.get('volume', 1.0)
loops = eventConfig.get('loops', 0)
self.bound_sounds[event].setSource(self.sound_effects[soundID].source())
self.bound_sounds[event].setVolume(volume)
self.bound_sounds[event].setLoopCount(loops)
except Exception as e:
self.mb.pushCritical('Error configuring sound effects plugin', str(e))

Expand Down Expand Up @@ -475,36 +477,48 @@ def configure_settings_window(self):
self.volume_ids = ['processingSuccessVolume','processingFailureVolume','zoomInVolume',
'zoomOutVolume','layersChangedVolume','renderCompleteVolume','renderErrorOccurredVolume',
'mapExportCompleteVolume','mapExportErrorVolume','printLayoutExportSuccessVolume']
self.loop_ids = ['processingSuccessLoopSpinbox','processingFailureLoopSpinbox','zoomInLoopSpinbox',
'zoomOutLoopSpinbox','layersChangedLoopSpinbox','renderCompleteLoopSpinbox','renderErrorOccurredLoopSpinbox',
'mapExportCompleteLoopSpinbox','mapExportErrorLoopSpinbox','printLayoutExportSuccessLoopSpinbox']


for i in range(0, len(self.checkbox_ids)):
eventID = self.objectid_to_eventid(self.checkbox_ids[i])
eventConfig = self.config.get(eventID, {})
try:
eventID = self.objectid_to_eventid(self.checkbox_ids[i])
eventConfig = self.config.get(eventID, {})

checkbox_id = self.checkbox_ids[i]
checkbox = self.config_window.findChild(QCheckBox, checkbox_id)
checked = eventConfig.get('enabled', False)
checkbox.setChecked(checked)
checkbox.stateChanged.connect(self.make_toggle_event(checkbox_id))
checkbox_id = self.checkbox_ids[i]
checkbox = self.config_window.findChild(QCheckBox, checkbox_id)
checked = eventConfig.get('enabled', False)
checkbox.setChecked(checked)
checkbox.stateChanged.connect(self.make_toggle_event(checkbox_id))

combobox_id = self.combobox_ids[i]
comboBox = self.config_window.findChild(QComboBox, combobox_id)
for j in self.sounds_config.keys():
comboBox.addItem(self.sounds_config[j]['label'], j)
combobox_id = self.combobox_ids[i]
comboBox = self.config_window.findChild(QComboBox, combobox_id)
for j in self.sounds_config.keys():
comboBox.addItem(self.sounds_config[j]['label'], j)

eventSoundIndex = eventConfig.get('sound_index', 0)

comboBox.setCurrentIndex(eventSoundIndex)
comboBox.currentIndexChanged.connect(self.make_set_event_sound(combobox_id))

test_button_id = self.test_button_ids[i]
test_button = self.config_window.findChild(QToolButton, test_button_id)
test_button.clicked.connect(self.make_test_sound(combobox_id))
eventSoundIndex = eventConfig.get('sound_index', 0)
comboBox.setCurrentIndex(eventSoundIndex)
comboBox.currentIndexChanged.connect(self.make_set_event_sound(combobox_id))
test_button_id = self.test_button_ids[i]
test_button = self.config_window.findChild(QToolButton, test_button_id)
test_button.clicked.connect(self.make_test_sound(combobox_id))

volume_id = self.volume_ids[i]
volume = self.config_window.findChild(QDoubleSpinBox, volume_id)
configVolume = eventConfig.get('volume', 1.0)
volume.setValue(configVolume)
volume_id = self.volume_ids[i]
volume = self.config_window.findChild(QDoubleSpinBox, volume_id)
configVolume = eventConfig.get('volume', 1.0)
volume.setValue(configVolume)

loop_id = self.loop_ids[i]
loop = self.config_window.findChild(QSpinBox, loop_id)
configLoop = eventConfig.get('loops', 0)
loop.setValue(configLoop)
except Exception as e:
QgsMessageLog.logMessage('Error configuring settings window: {}'.format(str(e)), MESSAGE_CATEGORY, Qgis.Critical)
QgsMessageLog.logMessage(str(e.__traceback__), MESSAGE_CATEGORY, Qgis.Critical)

self.config_window.saveSettingsButton.clicked.connect(self.save_settings)
self.config_window.cancelChangesButton.clicked.connect(self.config_window.hide)
Expand Down Expand Up @@ -536,7 +550,7 @@ def objectid_to_eventid(objid):
def restore_settings(self):
try:
self.enabled = self.get_setting('enabled', True)
default_config = '{"layersChanged": {"enabled": false, "sound": "woodenfrog", "sound_index": 10, "volume": 1.0}, "processingFailure": {"enabled": true, "sound": "fail", "sound_index": 0, "volume": 1.0}, "processingSuccess": {"enabled": true, "sound": "success", "sound_index": 1, "volume": 1.0}, "renderComplete": {"enabled": false, "sound": "fail", "sound_index": 0, "volume": 1.0}, "renderErrorOccurred": {"enabled": false, "sound": "fail", "sound_index": 0, "volume": 1.0}, "zoomIn": {"enabled": false, "sound": "synth-glide", "sound_index": 6, "volume": 1.0}, "zoomOut": {"enabled": false, "sound": "synth-glide", "sound_index": 6, "volume": 1.0}, "mapExportComplete": {"enabled": false, "sound": "good_answer_harp", "sound_index": 12, "volume": 1.0}, "mapExportError": {"enabled": false, "sound": "sad_trombone", "sound_index": 14, "volume": 1.0}, "printLayoutExportSuccess": {"enabled": false, "sound": "tada", "sound_index": 13, "volume": 1.0}}'
default_config = '{"layersChanged": {"enabled": false, "sound": "woodenfrog", "sound_index": 10, "volume": 1.0, "loops": 0}, "processingFailure": {"enabled": true, "sound": "fail", "sound_index": 0, "volume": 1.0, "loops": 0}, "processingSuccess": {"enabled": true, "sound": "success", "sound_index": 1, "volume": 1.0, "loops": 0}, "renderComplete": {"enabled": false, "sound": "fail", "sound_index": 0, "volume": 1.0, "loops": 0}, "renderErrorOccurred": {"enabled": false, "sound": "fail", "sound_index": 0, "volume": 1.0, "loops": 0}, "zoomIn": {"enabled": false, "sound": "synth-glide", "sound_index": 6, "volume": 1.0, "loops": 0}, "zoomOut": {"enabled": false, "sound": "synth-glide", "sound_index": 6, "volume": 1.0, "loops": 0}, "mapExportComplete": {"enabled": false, "sound": "good_answer_harp", "sound_index": 12, "volume": 1.0, "loops": 0}, "mapExportError": {"enabled": false, "sound": "sad_trombone", "sound_index": 14, "volume": 1.0, "loops": 0}, "printLayoutExportSuccess": {"enabled": false, "sound": "tada", "sound_index": 13, "volume": 1.0}}'
config = json.loads(self.get_setting('config', default_config))
return config
except Exception as e:
Expand All @@ -556,16 +570,18 @@ def save_settings(self):
combobox_id = self.combobox_ids[i]
comboBox = self.config_window.findChild(QComboBox, combobox_id)



volume_id = self.volume_ids[i]
volume = self.config_window.findChild(QDoubleSpinBox, volume_id)

loop_id = self.loop_ids[i]
loop = self.config_window.findChild(QSpinBox, loop_id)

event = {
'enabled': checked,
'sound': comboBox.currentData(),
'sound_index': comboBox.currentIndex(),
'volume': volume.value()
'volume': volume.value(),
'loops': loop.value()
}
self.config[eventID] = event

Expand Down
61 changes: 52 additions & 9 deletions qgs_sound_effects_configuration_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>484</width>
<width>518</width>
<height>461</height>
</rect>
</property>
Expand Down Expand Up @@ -50,7 +50,7 @@
<widget class="QPushButton" name="saveSettingsButton">
<property name="geometry">
<rect>
<x>310</x>
<x>350</x>
<y>420</y>
<width>75</width>
<height>23</height>
Expand All @@ -63,7 +63,7 @@
<widget class="QPushButton" name="cancelChangesButton">
<property name="geometry">
<rect>
<x>390</x>
<x>430</x>
<y>420</y>
<width>75</width>
<height>23</height>
Expand All @@ -77,9 +77,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>461</width>
<height>324</height>
<y>63</y>
<width>491</width>
<height>341</height>
</rect>
</property>
<layout class="QGridLayout" name="eventsGrid">
Expand Down Expand Up @@ -252,9 +252,6 @@
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QComboBox" name="layersChangedComboBox"/>
</item>
<item row="10" column="3">
<widget class="QToolButton" name="printLayoutExportSuccessTestButton">
<property name="text">
Expand All @@ -266,6 +263,9 @@
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QComboBox" name="layersChangedComboBox"/>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="mapExportErrorCheckBox">
<property name="text">
Expand Down Expand Up @@ -484,6 +484,49 @@
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QSpinBox" name="processingSuccessLoopSpinbox"/>
</item>
<item row="0" column="5">
<widget class="QLabel" name="loopsTitle">
<property name="toolTip">
<string>0 or 1 means the sound will be played only once</string>
</property>
<property name="whatsThis">
<string>0 or 1 means the sound will be played only once</string>
</property>
<property name="text">
<string>Loops</string>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QSpinBox" name="processingFailureLoopSpinbox"/>
</item>
<item row="3" column="5">
<widget class="QSpinBox" name="zoomInLoopSpinbox"/>
</item>
<item row="4" column="5">
<widget class="QSpinBox" name="zoomOutLoopSpinbox"/>
</item>
<item row="5" column="5">
<widget class="QSpinBox" name="layersChangedLoopSpinbox"/>
</item>
<item row="6" column="5">
<widget class="QSpinBox" name="renderCompleteLoopSpinbox"/>
</item>
<item row="7" column="5">
<widget class="QSpinBox" name="renderErrorOccurredLoopSpinbox"/>
</item>
<item row="8" column="5">
<widget class="QSpinBox" name="mapExportCompleteLoopSpinbox"/>
</item>
<item row="9" column="5">
<widget class="QSpinBox" name="mapExportErrorLoopSpinbox"/>
</item>
<item row="10" column="5">
<widget class="QSpinBox" name="printLayoutExportSuccessLoopSpinbox"/>
</item>
</layout>
</widget>
</widget>
Expand Down

0 comments on commit 9501493

Please sign in to comment.