1
0
mirror of https://github.com/aidygus/LinVAM.git synced 2024-11-23 09:18:04 +11:00
LinVAM/soundactioneditwnd.py
smirgol 7b4ae4d3e7 Fixes & implementation of playing audio files. See changes.md for details.
- hacked profileexcutor to reload command list when changing it. it did not do that,
  so changing the profile had no effect at all.
- hacked profileexecutor to somewhat make use of "Enable listening".
  It was an option without functionality at all until now.
- created new directory 'voicepacks', copy HCS voicepacks here
- new command to play a sound
- new gui to select sounds from voicepacks
- created playsound class that reads voicepack files and plays audio files with ffplay
- added alternate keypress handling using xdotool, which won't require root privileges.
  might not work for any key existing in profiles, as some need to be remapped. added some remappings to profileexecutor.py pressKey()
- added basic command line argument reading to set some configs. right now there:
  -noroot - will enable xdotool usage for keypresses
  -xdowindowid <windowid> - will send keypresses to this window only, makes it more relyable when window is not focused for any reason
- added auto-detection of Elite Dangerous client window id if -noroot is used and no -xdowindowid is supplied.
  for this to work, start this script AFTER the client is already running.
- monkey-wrenched a volume slider to the main window
- added confirmation dialog for removing a profile (!)
- copy existing profile. added a copy button to the main menu
- properly shutdown audio recording stream
- updated gitignore to ignore audio files
2020-05-16 20:51:24 +02:00

164 lines
5.1 KiB
Python

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import re
import os
from ui_soundactioneditwnd import Ui_SoundSelect
class SoundActionEditWnd(QDialog):
def __init__(self, p_sounds, p_soundAction = None, p_parent = None):
super().__init__(p_parent)
self.ui = Ui_SoundSelect()
self.ui.setupUi(self)
if p_sounds == None:
return
self.p_sounds = p_sounds
self.selectedVoicepack = False
self.selectedCategory = False
self.selectedFile = False
self.ui.buttonOkay.clicked.connect(self.slotOK)
self.ui.buttonCancel.clicked.connect(super().reject)
self.ui.buttonPlaySound.clicked.connect(self.playSound)
self.ui.buttonStopSound.clicked.connect(self.stopSound)
self.ui.buttonOkay.setEnabled(False)
# restore stuff when editing
if not p_soundAction == None:
self.selectedVoicepack = p_soundAction['pack']
self.selectedCategory = p_soundAction['cat']
self.selectedFile = p_soundAction['file']
self.ui.buttonOkay.setEnabled(True)
self.listVoicepacks_model = QStandardItemModel()
self.ui.listVoicepacks.setModel(self.listVoicepacks_model)
self.ui.listVoicepacks.clicked.connect(self.onVoicepackSelect)
self.listCategories_model = QStandardItemModel()
self.ui.listCategories.setModel(self.listCategories_model)
self.ui.listCategories.clicked.connect(self.onCategorySelect)
self.listFiles_model = QStandardItemModel()
self.ui.listFiles.setModel(self.listFiles_model)
self.ui.listFiles.clicked.connect(self.onFileSelect)
self.ui.listFiles.doubleClicked.connect(self.selectAndPlay)
s = sorted(p_sounds.m_sounds)
for v in s:
item = QStandardItem(v)
self.listVoicepacks_model.appendRow(item)
self.ui.filterCategories.textChanged.connect(self.populateCategories)
self.ui.filterFiles.textChanged.connect(self.populateFiles)
self.populateCategories(False)
self.populateFiles(False)
# when editing, select old entries
if not self.selectedVoicepack == False:
item = self.listVoicepacks_model.findItems(self.selectedVoicepack)
if len(item) > 0:
index = self.listVoicepacks_model.indexFromItem(item[0])
self.ui.listVoicepacks.setCurrentIndex(index)
if not self.selectedCategory == False:
item = self.listCategories_model.findItems(self.selectedCategory)
if len(item) > 0:
index = self.listCategories_model.indexFromItem(item[0])
self.ui.listCategories.setCurrentIndex(index)
if not self.selectedFile == False:
item = self.listFiles_model.findItems(self.selectedFile)
if len(item) > 0:
index = self.listFiles_model.indexFromItem(item[0])
self.ui.listFiles.setCurrentIndex(index)
def slotOK(self):
self.m_soundAction = {'name': 'play sound', 'pack': self.selectedVoicepack, 'cat' : self.selectedCategory, 'file' : self.selectedFile}
super().accept()
def slotCancel(self):
super().reject()
def onVoicepackSelect(self):
index = self.ui.listVoicepacks.currentIndex()
itemText = index.data()
self.selectedVoicepack = itemText
self.populateCategories()
self.ui.buttonOkay.setEnabled(False)
self.ui.buttonPlaySound.setEnabled(False)
def onCategorySelect(self):
index = self.ui.listCategories.currentIndex()
itemText = index.data()
self.selectedCategory = itemText
self.populateFiles()
self.ui.buttonOkay.setEnabled(False)
self.ui.buttonPlaySound.setEnabled(False)
def onFileSelect(self):
index = self.ui.listFiles.currentIndex()
itemText = index.data()
self.selectedFile = itemText
self.ui.buttonOkay.setEnabled(True)
self.ui.buttonPlaySound.setEnabled(True)
def selectAndPlay(self):
self.onFileSelect()
self.playSound()
def populateCategories(self, reset = True):
if self.selectedVoicepack == False:
return
if reset == True:
self.listCategories_model.removeRows( 0, self.listCategories_model.rowCount() )
self.listFiles_model.removeRows( 0, self.listFiles_model.rowCount() )
self.selectedCategory = False
self.selectedFile = False
filter_categories = self.ui.filterCategories.toPlainText()
if len(filter_categories) == 0:
filter_categories = None
s = sorted(self.p_sounds.m_sounds[self.selectedVoicepack])
for v in s:
if not filter_categories == None:
if not re.search(filter_categories, v, re.IGNORECASE):
continue
item = QStandardItem(v)
self.listCategories_model.appendRow(item)
def populateFiles(self, reset = True):
if self.selectedVoicepack == False or self.selectedCategory == False:
return
if reset == True:
self.listFiles_model.removeRows( 0, self.listFiles_model.rowCount() )
self.selectedFile = False
filter_files = self.ui.filterFiles.toPlainText()
if len(filter_files) == 0:
filter_files = None
s = sorted(self.p_sounds.m_sounds[self.selectedVoicepack][self.selectedCategory])
for v in s:
if not filter_files == None:
if not re.search(filter_files, v, re.IGNORECASE):
continue
item = QStandardItem(v)
self.listFiles_model.appendRow(item)
def playSound(self):
sound_file = './voicepacks/' + self.selectedVoicepack + '/' + self.selectedCategory + '/' + self.selectedFile
self.p_sounds.play(sound_file)
def stopSound(self):
self.p_sounds.stop()