-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMainpage.py
235 lines (172 loc) · 10.4 KB
/
Mainpage.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
#Mainpage.py
from PyQt5.QtWidgets import QMainWindow, QFileDialog, QMessageBox, QTableWidget, QLineEdit, QPushButton, QTimeEdit, QTextEdit
from PyQt5.QtGui import QPixmap
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.uic import loadUi
from PyQt5.QtCore import QByteArray, QBuffer, QIODevice
import sqlite3
import allimages
import arrowimages
class MainScreen(QMainWindow):
def __init__(self, username="", email="", password="", age="", phonenumber="", location="", gender=""):
super(MainScreen, self).__init__()
loadUi("Mainpage.ui", self)
self.username = username
self.email = email
self.password = password
self.age = age
self.phonenumber = phonenumber
self.location = location
self.gender = gender
self.user_image = None
self.current_index = 0 # Keep track of the current user index
self.loadUser(self.current_index)
### ASSIGNING EACH BUTTON TO A PAGE IN THE STACKED WIDGET IN THE MAIN ###
self.Home_button.clicked.connect(lambda: self.stackedWidget.setCurrentWidget(self.HomePage))
self.Find_match_button.clicked.connect(lambda: self.stackedWidget.setCurrentWidget(self.Match_Page))
self.Others_button.clicked.connect(lambda: self.stackedWidget.setCurrentWidget(self.Others_page))
self.Date_button.clicked.connect(lambda: self.stackedWidget.setCurrentWidget(self.Date_page))
self.Account_Button.clicked.connect(lambda: self.stackedWidget.setCurrentWidget(self.Account_page))
# ACTION TO OPEN FILE IMAGE AND UPLOAD ON THE ACOUNT PAGE ##
self.Upload_image_button.clicked.connect(self.updateProfilePicture)
## SETTING THE TEXT LABEL FIELD IN MAINPAGE UI TO THE USERNAME OF THE USER ##
self.username_label.setText(self.username)
## BUTTON THAT UPDATES THE USER PROFILE AUTOMATICALLY AS HE ENTERS THE MAINPAGE ##
self.Save_button.clicked.connect(self.UpdateProfile)
## BUTTON THAT HELPS VIEW SUGGESTIONS ##
self.View_suggestions_button.clicked.connect(self.viewSuggestions)
## BUTTON THAT MOVES TO THE NEXT USER IN THE OTHER PROFILES PAGE ##
self.Right_arrow_button.clicked.connect(self.nextUser)
## BUTTON THAT MOVES TO THE PREVIOUS USER IN THE OTHER PROFILES PAGE ##
self.Left_arrow_button.clicked.connect(self.previousUser)
# Connect calendar widget click event to set event date
self.calendarWidget.clicked.connect(self.setEventDate)
# Connect save button to save event function
self.Event_save_button.clicked.connect(self.saveEvent)
###########################################################################################
## METHOD THAT AUTOMATICALLY SETS UP THE USERPROFILE ON LOGIN OR CREATE ACCOUNT ##
###########################################################################################
def setUserProfile(self):
try:
conn=sqlite3.connect("userInfo.db")
cursor=conn.cursor()
cursor.execute('''SELECT Username,Password,Age,Email,Location,Phone Number,Gender,Image
FROM Users
WHERE Username=?''',(self.username,))
user_data=cursor.fetchone()
conn.close()
if user_data:
self.username, self.password, self.age, self.email, self.location, self.phonenumber, self.gender, image_data = user_data
pixmap = QPixmap()
pixmap.loadFromData(image_data)
self.user_image = pixmap
self.Account_image_Input.setPixmap(pixmap)
self.Account_username_Input.setText(self.username)
self.Account_password_Input.setText(self.password)
self.Account_age_Input.setText(str(self.age))
self.Account_email_Input.setText(self.email)
self.Account_location_Input.setText(self.location)
self.Account_Phone_number_Input.setText(str(self.phonenumber))
self.Account_gender_Input.setText(self.gender)
except Exception as e:
QMessageBox.critical(self, "Error", f"Failed to fetch user profile: {str(e)}")
######################################################################################################
## FUNCTION THAT ALLOWS USER TO UPDATE HIS PROFILE PICTURE ##
######################################################################################################
def updateProfilePicture(self):
pass
#####################################################################################################
## FUNCTION THAT ALLOWS USER TO UPDATE HIS PROFILE ##
#####################################################################################################
def UpdateProfile(self):
pass
#####################################################################################################
## FUNCTION THAT ALLOWS USER IN THE HOME TO SEE SUGGESTIONS ##
#####################################################################################################
def viewSuggestions(self):
try:
conn=sqlite3.connect("UserInfo.db")
cur=conn.cursor()
sql_query="SELECT Image,Username,Age,Location,Gender FROM Users WHERE Username!=? Limit 10"
rows=cur.execute(sql_query,(self.Username)).fetchall()
self.tableWidget.setRowCount(len(rows))
for i, row in enumerate(rows):
QPixmap
image_data=row[0]
pixmap=QPixmap()
pixmap.loadFFROMData(image_data)
label=QtWidgets.QLabel()
label.setPixmap(pixmap.scaled(100,100))
label.setAlignement(QtCore.Qt.AlignCenter)
self.tableWidget.setRowHeight(i,120)
self.tableWidget.setCellWidget(i,0,label)
for j in range(1,len(row)):
item=QtWidgets.QTableWidgetItem(str(row[j]))
item.setTextAlignment(QtCore.Qt.AlignCenter)
self.tableWidget.setItem(i,j,item)
conn.close()
except Exception as e:
QMessageBox.critical(self,"Error",f"Failed to view suggestions:{str(e)}")
#############################################################################################################
## FUNCTION THAT ALLOWS YOU TO LOAD A USERS PROFILE ON THE OTHER PROFILES PAGE FROM THE DATA BASE ##
#####################################################################################################
def loadUser(self, index):
pass
#####################################################################################################
## FUNCTION THAT ALLOWS USER TO MOVE TO THE NEXT USER IN THE OTHER PROFILES PAGE ##
#####################################################################################################
def nextUser(self):
pass
#####################################################################################################
## FUNCTION THAT ALLOWS USER TO MOVE TO THE PREVIOUS USER IN THE OTHER PROFILES PAGE ##
#####################################################################################################
def previousUser(self):
pass
#####################################################################################################
## FUNCTION THAT ALLOWS USER TO SAVE AN EVENT IN THE EVENT PAGE ##
#####################################################################################################
def saveEvent(self):
event_name = self.event_name_line_edit.text()
start_time = self.Start_time_edit.time().toString()
end_time = self.End_time_edit.time().toString()
description = self.Description_text_edit.toPlainText()
event_date = self.event_date_edit.text()
username= self.username
try:
conn=sqlite3.connect("Event.db")
cursor=conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Events(
EventID INTEGER PRIMARY KEY AUTOINCREMENT,
EventName TEXT,
StartTime TEXT,
EndTime TEXT,
Description TEXT,
EventDate TEXT,
Username TEXT,
)
''')
cursor.execute('''
INSERT INTO Events (EventName, StartTime, EndTime, Description, EventDate, Username)
VALUES (?,?,?,?,?,?)
''', (event_name,start_time,end_time,description,event_date,username))
conn.commit()
conn.close
QMessageBox.information(self,"Success","Event saved successfully!")
except Exception as e:
QMessageBox.critical(self,"Error",f"Failed to save event:{str(e)}")
#####################################################################################################
## FUNCTION THAT ALLOWS USER TO SET THE EVENT FIELDS FOR A SPECIFIC USER FROM THE DATABASE ##
#####################################################################################################
def setEventFields(self, event_data):
pass
#####################################################################################################
## FUNCTION THAT ALLOWS USER TO LOAD EVENT FROM THE DATA BASE TO THE CALENDAR ##
#####################################################################################################
def loadEvent(self):
pass
#####################################################################################################
## FUNCTION THAT SETS THE DATE EDIT TO THE SELECTED DATE ON THE CALENDAR WIDGET ##
#####################################################################################################
def setEventDate(self):
pass