-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
152 lines (117 loc) · 4.76 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
import sys
import time
import sqlite3
import bcrypt
import subprocess
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QDialog, QSplashScreen, QWidget
class SplashScreen(QSplashScreen):
def __init__(self):
super(QSplashScreen, self).__init__()
loadUi("splash.ui", self)
self.setWindowFlag(Qt.FramelessWindowHint) # Setting a frameless window
pixmap = QPixmap("background.png")
self.setPixmap(pixmap)
def progress(self):
for i in range(101):
time.sleep(0.1)
self.progressBar.setValue(i)
class Dashboard(QDialog):
def __init__(self):
super(Dashboard,self).__init__()
loadUi("dashboard.ui",self)
self.setFixedWidth(1201)
self.setFixedHeight(801)
self.login1.clicked.connect(self.gotologin)
self.create.clicked.connect(self.gotocreate)
def gotologin(self):
login = LoginScreen()
widget.addWidget(login)
widget.setCurrentIndex(widget.currentIndex()+1)
def gotocreate(self):
create=CreateAccountScreen()
widget.addWidget(create)
widget.setCurrentIndex(widget.currentIndex()+1)
class LoginScreen(QDialog):
def __init__(self):
super(LoginScreen,self).__init__()
loadUi("log_in.ui",self)
self.password_login.setEchoMode(QtWidgets.QLineEdit.Password)
self.login2.clicked.connect(self.loginfunction)
def loginfunction(self):
user=self.username_login.text()
password=self.password_login.text()
if len(user)==0 or len(password)==0:
self.error.setText("Please fill all fields.")
else:
passBytes=password.encode('utf-8')
conn = sqlite3.connect("user_data.db")
cur = conn.cursor()
query = 'SELECT Password FROM Login_info WHERE Username =\''+user+"\'"
cur.execute(query)
result_pass = cur.fetchone()[0]
result_pass2 = bcrypt.checkpw(passBytes,result_pass)
if result_pass2 == True:
print("Successfully logged in.")
self.error.setText("")
option=OptionScreen()
widget.addWidget(option)
widget.setCurrentIndex(widget.currentIndex()+1)
else:
self.error.setText("Invalid username or password!")
class CreateAccountScreen(QDialog):
def __init__(self):
super(CreateAccountScreen,self).__init__()
loadUi("sign_up.ui",self)
self.password_signup.setEchoMode(QtWidgets.QLineEdit.Password)
self.confirmpass_signup.setEchoMode(QtWidgets.QLineEdit.Password)
self.signup1.clicked.connect(self.signupfunction)
def signupfunction(self):
user =self.username_signup.text()
fname =self.fname_signup.text()
lname =self.lname_signup.text()
phonenumber=self.phoneno_signup.text()
password =self.password_signup.text()
confirmpass =self.confirmpass_signup.text()
if len(user)==0 or len(fname)==0 or len(lname)==0 or len(phonenumber)==0 or len(password)==0 or len(confirmpass)==0:
self.error.setText("Please fill in all the fields")
elif password!=confirmpass:
self.error.setText("Passwords do not match")
else:
#Hashing Password
passBytes=password.encode('utf-8')
salt=bcrypt.gensalt()
hashedpassword=bcrypt.hashpw(passBytes,salt)
conn = sqlite3.connect("user_data.db")
cur = conn.cursor()
user_info=[user,fname,lname,phonenumber,hashedpassword]
cur.execute('INSERT INTO Login_info (Username,Fname,Lname,Phone_number,Password) VALUES (?,?,?,?,?)',user_info)
conn.commit()
conn.close()
login = LoginScreen()
widget.addWidget(login)
widget.setCurrentIndex(widget.currentIndex()+1)
class OptionScreen(QDialog):
def __init__(self):
super(OptionScreen,self).__init__()
loadUi("option.ui",self)
self.generation_btn.clicked.connect(self.gotogeneration)
def gotogeneration(self):
subprocess.call([r'C:\Users\Allan\Documents\STRATHMORE\4_YEAR\IS_PROJECT_II\project\Sign_Language_Interpretation_and_Generation\Generation'])
#if __name__ == '__main__':
#main
app = QApplication(sys.argv)
splash = SplashScreen()
splash.show()
splash.progress()
dashboard=Dashboard()
widget=QtWidgets.QStackedWidget()
widget.addWidget(splash)
widget.addWidget(dashboard)
widget.show()
widget.setCurrentIndex(widget.currentIndex()+1)
#splash.finish(widget) Don't need this code since QStackedWidget is in use.
app.exec_()