-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUserInterface.py
More file actions
372 lines (276 loc) · 12.1 KB
/
UserInterface.py
File metadata and controls
372 lines (276 loc) · 12.1 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import sys
from PyQt4 import QtGui, QtCore
from random import shuffle
import pyaudio
import wave
class Window(QtGui.QMainWindow):
#window is just a variable and we make a class
def __init__(self):
super(Window,self).__init__()
self.setGeometry(50,50,700,400)
self.setWindowTitle('Engame')
self.setWindowIcon(QtGui.QIcon('playlogo.png'))
self.home()
def cEvent(self, event): #to add functionality in close button
event.ignore()
self.close_app()
def home(self):
image = QtGui.QLabel(self)
image.setGeometry(5,5, 150, 30)
pixmap = QtGui.QPixmap("logo Engame.png")
pixmap = pixmap.scaledToWidth(150)
image.setPixmap(pixmap)
image.show()
exit_btn=QtGui.QPushButton('X', self)
exit_btn.clicked.connect(self.close_app)
exit_btn.setStyleSheet('background-color: red')
exit_btn.resize(20,20)
exit_btn.move(680,10)
beginner_btn=QtGui.QPushButton('Beginner Level', self)
beginner_btn.clicked.connect(self.callbeginnerWindow)
beginner_btn.setStyleSheet('background-color: #fad123')
beginner_btn.resize(150,70)
beginner_btn.move(50,100)
intermidiate_btn=QtGui.QPushButton('Intermidiate Level', self)
intermidiate_btn.clicked.connect(self.callintermidiateWindow)
intermidiate_btn.setStyleSheet('background-color: cyan')
intermidiate_btn.resize(150,70)
intermidiate_btn.move(275,100)
expert_btn=QtGui.QPushButton('Expert Level', self)
expert_btn.clicked.connect(self.callexpertWindow)
expert_btn.setStyleSheet('background-color: green')
expert_btn.resize(150,70)
expert_btn.move(500,100)
self.show()
def close_app(self): #printing the line after quiting the app
#print('closed...')
choice=QtGui.QMessageBox.question(self, 'Extract!', 'Do you want to quit?',QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if choice==QtGui.QMessageBox.Yes:
sys.exit()
else:
pass
def callbeginnerWindow(self):
self.hide()
self.Window_Begin = BeginnerWindow()
self.Window_Begin.show()
self.Window_Begin.raise_()
def callintermidiateWindow(self):
self.hide()
self.Window_inter = IntermidiateWindow()
self.Window_inter.show()
self.Window_inter.raise_()
def callexpertWindow(self):
self.hide()
self.Window_expert = ExpertWindow()
self.Window_expert.show()
self.Window_expert.raise_()
class BeginnerWindow(QtGui.QMainWindow):
def __init__(self):
super(BeginnerWindow,self).__init__()
self.setGeometry(50,50,700,400)
self.setWindowTitle('Engame')
self.setWindowIcon(QtGui.QIcon('playlogo.png'))
self.buttons_Beginner()
def cEvent(self, event): #to add functionality in close button
event.ignore()
self.close_app()
def buttons_Beginner(self):
image_button = QtGui.QPushButton('', self)
image_button.clicked.connect(self.callmainWindow)
image_button.setIcon(QtGui.QIcon('logo Engame.png'))
image_button.resize(160,40)
image_button.setIconSize(QtCore.QSize(150,30))
exit_btn=QtGui.QPushButton('X', self)
exit_btn.clicked.connect(self.close_app)
exit_btn.setStyleSheet('background-color: red')
exit_btn.resize(20,20)
exit_btn.move(680,10)
speak_btn=QtGui.QPushButton('speak', self)
speak_btn.clicked.connect(self.speak_button)
speak_btn.setStyleSheet('background-color: pink')
speak_btn.resize(100,30)
speak_btn.move(150,300)
self.styleChoice=QtGui.QLabel(self)
next_btn=QtGui.QPushButton('Next Word', self)
next_btn.clicked.connect(self.randomized_bwords)
next_btn.setStyleSheet('background-color: cyan')
next_btn.resize(100,30)
next_btn.move(450,300)
self.words=['Hello', 'Buy', 'Chair', 'cash', 'money']
shuffle(self.words)
self.styleChoice.move(100,50)
self.styleChoice.resize(500,150)
self.styleChoice.setText(self.words[0])
self.styleChoice.setFont(QtGui.QFont("Times", 50, QtGui.QFont.Bold))
self.styleChoice.setStyleSheet('background-color: #fad123')
self.styleChoice.setAlignment(QtCore.Qt.AlignCenter)
self.show()
def speak_button(self):
for i in range(1,2):
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 24000
CHUNK = 1024
RECORD_SECONDS = 3
WAVE_OUTPUT_FILENAME = "audiofiles/file"+str(i)+".wav"
audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT, channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
stream.stop_stream()
stream.close()
audio.terminate()
waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
waveFile.setnchannels(CHANNELS)
waveFile.setsampwidth(audio.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()
def randomized_bwords(self):
if len(self.words)>0:
self.styleChoice.setText(self.words.pop(1))
self.styleChoice.move(100,50)
self.styleChoice.resize(500,150)
self.styleChoice.setFont(QtGui.QFont("Times", 50, QtGui.QFont.Bold))
self.styleChoice.setStyleSheet('background-color: #fad123')
self.styleChoice.setAlignment(QtCore.Qt.AlignCenter)
def close_app(self):
choice=QtGui.QMessageBox.question(self, 'Extract!', 'Do you want to quit?',QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if choice==QtGui.QMessageBox.Yes:
sys.exit()
else:
pass
def callmainWindow(self):
self.hide()
self.Window_main = Window()
self.Window_main.show()
self.Window_main.raise_()
class IntermidiateWindow(QtGui.QMainWindow):
def __init__(self):
super(IntermidiateWindow,self).__init__()
self.setGeometry(50,50,700,400)
self.setWindowTitle('Engame')
self.setWindowIcon(QtGui.QIcon('playlogo.png'))
self.buttons_Intermidiate()
def cEvent(self, event): #to add functionality in close button
event.ignore()
self.close_app()
def buttons_Intermidiate(self):
image_button = QtGui.QPushButton('', self)
image_button.clicked.connect(self.callmainWindow)
image_button.setIcon(QtGui.QIcon('logo Engame.png'))
image_button.resize(160,40)
image_button.setIconSize(QtCore.QSize(150,30))
exit_btn=QtGui.QPushButton('X', self)
exit_btn.clicked.connect(self.close_app)
exit_btn.setStyleSheet('background-color: red')
exit_btn.resize(20,20)
exit_btn.move(680,10)
speak_btn=QtGui.QPushButton('speak', self)
#speak_btn.clicked.connect(self.close_app)
speak_btn.setStyleSheet('background-color: pink')
speak_btn.resize(100,30)
speak_btn.move(150,300)
self.styleChoice=QtGui.QLabel(self)
next_btn=QtGui.QPushButton('Next Word', self)
next_btn.clicked.connect(self.randomized_bwords)
next_btn.setStyleSheet('background-color: cyan')
next_btn.resize(100,30)
next_btn.move(450,300)
self.words=['decoration', 'amused', 'humus', 'acknowledge', 'property']
shuffle(self.words)
self.styleChoice.move(100,50)
self.styleChoice.resize(500,150)
self.styleChoice.setText(self.words[0])
self.styleChoice.setFont(QtGui.QFont("Times", 50, QtGui.QFont.Bold))
self.styleChoice.setStyleSheet('background-color: #fad123')
self.styleChoice.setAlignment(QtCore.Qt.AlignCenter)
self.show()
def randomized_bwords(self):
if len(self.words)>0:
self.styleChoice.setText(self.words.pop(1))
self.styleChoice.move(100,50)
self.styleChoice.resize(500,150)
self.styleChoice.setFont(QtGui.QFont("Times", 50, QtGui.QFont.Bold))
self.styleChoice.setStyleSheet('background-color: #fad123')
self.styleChoice.setAlignment(QtCore.Qt.AlignCenter)
def close_app(self):
choice=QtGui.QMessageBox.question(self, 'Extract!', 'Do you want to quit?',QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if choice==QtGui.QMessageBox.Yes:
sys.exit()
else:
pass
def callmainWindow(self):
self.hide()
self.Window_main = Window()
self.Window_main.show()
self.Window_main.raise_()
class ExpertWindow(QtGui.QMainWindow):
def __init__(self):
super(ExpertWindow,self).__init__()
self.setGeometry(50,50,700,400)
self.setWindowTitle('Engame')
self.setWindowIcon(QtGui.QIcon('playlogo.png'))
self.buttons_Expert()
def cEvent(self, event): #to add functionality in close button
event.ignore()
self.close_app()
def buttons_Expert(self):
image_button = QtGui.QPushButton('', self)
image_button.clicked.connect(self.callmainWindow)
image_button.setIcon(QtGui.QIcon('logo Engame.png'))
image_button.resize(160,40)
image_button.setIconSize(QtCore.QSize(150,30))
exit_btn=QtGui.QPushButton('X', self)
exit_btn.clicked.connect(self.close_app)
exit_btn.setStyleSheet('background-color: red')
exit_btn.resize(20,20)
exit_btn.move(680,10)
speak_btn=QtGui.QPushButton('speak', self)
#speak_btn.clicked.connect(self.close_app)
speak_btn.setStyleSheet('background-color: pink')
speak_btn.resize(100,30)
speak_btn.move(150,300)
self.styleChoice=QtGui.QLabel(self)
next_btn=QtGui.QPushButton('Next Word', self)
next_btn.clicked.connect(self.randomized_bwords)
next_btn.setStyleSheet('background-color: cyan')
next_btn.resize(100,30)
next_btn.move(450,300)
self.words=['mischievous', 'asterisk', 'prerogative', 'frequently', 'nuclear']
shuffle(self.words)
self.styleChoice.move(100,50)
self.styleChoice.resize(500,150)
self.styleChoice.setText(self.words[0])
self.styleChoice.setFont(QtGui.QFont("Times", 50, QtGui.QFont.Bold))
self.styleChoice.setStyleSheet('background-color: #fad123')
self.styleChoice.setAlignment(QtCore.Qt.AlignCenter)
self.show()
def randomized_bwords(self):
if len(self.words)>0:
self.styleChoice.setText(self.words.pop(1))
self.styleChoice.move(100,50)
self.styleChoice.resize(500,150)
self.styleChoice.setFont(QtGui.QFont("Times", 50, QtGui.QFont.Bold))
self.styleChoice.setStyleSheet('background-color: #fad123')
self.styleChoice.setAlignment(QtCore.Qt.AlignCenter)
def close_app(self):
choice=QtGui.QMessageBox.question(self, 'Extract!', 'Do you want to quit?',QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if choice==QtGui.QMessageBox.Yes:
sys.exit()
else:
pass
def callmainWindow(self):
self.hide()
self.Window_main = Window()
self.Window_main.show()
self.Window_main.raise_()
def run():
app=QtGui.QApplication(sys.argv)
GUI= Window()
sys.exit(app.exec_())
run()