-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo.py
322 lines (274 loc) · 11.1 KB
/
video.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
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
# Developed by Alvaro Hurtado
# a.hurtado.bo@gmail.com
# Oruro, Bolivia
import sys
import multiprocessing
from PyQt4 import QtGui, QtCore, QtTest
from PyQt4.phonon import Phonon
from time import sleep, strftime
try:
from gpio import MembraneMatrix
except:
pass
class GUIParalela():
"""
La presente clase representa una interfaz visual de alarma Activada/Desactivada
Su función principal es la de gestionar la activación y desactivación de la alarma.
Al Desactivar la alarma Identifica a la persona ingresando
Al Activar la alarma se regresa al estado inicial
Presionar ESC para cerrar el GUI
"""
myQueue = multiprocessing.Queue()
try:
miTeclado = MembraneMatrix()
except:
pass
valorActual = ''
def __init__(self,fullScreen=True,lcd = False):
"""
Constructor de la clase tiene dos opciones a activar o desactivar:
bool simulation = Falso por defecto, corre una simulación de la activación y desactivación de la alarma por un minuto con datos simulados en forma de variable de clase
bool fullScreen = True por defecto, corre la GUI en modo de pantalla total, lo que se espera en su funcionamiento normal
"""
self.process = multiprocessing.Process(target=self._correrGui,args=(fullScreen,lcd))
self.process.start()
def _correrGui(self,fullScreen,lcd):
"""
Metodo auxiliar para paralelizar la interfaz
"""
app = QtGui.QApplication(sys.argv)
interfaz = InterfazVideo(GUIParalela.myQueue,pantallaTotal=fullScreen,lcd=lcd)
sys.exit(app.exec_())
def __del__(self):
self.process.join()
class PopUp(QtGui.QWidget): #QWidget #QMainWindow
"""
Pop up
"""
def __init__(self):
#super(InterfazPreguntas, self).__init__(parent)
QtGui.QWidget.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
# Parámetros constantes:
self.titulo = 'Revisando'
self.etiqueta = QtGui.QLabel('Correcta')
self.imagen = QtGui.QLabel(self)
self.imagenCorrecta = QtGui.QPixmap('./imagenes/pensando.png')
self.miLayout = QtGui.QVBoxLayout()
self.miLayout.addWidget(self.imagen)
self.miLayout.addWidget(self.etiqueta)
self.miLayout.setAlignment(self.etiqueta, QtCore.Qt.AlignHCenter)
self.setLayout(self.miLayout)
self.setWindowTitle(self.titulo)
resolution = QtGui.QDesktopWidget().screenGeometry()
self.move((resolution.width() / 2) - (self.frameSize().width() / 2),(resolution.height() / 2) - (self.frameSize().height() / 2))
def showEspera(self):
self.etiqueta.setText('Veamos .....')
self.imagen.setPixmap(self.imagenCorrecta)
self.show()
QtTest.QTest.qWait(2000)
self.hide()
class InterfazVideo(QtGui.QWidget): #QWidget #QMainWindow
"""
Interfaz gráfica visual
"""
def __init__(self,fila,pantallaTotal = True,lcd = False,parent=None):
#super(InterfazVideo, self).__init__(parent)
QtGui.QWidget.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
# Parámetros constantes:
self.titulo = 'Scape Room'
self.thread = ThreadClass()
self.video1 = Phonon.VideoPlayer(self)
self.video2 = Phonon.VideoPlayer(self)
self.thread.start()
self.miPopUp = PopUp()
self.myLcd = lcd
self.queue = fila
self.passwords = []
with open('./database/key', 'r') as f:
readData = f.read()
for password in readData.split('\n'):
if len(password)>4:
self.passwords.append(password)
# Clases auxiliares:
self.initUI()
self.connect(self.thread,QtCore.SIGNAL('REVISAR'),self.revisarRespuesta)
self.connect(self.video1,QtCore.SIGNAL("finished()"),self._terminoVideo)
self.connect(self.video2,QtCore.SIGNAL("finished()"),self._terminoVideo)
self.connect(self.thread,QtCore.SIGNAL("ACTUALIZAR"),self.actualizarTexto)
self.intro.returnPressed.connect(self.revisarRespuesta)
#self.intro.editingFinished.connect(self.revisarRespuesta) # Introduce ruido al final
# Al inicializarse la clase se muestra:
if pantallaTotal:
self.showFullScreen()
else:
self.show()
#self.displayOverlay()
def initUI(self):
"""
Inicialización de sus parámetros
"""
# Parte visual
self.imagen = QtGui.QLabel(self)
self.pixmapAct = QtGui.QPixmap('./imagenes/logoWeb.png')
self.imagen.setPixmap(self.pixmapAct)
self.media1 = Phonon.MediaSource('./videos/1.avi')
self.media2 = Phonon.MediaSource('./videos/2.avi')
self.video1.load(self.media1)
self.video2.load(self.media2)
# Layouts:
self.layoutVideo1 = QtGui.QVBoxLayout()
self.layoutVideo1.addWidget(self.imagen)
self.layoutVideo1.addWidget(self.video1)
self.layoutVideo1.addWidget(self.video2)
self.layoutVideo1.setAlignment(self.imagen, QtCore.Qt.AlignHCenter)
self.video1.setHidden(True)
self.video2.setHidden(True)
self.dataIntroLayout = QtGui.QHBoxLayout()
self.passwd = QtGui.QLabel('Ingrese respuesta:')
self.passwd.setFont(QtGui.QFont('SansSerif', 36))
self.intro = QtGui.QLineEdit()
self.intro.setFont(QtGui.QFont('SansSerif', 36))
#self.intro.setDisplayFormat("dd/MM/yyyy")
self.intro.setInputMask("99/99/9999")
self.intro.setCursorPosition(0)
self.digitalIntro = QtGui.QLCDNumber(self)
self.digitalIntro.setDigitCount(10)
self.digitalIntro.setMinimumWidth(180)
self.digitalIntro.display(' - - ')
self.digitalIntro.setMaximumHeight(90)
self.dataIntroLayout.addWidget(self.passwd)
self.dataIntroLayout.addWidget(self.digitalIntro)
self.dataIntroLayout.addWidget(self.intro)
if self.myLcd:
self.intro.setHidden(True)
else:
self.digitalIntro.setHidden(True)
self.layoutVideo1.addLayout(self.dataIntroLayout)
self.setLayout(self.layoutVideo1)
self.setMinimumHeight(450)
#self.setGeometry(300, 300, 300, 150)
# Algunas visualizaciones:
self.setWindowIcon(QtGui.QIcon('./imagenes/logo.png'))
self.setWindowTitle(self.titulo)
def revisarRespuesta(self):
textoSinSimbolo = self.intro.text().replace('/','')
if textoSinSimbolo in self.passwords:
print('Signal 1')
self._mostrarVideo1()
else:
print('Signal 2')
self._mostrarVideo2()
self.borrarTexto()
def borrarTexto(self):
GUIParalela.valorActual = ''
self.intro.setText('')
self.intro.setCursorPosition(0)
self.digitalIntro.display(' - - ')
def displayOverlay(self):
self.popup = QtGui.QDialog(self,QtCore.Qt.WindowStaysOnTopHint)
self.popup.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.passwd = QtGui.QLabel('Contraseña')
#self.passwd.setMinimumWidth(500)
self.intro = QtGui.QLineEdit('')
f = self.intro.font()
f.setPointSize(27)
self.intro.setFont(f)
self.intro.setMinimumWidth(500)
#self.intro.setEchoMode(QtGui.QLineEdit.Password)
self.intro.updateGeometry()
self.miMensaje = QtGui.QHBoxLayout()
#self.miMensaje.addWidget(self.passwd)
self.miMensaje.addWidget(self.intro)
self.popup.setLayout(self.miMensaje)
#position_x = (self.frameGeometry().width()-self.popup.frameGeometry().width())/2
#position_y = (self.frameGeometry().height()-self.popup.frameGeometry().height())/2
resolution = QtGui.QDesktopWidget().screenGeometry()
position_x = (resolution.width() / 2) - (self.popup.frameGeometry().width() / 2)
position_y = 7/8*((resolution.height()) - (self.popup.frameGeometry().height()))
self.popup.move(position_x, position_y)
#event.accept()
self.popup.show()
def keyPressEvent(self, e):
"""
Se redefine la interacción con el teclado para que la tecla ESC cierre el GUI
"""
if e.key() == QtCore.Qt.Key_Escape:
self.close()
def actualizarTexto(self):
longitud = len(GUIParalela.valorActual)
if longitud>=5:
formatoFecha = GUIParalela.valorActual[0:2]+'/'+GUIParalela.valorActual[2:4]+'/'+GUIParalela.valorActual[4:]
elif longitud>=3:
formatoFecha = GUIParalela.valorActual[0:2]+'/'+GUIParalela.valorActual[2:]
elif longitud>=1:
formatoFecha = GUIParalela.valorActual[0:]
else:
formatoFecha = ''
self.intro.setText(formatoFecha)
formatoFecha = formatoFecha.replace('/','-')
self.digitalIntro.display(formatoFecha)
def _mostrarVideo1(self):
"""
Despliega el video 1
"""
self.imagen.setHidden(True)
self.video1.setHidden(False)
self.video1.play()
self.miPopUp.showEspera()
def _mostrarVideo2(self):
"""
Despliega el video 2
"""
self.imagen.setHidden(True)
self.video2.setHidden(False)
self.video2.play()
self.miPopUp.showEspera()
def _terminoVideo(self):
self.video1.setHidden(True)
self.video2.setHidden(True)
self.imagen.setHidden(False)
class ThreadClass(QtCore.QThread):
"""
Thread para revisión continua de la fila de registros
"""
def __init__(self,parent = None):
"""
Constructor
"""
super(ThreadClass,self).__init__(parent)
def run(self):
"""
Re implementación del método
"""
while True:
try:
if not GUIParalela.miTeclado.teclas.empty():
valor = GUIParalela.miTeclado.teclas.get() # valor = (estado, id, nombre)
if valor == '*':
self.emit(QtCore.SIGNAL('REVISAR'))
print('Introducido: ',GUIParalela.valorActual)
#self.intro.setText(GUIParalela.valorActual)
else:
if valor == '#':
GUIParalela.valorActual = GUIParalela.valorActual[:-1]
else:
if len(GUIParalela.valorActual)<8:
GUIParalela.valorActual+= str(valor)
self.emit(QtCore.SIGNAL('ACTUALIZAR'))
#self.intro.setText(GUIParalela.valorActual)
except:
pass
if __name__ == '__main__':
"""
Video response
"""
lcd = False
pantalla = False
for input in sys.argv:
if input == 'Full':
pantalla = True
if input == 'lcd':
lcd = True
#print('Accediendo a LCD')
p = GUIParalela(fullScreen=pantalla,lcd = lcd)
p.process.join()