-
Notifications
You must be signed in to change notification settings - Fork 4
/
MainWindow.py
391 lines (326 loc) · 13.5 KB
/
MainWindow.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
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
from enum import IntEnum
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QMainWindow, QStatusBar
from PyQt5.uic import loadUi
from Resources.ResourceKeyboard import ResourceKeyboard
from Browser import Browser
from WheelChair import WheelChair
from inputs.Controller import Controller
try:
from enum import auto
except ImportError:
__my_enum_auto_id = 0
def auto() -> int:
global __my_enum_auto_id
i = __my_enum_auto_id
__my_enum_auto_id += 1
return i
class MODE(IntEnum):
CHAIR = auto()
MAIN = auto()
SUBPROC = auto()
AUDIO = auto()
VIDEO = auto()
NEWS = auto()
PLAYING = auto()
NEWSING = auto()
SMS = auto()
EMAIL = auto()
KEYBOARD = auto()
BROWSER = auto()
class METHOD(IntEnum):
EYE_HELP = 0
HEAD_HELP = 1
VOICE_HELP = 2
class MainWindow(QMainWindow):
def __init__(self):
WINDOW_TITLE = "Eye Based Wheelchair Control & Task Manager"
GUI_UI_LOCATION = "./UI/MainWindow.ui"
super(MainWindow, self).__init__()
loadUi(GUI_UI_LOCATION, self)
self.statusBar = QStatusBar()
self.setStatusBar(self.statusBar)
self.statusBar.showMessage("Welcome")
self.setWindowTitle(WINDOW_TITLE)
self.main_image_label.setScaledContents(True)
self.gaze_image_label.setScaledContents(True)
# self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
# self.b = QtGui.QPushButton("exit", self, clicked=self.close)
self.resetButton.clicked.connect(self.resetAll)
self.chair = WheelChair()
self.chairSpeedSlider.sliderReleased.connect(self.setSpeed)
self.keyboard = None
self.msg = ""
self.current_mode = MODE.MAIN
self.current_focus = 0
self.__initialize_buttons()
self.player = None
self.document = None
self.main_controller = Controller(self, self.gotInput)
self.timer = QTimer(self)
self.timer.timeout.connect(self.main_controller.getInput)
self.timer.start(100)
def setSpeed(self):
val = int(self.chairSpeedSlider.value())
self.chair.setSpeed(val)
def gotInput(self, command):
if command == "not initialized":
self.statusBar.showMessage("Please Initialize First")
return
if self.current_mode == MODE.MAIN:
if command in ["blinkleft", "headleft"]:
self.moveFocusLeft()
elif command in ["blinkright", "headright"]:
self.moveFocusRight()
elif command in ["headup"]:
self.moveFocusUp()
elif command in ["headdown"]:
self.moveFocusDown()
elif command in ["blinkboth"]:
self.pressFocused()
elif self.current_mode == MODE.CHAIR:
if command in ["gazeleft", "headleft"]:
self.chair.left()
elif command in ["gazeright", "headright"]:
self.chair.right()
elif command in ["gazecenter", "headcenter"]:
self.chair.start()
elif command in ["blinkboth"]:
self.chair.stop()
self.changeMode(MODE.MAIN)
elif self.current_mode == MODE.AUDIO:
if command in ["blinkright", "headright"]:
self.player.nextItem()
elif command in ["blinkleft", "headleft"]:
self.statusBar.showMessage("Select an option...")
if self.player.playing:
self.player.stop()
else:
self.player.Close()
self.changeMode(MODE.MAIN)
elif command == "blinkboth":
self.player.togglePlay()
elif self.current_mode == MODE.VIDEO:
if command in ["blinkright", "headright"]:
self.player.nextItem()
elif command in ["blinkleft", "headleft"]:
if self.player.resourceVideo.process != None:
self.player.stop()
else:
self.player.Close()
self.changeMode(MODE.MAIN)
elif command in ["blinkboth"]:
self.player.togglePlay()
elif self.current_mode == MODE.NEWS:
if command in ["blinkright", "headdown"]:
self.document.nextItem()
elif command in ["blinkleft", "headleft"]:
self.document.destroy()
self.changeMode(MODE.MAIN)
elif command in ["blinkboth"]:
if self.document.Open():
self.changeMode(MODE.NEWSING)
elif self.current_mode == MODE.NEWSING:
if command in ["blinkright", "headright"]:
self.document.scrollDown()
elif command in ["blinkleft", "headleft"]:
self.document.scrollUp()
elif command in ["blinkboth"]:
self.document.Close()
self.changeMode(MODE.NEWS)
elif self.current_mode == MODE.BROWSER:
if command in ["blinkright","headright"]:
self.browser.scrollDown()
elif command in ["blinkleft","headleft"]:
self.browser.scrollUp()
elif command in ["blinkboth"]:
self.browser.Close()
self.changeMode(MODE.MAIN)
elif self.current_mode is MODE.KEYBOARD:
if self.selectMethodComboBox.currentIndex() == METHOD.EYE_HELP:
if command in ["blinkright"]:
self.keyboard.moveFocusRight()
elif command in ["blinkleft"]:
self.keyboard.moveFocusLeft()
if command in ["gazeright"]:
self.keyboard.moveFloatRight()
elif command in ["gazeleft"]:
self.keyboard.moveFloatLeft()
elif self.selectMethodComboBox.currentIndex() == METHOD.HEAD_HELP:
if command in ["headright"]:
self.keyboard.moveFocusRight()
elif command in ["headleft"]:
self.keyboard.moveFocusLeft()
if command in ["blinkright"]:
self.keyboard.moveFloatRight()
elif command in ["blinkleft"]:
self.keyboard.moveFloatLeft()
if command in ["blinkboth"]:
if self.keyboard.selectKey():
self.msg = self.keyboard.str
nxtMode = self.keyboard.fortask
self.keyboard = None
if nxtMode == "sms":
self.changeMode(MODE.SMS)
elif nxtMode == "email":
self.changeMode(MODE.EMAIL)
elif self.current_mode == MODE.SMS:
self.sendSms(self.msg)
self.changeMode(MODE.MAIN)
elif self.current_mode == MODE.EMAIL:
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
try:
fromaddr = '[email protected]'
toaddr = '[email protected]'
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = 'Doctor Appointment'
body = self.msg
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, '060701cse')
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
self.statusBar.showMessage("Email sent")
server.quit()
except Exception as e:
self.statusBar.showMessage("Email not sent")
print(e)
self.changeMode(MODE.MAIN)
def closeEvent(self, event):
# self.main_controller.closed()
# self.deleteLater()
self.chair.stop()
self.chair.active = False
def sendSms(self, msg):
from zeep import Client
try:
url = 'https://api2.onnorokomsms.com/sendsms.asmx?WSDL'
client = Client(url)
userName = '01521313223'
password = '90053'
recipientNumber = '01521323429'
smsText = msg
smsType = 'TEXT'
maskName = ''
campaignName = ''
client.service.OneToOne(userName, password, recipientNumber, smsText, smsType, maskName,
campaignName)
self.statusBar.showMessage("SMS sent!!")
except Exception as e:
self.statusBar.showMessage("SMS not sent!!")
print(e)
def resetAll(self):
self.chair.stop()
self.chair.active = False
def __initialize_buttons(self):
self.selectMethodComboBox.clear()
self.selectMethodComboBox.addItems([
"Eye-Help",
"Head-Help",
"Voice-Help"
])
self.selectMethodComboBox.setCurrentIndex(METHOD.EYE_HELP)
self.selectMethodComboBox.currentIndexChanged.connect(self.comboboxIndexChanged)
self.buttons = [self.b1_1, self.b1_2,
self.b1_3, self.b2_1,
self.b2_2, self.b2_3,
self.b3_1, self.b3_2,
self.b4_1, self.b4_2]
for b in self.buttons:
b.setAutoDefault(True)
self.buttons[self.current_focus].setFocus(True)
self.b1_1.clicked.connect(self.controlWheel)
self.b1_2.clicked.connect(self.playSMS)
self.b1_3.clicked.connect(self.playEmail)
self.b2_1.clicked.connect(self.playVideo)
self.b2_2.clicked.connect(self.playMusic)
self.b2_3.clicked.connect(self.playDocument)
self.b3_1.clicked.connect(self.playLight)
self.b3_2.clicked.connect(self.playFan)
self.b4_1.clicked.connect(self.playBrowser)
self.b4_2.clicked.connect(self.playEmergency)
def comboboxIndexChanged(self):
import cv2
cv2.destroyAllWindows()
# TODO
if self.selectMethodComboBox.currentIndex() == METHOD.EYE_HELP:
pass
elif self.selectMethodComboBox.currentIndex() == METHOD.HEAD_HELP:
pass
elif self.selectMethodComboBox.currentIndex() == METHOD.VOICE_HELP:
pass
def moveFocusRight(self):
if self.current_mode is MODE.MAIN:
self.current_focus = (self.current_focus + 1) % 10
self.buttons[self.current_focus].setFocus(True)
def moveFocusLeft(self):
self.current_focus = (self.current_focus - 1) % 10
self.buttons[self.current_focus].setFocus(True)
def moveFocusUp(self):
self.current_focus = (self.current_focus - 2) % 10
self.buttons[self.current_focus].setFocus(True)
def moveFocusDown(self):
self.current_focus = (self.current_focus + 2) % 10
self.buttons[self.current_focus].setFocus(True)
def pressFocused(self):
self.buttons[self.current_focus].animateClick()
def playFan(self):
self.chair.toggleFan()
def controlWheel(self):
self.chair.active = True
self.changeMode(MODE.CHAIR)
def moveWindow(self, left, top):
from PyQt5 import QtWidgets
sizeObject = QtWidgets.QDesktopWidget().screenGeometry(-1)
height = sizeObject.height()
width = sizeObject.width()
self.move(int(width * left), int(height * top))
def playFan(self):
self.chair.toggleFan()
def playLight(self):
self.chair.toggleLight()
def playMusic(self):
from Players.Audio import Audio
self.changeMode(MODE.AUDIO)
self.player = Audio()
def playVideo(self):
from Players.Video import Video
self.changeMode(MODE.VIDEO)
self.player = Video()
def playSMS(self):
self.keyboard = ResourceKeyboard("sms")
self.changeMode(MODE.KEYBOARD)
def playEmail(self):
self.keyboard = ResourceKeyboard("email")
self.changeMode(MODE.KEYBOARD)
def playDocument(self):
from Document import Document
self.changeMode(MODE.NEWS)
self.document = Document()
def playEmergency(self):
self.sendSms("This is an emergency, please contack me!!!")
def playBrowser(self):
self.changeMode(MODE.BROWSER)
self.browser = Browser("https://iitestudent.blogspot.com/2012/05/8086-memory-banks.html")
def changeMode(self, mode):
self.current_mode = mode
if mode is MODE.KEYBOARD:
self.statusBar.showMessage("Please type what you want")
elif mode is MODE.SMS:
self.statusBar.showMessage("Sending sms")
elif mode is MODE.CHAIR:
self.statusBar.showMessage("Wheelchair control mode")
elif mode is MODE.NEWSING:
self.statusBar.showMessage("Reading PDF")
elif mode is MODE.AUDIO:
self.statusBar.showMessage("Playing Audio")
elif mode is MODE.SUBPROC:
self.statusBar.showMessage("In subprocess mode")
elif mode is MODE.MAIN:
self.statusBar.showMessage("Please Select an option")
self.gaze_image_label.setText("Not using Eye gaze")