-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
93 lines (75 loc) · 3.28 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
import sys
import os
from PyQt5 import QtWidgets, QtGui, QtCore
import webbrowser
from interface import Ui_JARVIS # Assuming Ui_JARVIS is defined in interface.py
class ExternalProcess(QtCore.QObject):
update_text = QtCore.pyqtSignal(str)
def __init__(self, command):
super().__init__()
self.command = command
def run(self):
process = QtCore.QProcess()
process.start(" ".join(self.command))
process.waitForFinished()
output = process.readAllStandardOutput().data().decode()
self.update_text.emit(output)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_JARVIS()
self.ui.setupUi(self)
self.connect_buttons()
self.external_thread = None
def connect_buttons(self):
self.ui.home.clicked.connect(self.show_home)
self.ui.advance.clicked.connect(self.show_advance)
self.ui.about.clicked.connect(self.show_about)
self.ui.pushButton.clicked.connect(lambda: self.open_url("https://google.com"))
self.ui.pushButton_2.clicked.connect(lambda: self.open_url("https://github.com"))
self.ui.pushButton_3.clicked.connect(lambda: self.open_url("https://youtube.com"))
self.ui.pushButton_4.clicked.connect(lambda: self.open_url("https://github.com/Likhithsai2580/Automated-YouTube-Video-Creator"))
self.ui.pushButton_5.clicked.connect(lambda: self.open_url("https://likhithsai2580.github.io/My-Website/"))
def start_external_process(self):
if self.external_thread and self.external_thread.isRunning():
return
command = ['python', 'JARVIS.py']
self.external_process = ExternalProcess(command)
self.external_thread = QtCore.QThread()
self.external_process.moveToThread(self.external_thread)
self.external_process.update_text.connect(self.append_text)
self.external_thread.started.connect(self.external_process.run)
self.external_thread.start()
def append_text(self, text):
cursor = self.ui.console.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertText(text)
self.ui.console.setTextCursor(cursor)
self.ui.console.ensureCursorVisible()
def show_home(self):
self.ui.stackedWidget.setCurrentIndex(0)
self.load_gif("assests/initalizing.gif", self.ui.label_3)
self.load_gif("assests/loop.gif", self.ui.label_9)
self.load_gif("assests/loop2.gif", self.ui.label_10)
self.load_gif("assests/loading.gif", self.ui.loading)
self.start_external_process()
QtCore.QTimer.singleShot(20000, self.load_second_gif)
def load_gif(self, path, label):
movie = QtGui.QMovie(path)
label.setMovie(movie)
label.setScaledContents(True)
movie.start()
def load_second_gif(self):
self.ui.loading.clear()
self.load_gif("assests/iron-man.gif", self.ui.loading)
def show_advance(self):
self.ui.stackedWidget.setCurrentIndex(1)
def show_about(self):
self.ui.stackedWidget.setCurrentIndex(2)
def open_url(self, url):
webbrowser.open(url)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())