-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule.py
More file actions
194 lines (161 loc) · 7.8 KB
/
schedule.py
File metadata and controls
194 lines (161 loc) · 7.8 KB
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
# -*- coding: utf-8 -*-
import mysql.connector
# Form implementation generated from reading ui file 'schedule.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
#############################################################
# #
# UI Generation #
# #
#############################################################
class Ui_Dialog(object):
def setupUi(self, Dialog, listValues):
Dialog.setObjectName("Dialog")
Dialog.resize(272, 199)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(10, 150, 251, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.formLayoutWidget = QtWidgets.QWidget(Dialog)
self.formLayoutWidget.setGeometry(QtCore.QRect(10, 20, 251, 131))
self.formLayoutWidget.setObjectName("formLayoutWidget")
self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout.setLabelAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.formLayout.setObjectName("formLayout")
self.lblInstructor = QtWidgets.QLabel(self.formLayoutWidget)
self.lblInstructor.setObjectName("lblInstructor")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.lblInstructor)
self.lblCourse = QtWidgets.QLabel(self.formLayoutWidget)
self.lblCourse.setObjectName("lblCourse")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.lblCourse)
self.lblSection = QtWidgets.QLabel(self.formLayoutWidget)
self.lblSection.setObjectName("lblSection")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.lblSection)
self.txtSection = QtWidgets.QLineEdit(self.formLayoutWidget)
self.txtSection.setObjectName("txtSection")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.txtSection)
self.lblSemester = QtWidgets.QLabel(self.formLayoutWidget)
self.lblSemester.setMouseTracking(False)
self.lblSemester.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.lblSemester.setObjectName("lblSemester")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.lblSemester)
self.cmbInstructor = QtWidgets.QComboBox(self.formLayoutWidget)
self.cmbInstructor.setObjectName("cmbInstructor")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.cmbInstructor)
self.cmbCourse = QtWidgets.QComboBox(self.formLayoutWidget)
self.cmbCourse.setObjectName("cmbCourse")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.cmbCourse)
self.cmbSemester = QtWidgets.QComboBox(self.formLayoutWidget)
self.cmbSemester.setObjectName("cmbSemester")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.cmbSemester)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Dialog)
# Update UI here
self.listValues = listValues
self.initialSetup()
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.lblInstructor.setText(_translate("Dialog", "Instructor:"))
self.lblCourse.setText(_translate("Dialog", "Course:"))
self.lblSection.setText(_translate("Dialog", "Section:"))
self.lblSemester.setText(_translate("Dialog", "Semester:"))
##################### End UI Generation ###################
#############################################################
# #
# Events #
# #
#############################################################
def initialSetup(self):
self.setupDatabase()
self.setValues()
def setupComboBoxInstructor(self, instructors = []):
self.cmbInstructor.clear()
for instructor in instructors:
self.cmbInstructor.addItem(instructor)
def setupComboBoxCourse(self, courses = []):
self.cmbCourse.clear()
for course in courses:
self.cmbCourse.addItem(course)
def setupComboboxSemester(self):
self.cmbSemester.addItem("23SU")
self.cmbSemester.addItem("23FA")
self.cmbSemester.addItem("24SP")
self.cmbSemester.addItem("24SU")
self.cmbSemester.addItem("24FA")
self.cmbSemester.addItem("25SP")
self.cmbSemester.addItem("25SU")
self.cmbSemester.addItem("25FA")
def setValues(self):
if self.listValues == None: #No list
return
self.cmbInstructor.setCurrentText(self.listValues[0])
self.cmbCourse.setCurrentText(self.listValues[1])
self.txtSection.setText(self.listValues[2])
self.cmbSemester.setCurrentText(self.listValues[3])
def getValues(self):
listResult = []
listResult.append(self.cmbInstructor.currentText())
listResult.append(self.cmbCourse.currentText())
listResult.append(self.txtSection.text())
listResult.append(self.cmbSemester.currentText())
return listResult
##################### End Events ###################
#############################################################
# #
# Database #
# #
#############################################################
def setupDatabase(self):
self.connect()
self.refresh()
def connect(self):
self.cnx = mysql.connector.connect(user="root",
password="222488842dahy",
host="127.0.0.1",
database="mydb")
def refresh(self):
# Create a cursor object to execute queries
cursor = self.cnx.cursor()
# Execute a query to retrieve data
query = "Select instructor_name " \
"from Instructor " \
"order by instructor_name asc"
cursor.execute(query)
# Fetch all the rows returned by the query
rows = cursor.fetchall()
instructor = [row[0] for row in rows]
if not instructor:
cursor.close()
return
self.setupComboBoxInstructor(instructor)
query = "Select course_id " \
"from course " \
"order by course_id asc"
cursor.execute(query)
# Fetch all the rows returned by the query
rows = cursor.fetchall()
course = [row[0] for row in rows]
if not course:
cursor.close()
return
self.setupComboBoxCourse(course)
self.setupComboboxSemester()
# Close the cursor and the database connection
cursor.close()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog, None)
Dialog.show()
sys.exit(app.exec_())