-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
4555 lines (4189 loc) · 225 KB
/
main.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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'StartUpWindow.ui'
#
# Created by: PyQt5 UI code generator 5.14.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QSettings
import urllib.request
from playsound import playsound
import pyttsx3 as ptts
import speech_recognition as sr
import random, os, webbrowser, time, wikipedia, datetime, smtplib, sys, time, wikipedia, subprocess
import youtube_search as ys
import wikipedia as w
from distutils.util import strtobool
from pynput.keyboard import Key, Controller
class Assistant_details(object):
try:
icon_display = "stark-logo"
click_sound = 'resources\\audio\\button_click.mp3'
start_sound = 'resources\\audio\\on.mp3'
stop_sound = 'resources\\audio\\off.mp3'
current_date = datetime.date.today().strftime('%d-%m-%Y')
current_year = datetime.date.today().strftime('%Y')
date_created = '01-06-2020'
personal_settings = QSettings('PyQt5Application', 'Stark')
owner = personal_settings.value('Name')
dob = personal_settings.value('DOB')
gender = personal_settings.value('Gender')
nickname = personal_settings.value('Nickname')
email = personal_settings.value('Email')
assistant_feedback_status = strtobool(personal_settings.value('assistant_feedback_status'))
click_sound_status = strtobool(personal_settings.value('click_sound_status'))
start_stop_sound_status = strtobool(personal_settings.value('start_stop_sound_status'))
music_folder = personal_settings.value('music_folder')
voice_type = personal_settings.value('voice_type')
if gender == 'Male':
denotation = 'Sir'
else:
denotation = "Ma'am"
except Exception as e:
pass
class Ui_AboutAssistant(object):
def setupUi(self, AboutAssistant):
AboutAssistant.setObjectName("AboutAssistant")
AboutAssistant.setWindowModality(QtCore.Qt.NonModal)
AboutAssistant.setFixedSize(600, 450)
font = QtGui.QFont()
font.setStyleStrategy(QtGui.QFont.PreferDefault)
AboutAssistant.setFont(font)
AboutAssistant.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("resources/icons/microphone.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
AboutAssistant.setWindowIcon(icon)
self.verticalLayoutWidget_2 = QtWidgets.QWidget(AboutAssistant)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(215, 360, 366, 74))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.SupportVericalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
self.SupportVericalLayout.setContentsMargins(0, 0, 0, 0)
self.SupportVericalLayout.setObjectName("SupportVericalLayout")
self.SupportLabel = QtWidgets.QLabel(self.verticalLayoutWidget_2)
font = QtGui.QFont()
font.setFamily("Monotype Corsiva")
font.setPointSize(15)
self.SupportLabel.setFont(font)
self.SupportLabel.setAlignment(QtCore.Qt.AlignCenter)
self.SupportLabel.setObjectName("SupportLabel")
self.SupportVericalLayout.addWidget(self.SupportLabel)
self.SocialMediaLayout = QtWidgets.QHBoxLayout()
self.SocialMediaLayout.setObjectName("SocialMediaLayout")
self.YoutubeIcon = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.YoutubeIcon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.YoutubeIcon.setText("")
self.YoutubeIcon.setIcon(QtGui.QIcon("resources/application/youtube.png"))
self.YoutubeIcon.setObjectName("YoutubeIcon")
self.SocialMediaLayout.addWidget(self.YoutubeIcon)
self.YoutubeIcon.setStyleSheet("border: none")
self.YoutubeIcon.setIconSize(QtCore.QSize(45, 45))
self.InstagramIcon = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.InstagramIcon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.InstagramIcon.setText("")
self.InstagramIcon.setIcon(QtGui.QIcon("resources/application/instagram.png"))
self.InstagramIcon.setObjectName("InstagramIcon")
self.SocialMediaLayout.addWidget(self.InstagramIcon)
self.InstagramIcon.setStyleSheet("border: none")
self.InstagramIcon.setIconSize(QtCore.QSize(35, 35))
self.GithubIcon = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.GithubIcon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.GithubIcon.setText("")
self.GithubIcon.setIcon(QtGui.QIcon("resources/application/github.svg"))
self.GithubIcon.setObjectName("GithubIcon")
self.SocialMediaLayout.addWidget(self.GithubIcon)
self.GithubIcon.setStyleSheet("border: none")
self.GithubIcon.setIconSize(QtCore.QSize(35, 35))
self.QuoraIcon = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.QuoraIcon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.QuoraIcon.setText("")
self.QuoraIcon.setIcon(QtGui.QIcon("resources/application/quora.webp"))
self.QuoraIcon.setObjectName("QuoraIcon")
self.SocialMediaLayout.addWidget(self.QuoraIcon)
self.QuoraIcon.setStyleSheet("border: none")
self.QuoraIcon.setIconSize(QtCore.QSize(35, 35))
self.LinkedinIccon = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.LinkedinIccon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.LinkedinIccon.setText("")
self.LinkedinIccon.setIcon(QtGui.QIcon("resources/application/linkedin.webp"))
self.LinkedinIccon.setObjectName("LinkedinIccon")
self.SocialMediaLayout.addWidget(self.LinkedinIccon)
self.LinkedinIccon.setStyleSheet("border: none")
self.LinkedinIccon.setIconSize(QtCore.QSize(35, 35))
self.FacebookIcon = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.FacebookIcon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.FacebookIcon.setText("")
self.FacebookIcon.setIcon(QtGui.QIcon("resources/application/facebook.png"))
self.FacebookIcon.setObjectName("FacebookIcon")
self.SocialMediaLayout.addWidget(self.FacebookIcon)
self.FacebookIcon.setStyleSheet("border: none")
self.FacebookIcon.setIconSize(QtCore.QSize(35, 35))
self.BloggerIcon = QtWidgets.QPushButton(self.verticalLayoutWidget_2)
self.BloggerIcon.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.BloggerIcon.setStatusTip("")
self.BloggerIcon.setText("")
self.BloggerIcon.setIcon(QtGui.QIcon("resources/application/blogger.png"))
self.BloggerIcon.setObjectName("BloggerIcon")
self.SocialMediaLayout.addWidget(self.BloggerIcon)
self.BloggerIcon.setStyleSheet("border: none")
self.BloggerIcon.setIconSize(QtCore.QSize(35, 35))
self.SupportVericalLayout.addLayout(self.SocialMediaLayout)
self.InformationLabel = QtWidgets.QLabel(AboutAssistant)
self.InformationLabel.setGeometry(QtCore.QRect(30, 128, 541, 201))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(13)
font.setBold(False)
font.setWeight(50)
self.InformationLabel.setFont(font)
self.InformationLabel.setScaledContents(False)
self.InformationLabel.setAlignment(QtCore.Qt.AlignJustify | QtCore.Qt.AlignVCenter)
self.InformationLabel.setWordWrap(True)
self.InformationLabel.setObjectName("InformationLabel")
self.CopyrightLabel = QtWidgets.QLabel(AboutAssistant)
self.CopyrightLabel.setGeometry(QtCore.QRect(12, 362, 191, 71))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(11)
font.setBold(False)
font.setWeight(50)
self.CopyrightLabel.setFont(font)
self.CopyrightLabel.setScaledContents(False)
self.CopyrightLabel.setAlignment(QtCore.Qt.AlignJustify | QtCore.Qt.AlignVCenter)
self.CopyrightLabel.setWordWrap(True)
self.CopyrightLabel.setObjectName("CopyrightLabel")
self.horizontalLayoutWidget = QtWidgets.QWidget(AboutAssistant)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(95, 10, 439, 102))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.HeadingHorizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.HeadingHorizontalLayout.setContentsMargins(0, 0, 0, 0)
self.HeadingHorizontalLayout.setObjectName("HeadingHorizontalLayout")
self.StarkIcon = QtWidgets.QLabel(self.horizontalLayoutWidget)
self.StarkIcon.setMaximumSize(QtCore.QSize(100, 100))
self.StarkIcon.setText("")
self.StarkIcon.setPixmap(QtGui.QPixmap("resources/icons/stark-logo.png"))
self.StarkIcon.setScaledContents(True)
self.StarkIcon.setObjectName("StarkIcon")
self.HeadingHorizontalLayout.addWidget(self.StarkIcon)
self.HeadingLayout = QtWidgets.QVBoxLayout()
self.HeadingLayout.setObjectName("HeadingLayout")
self.StarkLabel = QtWidgets.QLabel(self.horizontalLayoutWidget)
font = QtGui.QFont()
font.setFamily("Colonna MT")
font.setPointSize(40)
font.setStyleStrategy(QtGui.QFont.PreferDefault)
self.StarkLabel.setFont(font)
self.StarkLabel.setAlignment(QtCore.Qt.AlignCenter)
self.StarkLabel.setObjectName("StarkLabel")
self.HeadingLayout.addWidget(self.StarkLabel)
self.StarkMotto = QtWidgets.QLabel(self.horizontalLayoutWidget)
font = QtGui.QFont()
font.setFamily("Colonna MT")
font.setPointSize(25)
font.setStyleStrategy(QtGui.QFont.PreferDefault)
self.StarkMotto.setFont(font)
self.StarkMotto.setAlignment(QtCore.Qt.AlignCenter)
self.StarkMotto.setObjectName("StarkMotto")
self.HeadingLayout.addWidget(self.StarkMotto)
self.HeadingHorizontalLayout.addLayout(self.HeadingLayout)
self.retranslateUi(AboutAssistant)
QtCore.QMetaObject.connectSlotsByName(AboutAssistant)
self.YoutubeIcon.clicked.connect(lambda: self.open_link('youtube'))
self.InstagramIcon.clicked.connect(lambda: self.open_link('instagram'))
self.GithubIcon.clicked.connect(lambda: self.open_link('github'))
self.QuoraIcon.clicked.connect(lambda: self.open_link('quora'))
self.LinkedinIccon.clicked.connect(lambda: self.open_link('linkedin'))
self.FacebookIcon.clicked.connect(lambda: self.open_link('facebook'))
self.BloggerIcon.clicked.connect(lambda: self.open_link('blogger'))
def retranslateUi(self, AboutAssistant):
_translate = QtCore.QCoreApplication.translate
AboutAssistant.setWindowTitle(_translate("AboutAssistant", "About - \'Stark\'"))
self.SupportLabel.setText(_translate("AboutAssistant", "Support the Developer"))
self.YoutubeIcon.setToolTip(_translate("AboutAssistant", "Subscribe to YouTube Channel"))
self.InstagramIcon.setToolTip(_translate("AboutAssistant", "Follow on Instagram"))
self.GithubIcon.setToolTip(_translate("AboutAssistant", "Github Profile"))
self.QuoraIcon.setToolTip(_translate("AboutAssistant", "Follow on Quora"))
self.LinkedinIccon.setToolTip(_translate("AboutAssistant", "Connect on Linkedin"))
self.FacebookIcon.setToolTip(_translate("AboutAssistant", "Reach at Facebook"))
self.BloggerIcon.setToolTip(_translate("AboutAssistant", "Read Blog posts"))
self.InformationLabel.setText(_translate("AboutAssistant",
"\'Stark\' - The Personal Assistant, is a project application made by Charitra Agarwal. It is a simple GUI based Desktop Application, which can help you carry out some troublesome tasks in a simple way. It cannot perform as good as other personal assistants like Google Assistant or Cortana, but it comes handy, even if you don\'t have internet connection. You can perform some simple tasks even without internet connected, with the help of manual command input functionality. Hope you like this project. It\'ll be a great pleasure, if you all express your love by supporting the developer in the following given links."))
self.CopyrightLabel.setText(_translate("AboutAssistant", "\'Stark\' - The Personal Assistant\n"
"Copyright (c) 2020 - {}\n"
"Developer - Charitra Agarwal\n"
"India".format(Assistant_details.current_year)))
self.StarkLabel.setText(_translate("AboutAssistant", "Stark"))
self.StarkMotto.setText(_translate("AboutAssistant", "The Personal Assistant"))
def open_link(self, string=False):
if string:
if string == 'youtube':
url = "https://www.youtube.com/channel/UCLeAOMSk1sGxRT8-0r3mY9g"
if string == 'instagram':
url = "https://www.instagram.com/everything_computerized/"
if string == 'github':
url = "https://github.com/Charitra1022"
if string == 'quora':
url = "https://www.quora.com/profile/Charitra-Agarwal-1"
if string == 'linkedin':
url = "https://www.linkedin.com/in/charitra1022/"
if string == 'facebook':
url = "https://www.facebook.com/charitra.agarwal"
if string == 'blogger':
url = "https://everythingcomputerized-ca.blogspot.com/"
webbrowser.get().open(url)
class Ui_VolumeSelector(object):
def setupUi(self, VolumeSelector):
VolumeSelector.setObjectName("VolumeSelector")
VolumeSelector.setFixedSize(309, 140)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("resources/icons/sound-on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
VolumeSelector.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(VolumeSelector)
self.centralwidget.setObjectName("centralwidget")
self.VolumeSlider = QtWidgets.QSlider(self.centralwidget)
self.VolumeSlider.setGeometry(QtCore.QRect(47, 46, 191, 21))
self.VolumeSlider.setOrientation(QtCore.Qt.Horizontal)
self.VolumeSlider.setObjectName("VolumeSlider")
self.VolumeDisplay = QtWidgets.QLabel(self.centralwidget)
self.VolumeDisplay.setGeometry(QtCore.QRect(250, 46, 30, 16))
self.VolumeSlider.setStyleSheet("QSlider::groove:horizontal {border: 1px solid #bbb;background: white;height: 7px;border-radius: 4px;}"
"QSlider::sub-page:horizontal {background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #66e, stop: 1 #bbf);"
"background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1, stop: 0 #bbf, stop: 1 #55f);border: 0px solid #777;height: 10px;border-radius: 4px;}"
"QSlider::add-page:horizontal {background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0.5 #fff, stop: 1 #d4d4d4);border: 0px solid #777;height: 10px;border-radius: 4px;}"
"QSlider::handle:horizontal {background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #52307c, stop: 1 #ece6ff);width: 13px;margin-top: -5px;margin-bottom: -5px;border-radius: 4px;}"
"QSlider::handle:horizontal:hover {background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #bca0dc, stop:1 #e0d6ff);border: 0px solid #444;border-radius: 4px;}"
"QSlider::sub-page:horizontal:disabled {background: #bbb;border-color: #999;}"
"QSlider::add-page:horizontal:disabled {background: #eee;border-color: #999;}QSlider::handle:horizontal:disabled {background: #eee;border: 1px solid #aaa;border-radius: 4px;}")
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(12)
self.VolumeDisplay.setFont(font)
self.VolumeDisplay.setAlignment(QtCore.Qt.AlignCenter)
self.VolumeDisplay.setObjectName("VolumeDisplay")
self.CancelButton = QtWidgets.QPushButton(self.centralwidget)
self.CancelButton.setGeometry(QtCore.QRect(75, 100, 75, 23))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI Light")
font.setPointSize(9)
font.setBold(True)
font.setWeight(75)
self.CancelButton.setFont(font)
self.CancelButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.CancelButton.setStyleSheet("background-color:#0162ff; color: white; border-radius:5px")
self.CancelButton.setObjectName("CancelButton")
self.ConfirmButton = QtWidgets.QPushButton(self.centralwidget)
self.ConfirmButton.setGeometry(QtCore.QRect(180, 100, 75, 23))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei Light")
font.setPointSize(9)
font.setBold(True)
font.setWeight(75)
self.ConfirmButton.setFont(font)
self.ConfirmButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.ConfirmButton.setStyleSheet("background-color:#0162ff; color: white; border-radius:5px")
self.ConfirmButton.setObjectName("ConfirmButton")
VolumeSelector.setCentralWidget(self.centralwidget)
self.VolumeSlider.setMinimum(0)
self.VolumeSlider.setMaximum(100)
self.VolumeSlider.valueChanged.connect(self.volume_changed)
self.CancelButton.clicked.connect(lambda: self.cancel_button(VolumeSelector))
self.ConfirmButton.clicked.connect(lambda: self.confirm_button(VolumeSelector))
self.settings = QSettings('PyQt5Application', 'Stark')
try:
self.VolumeSlider.setValue(self.settings.value('volume'))
except:
self.VolumeSlider.setValue(100)
self.VolumeDisplay.setText(str(self.VolumeSlider.value()))
self.retranslateUi(VolumeSelector)
QtCore.QMetaObject.connectSlotsByName(VolumeSelector)
VolumeSelector.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowCloseButtonHint)
def retranslateUi(self, VolumeSelector):
_translate = QtCore.QCoreApplication.translate
VolumeSelector.setWindowTitle(_translate("VolumeSelector", "Volume Selector"))
self.CancelButton.setText(_translate("VolumeSelector", "Cancel"))
self.ConfirmButton.setText(_translate("VolumeSelector", "OK"))
self.ConfirmButton.setShortcut(_translate("VolumeSelector", "Return"))
self.CancelButton.setShortcut(_translate("VolumeSelector", "Esc"))
def volume_changed(self):
value = self.VolumeSlider.value()
self.VolumeDisplay.setText(str(value))
def cancel_button(self, x):
x.close()
def confirm_button(self, x):
value = self.VolumeSlider.value()
keyboard = Controller()
for i in range(0, 50):
keyboard.press(Key.media_volume_down)
keyboard.release(Key.media_volume_down)
for i in range(0, int(value / 2)):
keyboard.press(Key.media_volume_up)
keyboard.release(Key.media_volume_up)
self.settings.setValue('volume', self.VolumeSlider.value())
x.close()
########################### Assistant Brain ###################################
class AssistantSpeakAndListen(object):
@staticmethod
def speak(string):
"""Makes the Assistant give feedback in the form of spoken words"""
s = ptts.init()
AssistantSpeakAndListen.voice_change()
s.setProperty('rate', 180)
s.say(string)
s.runAndWait()
@staticmethod
def voice_change():
s = ptts.init()
voices = s.getProperty('voices')
s.setProperty('voice', voices[0].id) if Assistant_details.voice_type == 'Male' else s.setProperty('voice',
voices[1].id)
class Assistant_main(object):
@classmethod
def command_input(cls, command_input):
"""Initiate the Assistant"""
commands_present = ['hi', 'hello', 'hey', 'stark', 'hay', 'star', 'stock',
'launch', 'open', 'start',
'google', 'youtube', 'wikipedia',
'search', 'find', 'navigate', 'location',
'calculate',
'help', 'assist',
'play', 'music',
'time',
'is', 'was', 'has', 'had',
'send', 'email', 'gmail', 'message',
'what', 'how', 'when', 'where', 'who',
'increase', 'decrease', 'mute', 'volume', 'full'] # recognize keywords for Assistant
command = Commands.check_availability(command_input, commands_present)
if command:
status = Commands.execute_command(command_input)
return status
return False
class Time(object):
"""Returns the current time"""
@staticmethod
def current_time(string):
"""Returns the current time"""
try:
cur_time = datetime.datetime.now().strftime("%I:%M %p")
Assistant_details.icon_display = 'time'
return "The time is " + cur_time
except:
return 'Something went wrong'
class OtherCommands(object):
"""Class 'OtherCommands' : It contains all the miscelleneous commands related to the Assistant
name_Assistant(string) : Speaks the name of Assistant
age_Assistant(string) : Speaks the age of Assistant
own_Assistant(string) : Speaks the owner of Assistant
coder_Assistant(string) : Speaks the manufacturer of Assistant
"""
@staticmethod
def name_Assistant(string):
"""Class 'OtherCommands' - name_Assistant(string) : Speaks the name of Assistant"""
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return 'I\'m Stark, your Personal Assistant!'
@staticmethod
def age_Assistant(string):
"""Class 'OtherCommands' - age_Assistant(string) : Speaks the age of Assistant"""
try:
dateformat = '%d-%m-%Y'
d1 = datetime.datetime.strptime(Assistant_details.date_created, dateformat)
d2 = datetime.datetime.strptime(Assistant_details.current_date, dateformat)
years = (d2 - d1).days // 365
months = ((d2 - d1).days - years * 365) // 30
if years == 0 and months != 0:
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return 'I\'m {} months old!'.format(str(months))
if years != 0 and months == 0:
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return 'I\'m {} years old!'.format(str(years))
if years != 0 and months != 0:
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return 'I\'m {} years {} months old!'.format(str(years), str(months))
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return 'I\'m ' + str((d2 - d1).days) + ' days old!'
except:
return 'Something went wrong'
@staticmethod
def own_Assistant(string):
"""Class 'OtherCommands' - own_Assistant(string) : Speaks the owner of Assistant"""
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return str('I work for {}'.format(Assistant_details.owner))
@staticmethod
def coder_Assistant(string):
"""Class 'OtherCommands' - coder_Assistant(string) : Speaks the manufacturer of Assistant"""
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return "I was made by 'Charitra Agarwal'. He coded me and made me worthy of helping you!"
@staticmethod
def age_Owner(string):
"""Class 'OtherCommands' - age_Owner(string) : Speaks the age of owner"""
try:
dateformat = '%d-%m-%Y'
d1 = datetime.datetime.strptime(Assistant_details.dob, dateformat)
d2 = datetime.datetime.strptime(Assistant_details.current_date, dateformat)
years = (d2 - d1).days // 365
months = ((d2 - d1).days - years * 365) // 30
if months != 0:
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return 'You are {} years {} months old!'.format(str(years), str(months))
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return 'You are {} years old!'.format(str(years))
except:
return 'Something went wrong'
@staticmethod
def owner_name(string):
"""Returns owner name"""
try:
Assistant_details.icon_display = random.choice(['angel', 'happy', 'heart', 'lol', 'love', 'wink'])
return 'You are {}'.format(Assistant_details.owner)
except:
return 'Something went wrong'
class Search_internet(object):
"""Opens something in the internet"""
@staticmethod
def search_google(string):
"""Searches for a query in the internet"""
try:
if 'search' in string:
string = string.replace('search ', "")
url = 'https://google.com/search?q=' + string
webbrowser.get().open(url)
Assistant_details.icon_display = 'google'
return 'Here is what I got'
except:
return 'Something went wrong'
@staticmethod
def open_youtube(string=False):
"""Opens youtube and searches for a song if 'string' parameter present"""
try:
if 'open youtube' in string:
string = string.replace('open youtube', '')
else:
string = string.replace('youtube', '')
keywords = string.split()
if len(keywords) == 0:
url = "https://youtube.com/"
webbrowser.get().open(url)
Assistant_details.icon_display = 'youtube'
return 'Opening YouTube'
search_key = ' '.join(keywords)
Assistant_details.icon_display = 'youtube'
return PlayMusic.youtube_play(search_key)
except:
return 'Somethimg went wrong'
@staticmethod
def open_google(string=False):
"""Open 'google.com'"""
try:
url = "https://www.google.co.in/"
webbrowser.get().open(url)
Assistant_details.icon_display = 'google'
return 'Opening Google'
except:
return 'Something went wrong'
@staticmethod
def wikipedia_search(string):
"""Search wikipedia for something"""
try:
if 'wikipedia' in string:
string = string.replace('wikipedia', '')
try:
result = w.summary(string, sentences=2)
AssistantSpeakAndListen.speak(result)
Assistant_details.icon_display = 'wikipedia'
return 'This was according to Wikipedia'
except:
Assistant_details.icon_display = 'wikipedia'
return 'Seems like internet is not connected'
except:
return 'Something went wrong'
class Location_search(object):
"""Searches google for a location parameter"""
@staticmethod
def search_location(string):
"""Searches google for a location parameter"""
try:
if 'location' in string:
string = string.replace('location ', "")
if 'navigate' in string:
string = string.replace('navigate ', "")
url = 'https://google.nl/maps/place/' + string + '/&'
webbrowser.get().open(url)
return 'Here is what I got'
except:
return 'Something went wrong'
class LaunchApp(object):
"""Launches a registered application"""
@staticmethod
def launch_app(string):
"""Checks if an application is installed or not, then opens it"""
try:
if 'chrome' in string or 'web browser' in string or 'browser' in string or 'internet' in string:
try:
os.startfile('chrome.exe')
except:
os.startfile('iexplore.exe')
Assistant_details.icon_display = 'internet'
return 'Launching Internet Browser'
elif 'opera' in string:
try:
os.startfile('opera.exe')
except:
os.startfile('iexplore.exe')
Assistant_details.icon_display = 'internet'
return 'Launching Internet Browser'
elif 'internet explore' in string:
os.startfile('iexplore.exe')
Assistant_details.icon_display = 'internet'
return 'Launching Internet Browser'
elif 'firefox' in string:
try:
os.startfile('firefox.exe')
except:
os.startfile('iexplore.exe')
Assistant_details.icon_display = 'internet'
return 'Launching Internet Browser'
elif 'wordpad' in string or 'wattpad' in string:
os.startfile('wordpad.exe')
Assistant_details.icon_display = 'wordpad'
return 'Launching Wordpad'
elif 'ms word' in string or 'microsoft word' in string or 'word' in string:
os.startfile('winword.exe')
Assistant_details.icon_display = 'word'
return 'Launching Microsoft Word'
elif 'ms powerpoint' in string or 'microsoft powerpoint' in string or 'powerpoint' in string or 'presentation' in string or 'ppt' in string:
os.startfile('powerpnt.exe')
Assistant_details.icon_display = 'powerpoint'
return 'Launching Microsoft Powerpoint'
elif 'ms excel' in string or 'microsoft excel' in string or 'excel' in string or 'spreadsheet' in string:
os.startfile('excel.exe')
Assistant_details.icon_display = 'excel'
return 'Launching Microsoft Excel'
elif 'ms access' in string or 'microsoft access' in string or 'access' in string:
os.startfile('msaccess.exe')
Assistant_details.icon_display = 'access'
return 'Launching Microsoft Access'
elif 'settings' in string or 'device settings' in string:
try:
os.system('start ms-settings:')
Assistant_details.icon_display = 'settings'
return 'Launching Settings'
except Exception as e:
os.startfile('control.exe')
Assistant_details.icon_display = 'settings'
return 'Launching Control Panel'
elif 'control panel' in string or 'control' in string or 'panel' in string:
os.startfile('control.exe')
Assistant_details.icon_display = 'settings'
return 'Launching Control Panel'
elif 'this pc' in string or 'file manager' in string or 'file explorer' in string or 'my files' in string or 'my computer' in string or 'files' in string:
os.system('explorer.exe /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}')
Assistant_details.icon_display = 'files'
return 'Launching This PC'
elif 'notepad' in string:
os.startfile('notepad.exe')
Assistant_details.icon_display = 'wordpad'
return 'Launching Notepad'
elif 'cmd' in string or 'command prompt' in string or 'terminal' in string or 'command' in string or 'prompt' in string:
os.startfile('cmd.exe')
Assistant_details.icon_display = 'cmd'
return 'Launching Microsoft Command Prompt'
elif 'calculator' in string or 'calculation' in string or 'calc' in string:
os.startfile('calc.exe')
Assistant_details.icon_display = 'calculator'
return 'Launching Calculator'
elif 'powershell' in string:
try:
os.startfile('powershell.exe')
Assistant_details.icon_display = 'powershell'
return 'Launching Windows PowerShell'
except Exception as e:
os.startfile('cmd.exe')
Assistant_details.icon_display = 'cmd'
return 'Launching Microsoft Command Prompt'
elif 'run' in string:
os.system('explorer.exe Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}')
Assistant_details.icon_display = 'run'
return 'Launching Run'
elif 'paint' in string or 'mspaint' in string or 'microsoft paint' in string or 'draw' in string or 'colour' in string or 'color' in string:
os.startfile('mspaint.exe')
Assistant_details.icon_display = 'paint'
return 'Launching Microsoft Paint'
elif 'task manager' in string:
os.startfile("taskmgr.exe")
Assistant_details.icon_display = 'task-manager'
return 'Launching Task Manager'
elif 'media player' in string or 'music player' in string or 'music' in string or 'song' in string:
os.startfile("wmplayer.exe")
Assistant_details.icon_display = 'music'
return 'Launching Windows Media Player'
else:
Assistant_details.icon_display = 'not_found'
return "Seems like the application is not installed"
except Exception as e:
Assistant_details.icon_display = 'not_found'
return "Seems like the application is not installed"
class PlayMusic(object):
"""Opens a music streamer and plays a desired song"""
@staticmethod
def music_search(keywords, song):
"""Searches for a song and returns its path if requested else returns a random music path"""
try:
if song:
found = False
for root, directories, files in os.walk(Assistant_details.music_folder):
for file in files:
for keyword in keywords:
if not keyword in file.lower():
found = False
break
found = True
if found:
return root + '\\' + file
return
else:
for root, directories, files in os.walk(Assistant_details.music_folder):
music = root + '\\' + str(random.choice(files))
while not '.mp3' in music:
music = root + '\\' + str(random.choice(files))
return music
except: return
@staticmethod
def play_music(string):
"""Opens a music streamer and plays a desired song"""
if 'play music' in string:
string = string.replace('play music', '')
else:
string = string.replace('play', '')
if Assistant_details.music_folder != 'None' and Assistant_details.music_folder != '':
try:
keywords = string.lower().split()
if len(keywords) == 0:
music_found = PlayMusic.music_search(keywords, False)
else:
music_found = PlayMusic.music_search(keywords, True)
if music_found:
try:
wmp = r"C:\Program Files (x86)\Windows Media Player\wmplayer.exe"
subprocess.Popen([wmp, music_found])
Assistant_details.icon_display = 'music'
return 'Playing ' + string.title()
except:
pass
return PlayMusic.youtube_play(string)
except:
return 'Something went wrong'
else:
try:
return PlayMusic.youtube_play(string)
except:
return 'Something went wrong'
@staticmethod
def youtube_play(string):
try:
results = ys.YoutubeSearch(string, max_results=1).to_dict()
result_dict = results[0]
title = result_dict['title']
id = result_dict['id']
url = "https://m.youtube.com/watch?v=" + id
webbrowser.get().open(url)
os.system("taskkill /im wmplayer.exe")
Assistant_details.icon_display = 'youtube'
return 'Playing ' + '"' + title + '"'
except:
Assistant_details.icon_display = 'internet_error'
return 'Seems like internet is not connected'
class Commands(object):
"""'Commands' class: Contains functions for starting phase of a command, i.e, initialization, processing
start_Assistant() : Listen to the commands and return it in string
check_availability(string_input, commands_present) : checks if a command is acceptable or not
hello_Assistant() : greets the user
help_Assistant() : opens up help window
execute_command(command) : processes the command and calls the required functions"""
@staticmethod
def check_availability(string_input, commands_present):
"""In 'Commands' class - check_availability(str_in, commands_present) : Check if a command is available for execution, else return 'None'"""
for command in commands_present:
if command in string_input:
return command
return
@staticmethod
def hello_Assistant():
"""In 'Commands' class - hello_Assistant() : Greetings for first initialization of the Assistant"""
greet_str = ['Hi There!',
"Hello {},".format(Assistant_details.denotation),
"I'm before you!",
"I'm your Assistant!",
"Hola!",
"What's up!",
"I'm Stark! Your Assistant!"]
order_str = ["How can I help?",
"How can I help you?",
"What do you want me to do?",
"How do you want me to assist you?",
"What do you want me to do?",
"I'm waiting eagerly for your orders!"]
string = str(random.choice(greet_str)) + " " + str(random.choice(order_str))
return string
@staticmethod
def help_Assistant():
Ui_StarkWindow.helpui = Ui_HelpAssistant()
Ui_StarkWindow.helpwindow = QtWidgets.QMainWindow()
Ui_StarkWindow.helpui.setupUi(Ui_StarkWindow.helpwindow)
Ui_StarkWindow.helpwindow.show()
Assistant_details.icon_display = 'help_assistant'
return "Opening Assistant Help"
@staticmethod
def execute_command(command_str):
"""In 'Commands' class - execute_command(command_str) : If a command is recognized as acceptable, run the associated task"""
try:
############ Miscelleneous Commands ###################
if 'what is your name' in command_str or 'who are you' in command_str:
return OtherCommands.name_Assistant(command_str)
elif 'what is my name' in command_str or 'who am i' in command_str or 'who i am' in command_str:
return OtherCommands.owner_name(command_str)
elif 'what is my age' in command_str or 'how old am i' in command_str or 'how old i am' in command_str or 'how much old am i' in command_str or 'how much old i am' in command_str:
return OtherCommands.age_Owner(command_str)
elif 'what is your age' in command_str or 'how much old are you' in command_str or 'how much old you are' in command_str or 'how old are you' in command_str or 'how old you are' in command_str:
return OtherCommands.age_Assistant(command_str)
elif 'what is your owner' in command_str or 'who is your owner' in command_str or 'who is your master' in command_str or 'who owns you' in command_str or 'who is owner' in command_str:
return OtherCommands.own_Assistant(command_str)
elif 'who made you' in command_str or 'who designed you' in command_str or 'who coded you' in command_str or 'who manufactured you' in command_str or 'who created you' in command_str or 'who wrote you' in command_str:
return OtherCommands.coder_Assistant(command_str)
###########################################################
################### Service Commands ######################
elif 'open google' in command_str or 'google' in command_str:
return Search_internet.open_google(command_str)
elif 'increase volume' in command_str or 'decrease volume' in command_str or 'mute volume' in command_str or 'full volume' in command_str:
return VolumeCommands.volume_control(command_str)
elif 'open youtube' in command_str or 'youtube' in command_str:
return Search_internet.open_youtube(command_str)
elif 'launch' in command_str or 'open' in command_str:
return LaunchApp.launch_app(command_str)
elif 'play music' in command_str or 'play' in command_str:
return PlayMusic.play_music(command_str)
elif 'time' in command_str:
return Time.current_time(command_str)
elif 'search' in command_str or 'what' in command_str or 'where' in command_str or 'how' in command_str or 'who' in command_str or 'when' in command_str:
return Search_internet.search_google(command_str)
elif 'location' in command_str or 'navigate' in command_str:
return Location_search.search_location(command_str)
elif 'wikipedia' in command_str:
return Search_internet.wikipedia_search(command_str)
elif 'hi' in command_str or 'hello' in command_str or 'stark' in command_str or 'hey' in command_str or 'hay' in command_str:
return Commands.hello_Assistant()
elif 'help assistant' in command_str:
return Commands.help_Assistant()
##################################################################
else:
return Search_internet.search_google(command_str)
# find command to write
return status
except:
return 'command not found'
class VolumeCommands(object):
"""Controls the volume of the Computer"""
@staticmethod
def volume_control(string):
if 'increase' in string:
return VolumeCommands.increase_volume()
if 'decrease' in string:
return VolumeCommands.decrease_volume()
if 'mute' in string:
return VolumeCommands.mute_volume()
if 'full' in string:
return VolumeCommands.full_volume()
@staticmethod
def increase_volume():
try:
keyboard = Controller()
for i in range(0, 5):
keyboard.press(Key.media_volume_up)
keyboard.release(Key.media_volume_up)
Assistant_details.icon_display = 'volume'
except Exception as e:
pass
return 'Done'
@staticmethod
def decrease_volume():
try:
keyboard = Controller()
for i in range(0, 5):
keyboard.press(Key.media_volume_down)
keyboard.release(Key.media_volume_down)
Assistant_details.icon_display = 'volume'
except Exception as e:
pass
return 'Done'
@staticmethod
def mute_volume():
try:
keyboard = Controller()
keyboard.press(Key.media_volume_mute)
keyboard.release(Key.media_volume_mute)
Assistant_details.icon_display = 'mute'
except Exception as e:
pass
return 'Done'
@staticmethod
def full_volume():
try:
keyboard = Controller()
for i in range(0, 50):
keyboard.press(Key.media_volume_up)
keyboard.release(Key.media_volume_up)
Assistant_details.icon_display = 'volume'
except Exception as e:
pass
return 'Done'
################################ UI Elements ######################################
class Ui_HelpAssistant(object):
def setupUi(self, HelpAssistant):
HelpAssistant.setObjectName("HelpAssistant")
HelpAssistant.setFixedSize(547, 389)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("resources/icons/microphone.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
HelpAssistant.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(HelpAssistant)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(171, 10, 301, 81))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.StarkTitleLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.StarkTitleLayout.setContentsMargins(0, 0, 0, 0)
self.StarkTitleLayout.setObjectName("StarkTitleLayout")
self.StarkTitle = QtWidgets.QLabel(self.verticalLayoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.StarkTitle.sizePolicy().hasHeightForWidth())
self.StarkTitle.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("Colonna MT")
font.setPointSize(30)
font.setBold(False)
font.setWeight(50)
self.StarkTitle.setFont(font)
self.StarkTitle.setAlignment(QtCore.Qt.AlignCenter)
self.StarkTitle.setOpenExternalLinks(False)
self.StarkTitle.setObjectName("StarkTitle")
self.StarkTitleLayout.addWidget(self.StarkTitle)
self.PageTitle_2 = QtWidgets.QLabel(self.verticalLayoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PageTitle_2.sizePolicy().hasHeightForWidth())
self.PageTitle_2.setSizePolicy(sizePolicy)