forked from rose-jinyang/LinVAM
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsoundactioneditwnd.py
164 lines (129 loc) · 5.06 KB
/
soundactioneditwnd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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()