def initSchedule self self ui tw setColumnCount self ui tw setRowCount

 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
def initSchedule(self):
self.ui.tw.setColumnCount(0)
self.ui.tw.setRowCount(vCfg.pairsCount)
#Select all groups with selected course to list groupNames and sort it
q = QSqlQuery()
q.prepare("SELECT id, name FROM groups WHERE course=?;")
q.bindValue(0, QtCore.QVariant(self.curCourseNum()))
q.exec_()
self.groupNames = []
while q.next():
self.groupNames.append(q.value(1))
self.groupNames.sort(reverse=True)
self.ui.tw.setColumnCount(len(self.groupNames))
#Resize tw`s columns
#and prepare horizontal headers labels
strList = QtCore.QStringList()
j = 0 #column counter
for name in self.groupNames:
strList = strList + name.toStringList()
self.ui.tw.setColumnWidth(j, vCfg.columnWidth)
j = j + 1
self.ui.tw.setHorizontalHeaderLabels(strList)
#Resize rows
for i in range(vCfg.pairsCount):
self.ui.tw.setRowHeight(i, vCfg.rowHeight)
#self.groupNames.sort()
def reloadSchedule(self):
q = QSqlQuery()
day = self.curDayNum()
for i in range(len(self.groupNames)):
for j in range(vCfg.pairsCount):
q.prepare(u"SELECT subject_id, room_id, teacher_id, " + \
u"even_week FROM schedule" + \
u"WHERE day_of_week=? AND group_id=? AND pair_num=?;")
q.bindValue(0, QtCore.QVariant(day))
q.bindValue(1, QtCore.QVariant(self.groupNames[i]))
q.exec_()
s = ['', '']
i = 0
while q.next():
even = q.value(3).toInt()
if i > 2 or even not in [0, 1, 2]:
print("Broken schedule structure! Check it.")
i = i + 1
if not even:
#Same pair on even and not even weeks
s[0] = q.value(0).toString().toUtf8() + '\n'
s[0] = s[0] + q.value(1).toString().toUtf8() + '\n'
s[0] = s[0] + q.value(2).toString().toUtf8()
break
elif even in [1, 2]:
s[even-1] = q.value(0).toString().toUtf8() + '\n'
s[even-1] = s[even-1] + q.value(1).toString().toUtf8()
s[even-1] = s[even-1] + ' '
s[even-1] = s[even-1] + q.value(2).toString().toUtf8()
self.tw.setItem(j, i, QTableWidgetItem(QString(s[0]+s[1])))