tirilane
/
egon
Archived
1
0
Fork 0

Finished! The exception handling is not great, but unless you writes it wrong on purpose, it should be okay.

This commit is contained in:
Tiril Anette Langfeldt Rødland 2008-06-18 19:26:48 +00:00
parent e68b9852a0
commit 1f47a395d4
2 changed files with 208 additions and 177 deletions

BIN
egon.db

Binary file not shown.

361
egon.py
View File

@ -18,7 +18,7 @@ from pysqlite2 import dbapi2 as sqlite
from qrc_resources import * from qrc_resources import *
__version__ = "0.0.2" __version__ = "0.9.0"
main = None main = None
@ -66,7 +66,7 @@ class MainWindow(QMainWindow):
self.calendarDockWidget.setObjectName("CalendarDockWidget") self.calendarDockWidget.setObjectName("CalendarDockWidget")
self.calendarDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea|Qt.RightDockWidgetArea|Qt.BottomDockWidgetArea) self.calendarDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea|Qt.RightDockWidgetArea|Qt.BottomDockWidgetArea)
self.calendar = QCalendarWidget() self.calendar = QCalendarWidget()
self.calendar.setFirstDayOfWeek(Qt.Monday) self.calendar.setFirstDayOfWeek(Qt.Monday)
self.calendarLayout = QVBoxLayout() self.calendarLayout = QVBoxLayout()
self.calendarLayout.addWidget(self.calendar) self.calendarLayout.addWidget(self.calendar)
self.calendarFrame.setLayout(self.calendarLayout) self.calendarFrame.setLayout(self.calendarLayout)
@ -75,8 +75,8 @@ class MainWindow(QMainWindow):
# The semesters # The semesters
global semester, semesters, termList global semester, semesters, termList
termList = QStringList() termList = QStringList()
termList.append(self.trUtf8("Spring")) termList.append(self.trUtf8("Spring"))
termList.append(self.trUtf8("Autumn")) termList.append(self.trUtf8("Autumn"))
semesters = getSemestersFromDB() semesters = getSemestersFromDB()
semester = self.getLatestSemester(semesters) semester = self.getLatestSemester(semesters)
@ -121,7 +121,6 @@ class MainWindow(QMainWindow):
self.connect(self.reading.readingDoneButton, SIGNAL("pressed()"), self.doneReading) self.connect(self.reading.readingDoneButton, SIGNAL("pressed()"), self.doneReading)
self.connect(self.schedule.addScheduleButton, SIGNAL("pressed()"), self.addLesson) self.connect(self.schedule.addScheduleButton, SIGNAL("pressed()"), self.addLesson)
self.connect(self.schedule.deleteScheduleButton, SIGNAL("pressed()"), self.deleteLesson) self.connect(self.schedule.deleteScheduleButton, SIGNAL("pressed()"), self.deleteLesson)
self.connect(self.calendar, SIGNAL("selectionChanged()"), self.changeDay)
# The toolbars # The toolbars
fileToolbar = self.addToolBar("File") fileToolbar = self.addToolBar("File")
@ -134,7 +133,7 @@ class MainWindow(QMainWindow):
# Set the title # Set the title
self.setMainWindowTitle() self.setMainWindowTitle()
# The courses # The courses
courses = getCourses() courses = getCourses()
makeCoursesString() makeCoursesString()
@ -144,13 +143,23 @@ class MainWindow(QMainWindow):
# Semester # Semester
## Open the New dialog
def fileNew(self):
self.nsdlg = NewSemesterDlg()
self.nsdlg.show()
## Open the Open dialog
def fileOpen(self):
self.osdlg = OpenSemesterDlg()
self.osdlg.show()
## Return the latest semester ## Return the latest semester
def getLatestSemester(self, semesters): def getLatestSemester(self, semesters):
if len(semesters) == 0: if len(semesters) == 0:
return None return None
global termList global termList
max = semesters[0] max = semesters[0]
for s in semesters: for s in semesters:
if s.getYear() > max.getYear(): if s.getYear() > max.getYear():
max = s max = s
if s.getYear() == max.getYear(): if s.getYear() == max.getYear():
@ -183,10 +192,10 @@ class MainWindow(QMainWindow):
def completeAssignment(self, completionLevel): def completeAssignment(self, completionLevel):
course, number = self.getCourseAndNumber() course, number = self.getCourseAndNumber()
table, row = self.getAssignmentTableAndRow() table, row = self.getAssignmentTableAndRow()
updateAssignmentCompletion(course, number, completionLevel) updateAssignmentCompletion(course, number, completionLevel)
item = QTableWidgetItem(QString(completionLevel)) item = QTableWidgetItem(QString(completionLevel))
item.setBackground(self.assignment.makeBrush(completionLevel)) item.setBackground(self.assignment.makeBrush(completionLevel))
table.setItem(row, 4, item) table.setItem(row, 4, item)
table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents) table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
## Return the assignment table and its current row ## Return the assignment table and its current row
@ -202,7 +211,7 @@ class MainWindow(QMainWindow):
numberItem = table.item(row, 2) numberItem = table.item(row, 2)
courseFull = courseItem.text() courseFull = courseItem.text()
number = numberItem.text() number = numberItem.text()
course = getCourseCode(courseFull) course = getCourseCode(courseFull)
return course, number return course, number
# Reading # Reading
@ -235,11 +244,11 @@ class MainWindow(QMainWindow):
table.setItem(row, 6, item) table.setItem(row, 6, item)
table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents) table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
week = (table.item(row, 0).text().toInt())[0] week = (table.item(row, 0).text().toInt())[0]
courseFull = table.item(row, 1).text() courseFull = table.item(row, 1).text()
courseCode = QString(getCourseCode(courseFull)) courseCode = QString(getCourseCode(courseFull))
bookTitle = table.item(row, 2).text() bookTitle = table.item(row, 2).text()
book = getBookWithTitleFromDB(bookTitle) book = getBookWithTitleFromDB(bookTitle)
bookIsbn = book.getIsbn() bookIsbn = book.getIsbn()
updateReadingDone(week, courseCode, bookIsbn, True) updateReadingDone(week, courseCode, bookIsbn, True)
## Return the reading table and its current row ## Return the reading table and its current row
@ -327,23 +336,13 @@ class MainWindow(QMainWindow):
## Make and open the About dialog ## Make and open the About dialog
def helpAbout(self): def helpAbout(self):
QMessageBox.about(self, "About %s" % self.title, u""" QMessageBox.about(self, "About %s" % self.title, u"""
<b>%s</b> v %s <b>%s</b> v %s
<p>Copyright &copy; 2008 Tiril Anette Langfeldt Rødland. No rights reserved. <p>Copyright &copy; 2008 Tiril Anette Langfeldt Rødland. No rights reserved.
<p>You may modify and redistribute the program under the terms of the GPL. The license can be found here: http://www.gnu.org/licenses/gpl.html <p>You may modify and redistribute the program under the terms of the GPL. The license can be found here: http://www.gnu.org/licenses/gpl.html
<p>This application is mainly for use by students, and can be used to keep track of assignments, planned readings and the schedule. <p>This application is mainly for use by students, and can be used to keep track of assignments, planned readings and the schedule.
<p>Python %s - Qt %s - PyQt %s on %s <p>Python %s - Qt %s - PyQt %s on %s
<p>Developer: Tiril Anette Langfeldt Rødland, tirilane@pvv.ntnu.no <p>Developer: Tiril Anette Langfeldt Rødland, tirilane@pvv.ntnu.no
""" % (self.title, __version__, platform.python_version(), QT_VERSION_STR, PYQT_VERSION_STR, platform.system())) """ % (self.title, __version__, platform.python_version(), QT_VERSION_STR, PYQT_VERSION_STR, platform.system()))
## Open the New dialog
def fileNew(self):
self.nsdlg = NewSemesterDlg()
self.nsdlg.show()
## Open the Open dialog
def fileOpen(self):
self.osdlg = OpenSemesterDlg()
self.osdlg.show()
## Updates the File menu ## Updates the File menu
def updateFileMenu(self): def updateFileMenu(self):
@ -402,15 +401,15 @@ class NewSemesterDlg(QDialog):
self.termLabel = QLabel(self.trUtf8("Term")) self.termLabel = QLabel(self.trUtf8("Term"))
self.yearLabel = QLabel(self.trUtf8("Year")) self.yearLabel = QLabel(self.trUtf8("Year"))
# Widgets # Widgets
self.termEdit = QComboBox() self.termEdit = QComboBox()
self.yearEdit = QSpinBox() self.yearEdit = QSpinBox()
self.termEdit.addItems(getMain().getTermList()) self.termEdit.addItems(getMain().getTermList())
self.yearEdit.setRange(2000, 2050) self.yearEdit.setRange(2000, 2050)
self.yearEdit.setSingleStep(1) self.yearEdit.setSingleStep(1)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Layout # Layout
layout = QGridLayout() layout = QGridLayout()
layout.addWidget(self.termLabel, 0, 0) layout.addWidget(self.termLabel, 0, 0)
layout.addWidget(self.termEdit, 0, 1) layout.addWidget(self.termEdit, 0, 1)
@ -430,9 +429,9 @@ class NewSemesterDlg(QDialog):
def accept(self): def accept(self):
term = unicode(self.termEdit.currentText()) term = unicode(self.termEdit.currentText())
year = self.yearEdit.value() year = self.yearEdit.value()
global semester global semester
semester = SemesterModel(term, year) semester = SemesterModel(term, year)
addNewSemesterToDB(term, year) addNewSemesterToDB(term, year)
getMain().load(semester) getMain().load(semester)
getMain().setMainWindowTitle() getMain().setMainWindowTitle()
self.close() self.close()
@ -458,7 +457,7 @@ class OpenSemesterDlg(QDialog):
layout = QVBoxLayout() layout = QVBoxLayout()
layout.addWidget(self.semesterList) layout.addWidget(self.semesterList)
layout.addStretch() layout.addStretch()
layout.addWidget(self.buttonBox) layout.addWidget(self.buttonBox)
self.setLayout(layout) self.setLayout(layout)
# Connect statements # Connect statements
@ -552,13 +551,13 @@ class AssignmentTab(QWidget):
# Widgets # Widgets
self.addAssignmentButton = QPushButton("Add assignment") self.addAssignmentButton = QPushButton("Add assignment")
self.completeAssignmentBox = QComboBox() self.completeAssignmentBox = QComboBox()
self.deleteAssignmentButton = QPushButton("Delete assignment") self.deleteAssignmentButton = QPushButton("Delete assignment")
completeTypes = [self.trUtf8("Not available"), self.trUtf8("Available"), self.trUtf8("Begun"), self.trUtf8("Finished"), self.trUtf8("Delivered"), self.trUtf8("Approved"), self.trUtf8("Not approved")] completeTypes = [self.trUtf8("Not available"), self.trUtf8("Available"), self.trUtf8("Begun"), self.trUtf8("Finished"), self.trUtf8("Delivered"), self.trUtf8("Approved"), self.trUtf8("Not approved")]
self.completeAssignmentBox.addItems(completeTypes) self.completeAssignmentBox.addItems(completeTypes)
# Make the table # Make the table
self.makeTable() self.makeTable()
# Layout # Layout
self.vlayout = QVBoxLayout() self.vlayout = QVBoxLayout()
@ -576,31 +575,31 @@ class AssignmentTab(QWidget):
self.assignmentTable = QTableWidget(0, 5, self) self.assignmentTable = QTableWidget(0, 5, self)
self.assignmentTable.clear() self.assignmentTable.clear()
self.assignmentHeaderList = QStringList() self.assignmentHeaderList = QStringList()
self.assignmentHeaderList.append(self.trUtf8("Date")) self.assignmentHeaderList.append(self.trUtf8("Date"))
self.assignmentHeaderList.append(self.trUtf8("Course")) self.assignmentHeaderList.append(self.trUtf8("Course"))
self.assignmentHeaderList.append(self.trUtf8("Number")) self.assignmentHeaderList.append(self.trUtf8("Number"))
self.assignmentHeaderList.append(self.trUtf8("Description")) self.assignmentHeaderList.append(self.trUtf8("Description"))
self.assignmentHeaderList.append(self.trUtf8("Complete")) self.assignmentHeaderList.append(self.trUtf8("Complete"))
self.assignmentTable.setHorizontalHeaderLabels(self.assignmentHeaderList) self.assignmentTable.setHorizontalHeaderLabels(self.assignmentHeaderList)
self.assignmentTable.setAlternatingRowColors(True) self.assignmentTable.setAlternatingRowColors(True)
self.assignmentTable.setEditTriggers(QAbstractItemView.NoEditTriggers) self.assignmentTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.assignmentTable.setSelectionBehavior(QAbstractItemView.SelectRows) self.assignmentTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.assignmentTable.setSelectionMode(QAbstractItemView.SingleSelection) self.assignmentTable.setSelectionMode(QAbstractItemView.SingleSelection)
selected = None selected = None
## Add the assignments of the semester to the table ## Add the assignments of the semester to the table
def updateTable(self, semester, current=None): def updateTable(self, semester, current=None):
self.assignments = getAssignmentsFromDB(semester) self.assignments = getAssignmentsFromDB(semester)
rows = len(self.assignments) rows = len(self.assignments)
self.assignmentTable.setRowCount(rows) self.assignmentTable.setRowCount(rows)
for row in range(rows): for row in range(rows):
self.addAssignmentToTable(row) self.addAssignmentToTable(row)
self.assignmentTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents) self.assignmentTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
self.assignmentTable.sortItems(0, Qt.AscendingOrder) self.assignmentTable.sortItems(0, Qt.AscendingOrder)
## Add new assignment to Table ## Add new assignment to Table
@ -608,15 +607,15 @@ class AssignmentTab(QWidget):
if assignment == None: if assignment == None:
assignment = self.assignments[row] assignment = self.assignments[row]
complete = QString(assignment.getComplete()) complete = QString(assignment.getComplete())
brush = self.makeBrush(complete) brush = self.makeBrush(complete)
self.assignmentTable.setItem(row, 0, QTableWidgetItem(QString(assignment.getDate().toString("yyyy-MM-dd hh:mm, ddd")))) self.assignmentTable.setItem(row, 0, QTableWidgetItem(QString(assignment.getDate().toString("yyyy-MM-dd hh:mm, ddd"))))
self.assignmentTable.setItem(row, 1, QTableWidgetItem(QString(assignment.getCourse().getFull()))) self.assignmentTable.setItem(row, 1, QTableWidgetItem(QString(assignment.getCourse().getFull())))
self.assignmentTable.setItem(row, 2, QTableWidgetItem(QString("%i" % assignment.getNumber()))) self.assignmentTable.setItem(row, 2, QTableWidgetItem(QString("%i" % assignment.getNumber())))
self.assignmentTable.setItem(row, 3, QTableWidgetItem(QString("%s" % assignment.getDescription()))) self.assignmentTable.setItem(row, 3, QTableWidgetItem(QString("%s" % assignment.getDescription())))
completeItem = QTableWidgetItem(complete) completeItem = QTableWidgetItem(complete)
completeItem.setBackground(brush) completeItem.setBackground(brush)
self.assignmentTable.setItem(row, 4, completeItem) self.assignmentTable.setItem(row, 4, completeItem)
@ -643,7 +642,7 @@ class AssignmentTab(QWidget):
brush.setColor(QColor(Qt.red)) brush.setColor(QColor(Qt.red))
else: else:
brush.setStyle(Qt.NoBrush) brush.setStyle(Qt.NoBrush)
return brush return brush
### The Add Assignment dialog ### The Add Assignment dialog
@ -653,53 +652,53 @@ class AssignmentDlg(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super(AssignmentDlg, self).__init__(parent) super(AssignmentDlg, self).__init__(parent)
# Labels # Labels
self.dateLabel = QLabel(self.trUtf8("&Date")) self.dateLabel = QLabel(self.trUtf8("&Date"))
self.courseLabel = QLabel(self.trUtf8("&Course")) self.courseLabel = QLabel(self.trUtf8("&Course"))
self.numberLabel = QLabel(self.trUtf8("&Number")) self.numberLabel = QLabel(self.trUtf8("&Number"))
self.descriptionLabel = QLabel(self.trUtf8("De&scription")) self.descriptionLabel = QLabel(self.trUtf8("De&scription"))
self.completeLabel = QLabel(self.trUtf8("&Complete")) self.completeLabel = QLabel(self.trUtf8("&Complete"))
# Widgets # Widgets
self.dateEdit = QLineEdit("DD.MM.YYYY HH:MM") self.dateEdit = QLineEdit("DD.MM.YYYY HH:MM")
self.dateEdit.setSelection(0, 16) self.dateEdit.setSelection(0, 16)
self.courseEdit = QComboBox() self.courseEdit = QComboBox()
self.courseEdit.addItems(makeCoursesString()) self.courseEdit.addItems(makeCoursesString())
self.numberEdit = QSpinBox() self.numberEdit = QSpinBox()
self.numberEdit.setRange(1, 20) self.numberEdit.setRange(1, 20)
self.descriptionEdit = QLineEdit() self.descriptionEdit = QLineEdit()
self.completeEdit = QComboBox() self.completeEdit = QComboBox()
completeTypes = [self.trUtf8("Not available"), self.trUtf8("Available"), self.trUtf8("Begun"), self.trUtf8("Finished"), self.trUtf8("Delivered"), self.trUtf8("Approved"), self.trUtf8("Not approved")] completeTypes = [self.trUtf8("Not available"), self.trUtf8("Available"), self.trUtf8("Begun"), self.trUtf8("Finished"), self.trUtf8("Delivered"), self.trUtf8("Approved"), self.trUtf8("Not approved")]
self.completeEdit.addItems(completeTypes) self.completeEdit.addItems(completeTypes)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies # Buddies
self.dateLabel.setBuddy(self.dateEdit) self.dateLabel.setBuddy(self.dateEdit)
self.courseLabel.setBuddy(self.courseEdit) self.courseLabel.setBuddy(self.courseEdit)
self.numberLabel.setBuddy(self.numberEdit) self.numberLabel.setBuddy(self.numberEdit)
self.descriptionLabel.setBuddy(self.descriptionEdit) self.descriptionLabel.setBuddy(self.descriptionEdit)
self.completeLabel.setBuddy(self.completeEdit) self.completeLabel.setBuddy(self.completeEdit)
# Layout # Layout
self.layout = QGridLayout() self.layout = QGridLayout()
self.layout.addWidget(self.dateLabel, 0, 0) self.layout.addWidget(self.dateLabel, 0, 0)
self.layout.addWidget(self.courseLabel, 1, 0) self.layout.addWidget(self.courseLabel, 1, 0)
self.layout.addWidget(self.numberLabel, 2, 0) self.layout.addWidget(self.numberLabel, 2, 0)
self.layout.addWidget(self.descriptionLabel, 3, 0) self.layout.addWidget(self.descriptionLabel, 3, 0)
self.layout.addWidget(self.completeLabel, 4, 0) self.layout.addWidget(self.completeLabel, 4, 0)
self.layout.addWidget(self.dateEdit, 0, 1) self.layout.addWidget(self.dateEdit, 0, 1)
self.layout.addWidget(self.courseEdit, 1, 1) self.layout.addWidget(self.courseEdit, 1, 1)
self.layout.addWidget(self.numberEdit, 2, 1) self.layout.addWidget(self.numberEdit, 2, 1)
self.layout.addWidget(self.descriptionEdit, 3, 1) self.layout.addWidget(self.descriptionEdit, 3, 1)
self.layout.addWidget(self.completeEdit, 4, 1) self.layout.addWidget(self.completeEdit, 4, 1)
self.layout.addWidget(self.buttonBox, 5, 0, 1, 2) self.layout.addWidget(self.buttonBox, 5, 0, 1, 2)
self.setLayout(self.layout) self.setLayout(self.layout)
# Connect statements # Connect statements
self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
# Set the title # Set the title
self.setWindowTitle(self.trUtf8("Add new assignment")) self.setWindowTitle(self.trUtf8("Add new assignment"))
## Return an array with the values of the widgets ## Return an array with the values of the widgets
@ -721,6 +720,13 @@ class AssignmentDlg(QDialog):
description = assignmentList[3] description = assignmentList[3]
complete = assignmentList[4] complete = assignmentList[4]
regex = QRegExp(r"[01-31].[01-12].[2000-2050] [00-23]:[00-60]")
validator = QRegExpValidator(regex, self)
valid = validator.validate(dateString, 16)
if valid == QValidator.Invalid:
regexMessage = QErrorMessage()
regexMessage.showMessage(QString(self.trUtf8("The date is not in a correct format.")))
if len(dateString) <= 11: if len(dateString) <= 11:
dateList = dateString.split('.') dateList = dateString.split('.')
timeList = ['00', '00'] timeList = ['00', '00']
@ -728,22 +734,47 @@ class AssignmentDlg(QDialog):
dateTime = dateString.split() dateTime = dateString.split()
dateList = dateTime[0].split('.') dateList = dateTime[0].split('.')
timeList = dateTime[1].split(':') timeList = dateTime[1].split(':')
print dateList, timeList
date = QDate(string.atoi(dateList[2]), string.atoi(dateList[1]), string.atoi(dateList[0])) if dateList[1] > '13':
time = QTime(string.atoi(timeList[0]), string.atoi(timeList[1])) dateMessage = QErrorMessage()
datetime = QDateTime(date, time) dateMessage.showMessage(QString(self.trUtf8("The month is not valid. Please enter a valid date.")))
print dateList[1]
elif dateList[0] > '31':
dateMessage = QErrorMessage()
dateMessage.showMessage(QString(self.trUtf8("The day is not valid. Please enter a valid date.")))
print dateList[0]
elif timeList[0] > '23':
dateMessage = QErrorMessage()
dateMessage.showMessage(QString(self.trUtf8("The hour is not valid. Please enter a valid time.")))
print timeList[0]
elif timeList[1] > '59':
dateMessage = QErrorMessage()
dateMessage.showMessage(QString(self.trUtf8("The minutes are not valid. Please enter a valid time.")))
print timeList[1]
else:
try:
date = QDate(string.atoi(dateList[2]), string.atoi(dateList[1]), string.atoi(dateList[0]))
time = QTime(string.atoi(timeList[0]), string.atoi(timeList[1]))
datetime = QDateTime(date, time)
except ValueError, e:
valueMessage = QErrorMessage()
valueMessage.showMessage(QString(self.trUtf8("The date is not valid. Please enter a date on the DD.MM.YYYY HH:MM form.")))
course = getCourseFromDB(getCourseCode(courseFull)) course = getCourseFromDB(getCourseCode(courseFull))
global semester try:
addNewAssignmentToDB(semester, datetime, course, number, description, complete) global semester
addNewAssignmentToDB(semester, datetime, course, number, description, complete)
assignment = AssignmentModel(datetime, course, number, description, complete)
except UnboundLocalError, e:
pass
assignment = AssignmentModel(datetime, course, number, description, complete) table = getMain().assignment.assignmentTable
table = getMain().assignment.assignmentTable row = table.rowCount()
row = table.rowCount() table.insertRow(row)
table.insertRow(row) getMain().assignment.addAssignmentToTable(row, assignment)
getMain().assignment.addAssignmentToTable(row, assignment) table.sortItems(0, Qt.AscendingOrder)
table.sortItems(0, Qt.AscendingOrder)
self.close() self.close()
@ -798,7 +829,7 @@ class ReadingTab(QWidget):
self.deleteReadingButton = QPushButton(self.trUtf8("Delete pages")) self.deleteReadingButton = QPushButton(self.trUtf8("Delete pages"))
self.readingDoneButton = QPushButton(self.trUtf8("Done")) self.readingDoneButton = QPushButton(self.trUtf8("Done"))
# Make the table # Make the table
self.makeTable() self.makeTable()
# Layout # Layout
@ -816,15 +847,15 @@ class ReadingTab(QWidget):
def makeTable(self, current=None): def makeTable(self, current=None):
self.readingTable = QTableWidget(0, 7, self) self.readingTable = QTableWidget(0, 7, self)
self.readingTable.clear() self.readingTable.clear()
self.readingHeaderList = QStringList() self.readingHeaderList = QStringList()
self.readingHeaderList.append(self.trUtf8("Week")) self.readingHeaderList.append(self.trUtf8("Week"))
self.readingHeaderList.append(self.trUtf8("Course")) self.readingHeaderList.append(self.trUtf8("Course"))
self.readingHeaderList.append(self.trUtf8("Book")) self.readingHeaderList.append(self.trUtf8("Book"))
self.readingHeaderList.append(self.trUtf8("Chapter")) self.readingHeaderList.append(self.trUtf8("Chapter"))
self.readingHeaderList.append(self.trUtf8("Pages")) self.readingHeaderList.append(self.trUtf8("Pages"))
self.readingHeaderList.append(self.trUtf8("Number of pages")) self.readingHeaderList.append(self.trUtf8("Number of pages"))
self.readingHeaderList.append(self.trUtf8("Done")) self.readingHeaderList.append(self.trUtf8("Done"))
self.readingTable.setHorizontalHeaderLabels(self.readingHeaderList) self.readingTable.setHorizontalHeaderLabels(self.readingHeaderList)
self.readingTable.setAlternatingRowColors(True) self.readingTable.setAlternatingRowColors(True)
self.readingTable.setEditTriggers(QAbstractItemView.NoEditTriggers) self.readingTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.readingTable.setSelectionBehavior(QAbstractItemView.SelectRows) self.readingTable.setSelectionBehavior(QAbstractItemView.SelectRows)
@ -851,7 +882,7 @@ class ReadingTab(QWidget):
if reading.getDone(): if reading.getDone():
doneString = self.trUtf8("Done") doneString = self.trUtf8("Done")
brush.setColor(Qt.green) brush.setColor(Qt.green)
else: else:
doneString = self.trUtf8("Not done") doneString = self.trUtf8("Not done")
brush.setColor(Qt.red) brush.setColor(Qt.red)
@ -859,12 +890,12 @@ class ReadingTab(QWidget):
self.readingTable.setItem(row, 0, QTableWidgetItem(QString("%02s" % reading.getWeek()))) self.readingTable.setItem(row, 0, QTableWidgetItem(QString("%02s" % reading.getWeek())))
self.readingTable.setItem(row, 1, QTableWidgetItem(QString(reading.getCourse().getFull()))) self.readingTable.setItem(row, 1, QTableWidgetItem(QString(reading.getCourse().getFull())))
self.readingTable.setItem(row, 2, QTableWidgetItem(QString(reading.getBook().getTitle()))) self.readingTable.setItem(row, 2, QTableWidgetItem(QString(reading.getBook().getTitle())))
self.readingTable.setItem(row, 3, QTableWidgetItem(QString(reading.getChapter()))) self.readingTable.setItem(row, 3, QTableWidgetItem(QString(reading.getChapter())))
self.readingTable.setItem(row, 4, QTableWidgetItem(QString(reading.getPages()))) self.readingTable.setItem(row, 4, QTableWidgetItem(QString(reading.getPages())))
self.readingTable.setItem(row, 5, QTableWidgetItem(QString("%i" % reading.getNumberOfPages()))) self.readingTable.setItem(row, 5, QTableWidgetItem(QString("%i" % reading.getNumberOfPages())))
item = QTableWidgetItem(QString(doneString)) item = QTableWidgetItem(QString(doneString))
item.setBackground(brush) item.setBackground(brush)
self.readingTable.setItem(row, 6, item) self.readingTable.setItem(row, 6, item)
@ -875,14 +906,14 @@ class ReadingDlg(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super(ReadingDlg, self).__init__(parent) super(ReadingDlg, self).__init__(parent)
# Labels # Labels
self.weekLabel = QLabel(self.trUtf8("&Week")) self.weekLabel = QLabel(self.trUtf8("&Week"))
self.courseLabel = QLabel(self.trUtf8("&Course")) self.courseLabel = QLabel(self.trUtf8("&Course"))
self.bookLabel = QLabel(self.trUtf8("&Book")) self.bookLabel = QLabel(self.trUtf8("&Book"))
self.chapterLabel = QLabel(self.trUtf8("Cha&pter")) self.chapterLabel = QLabel(self.trUtf8("Cha&pter"))
self.pagesLabel = QLabel(self.trUtf8("&Pages")) self.pagesLabel = QLabel(self.trUtf8("&Pages"))
# Widgets # Widgets
self.weekEdit = QSpinBox() self.weekEdit = QSpinBox()
self.weekEdit.setRange(1, 52) self.weekEdit.setRange(1, 52)
self.courseEdit = QComboBox() self.courseEdit = QComboBox()
@ -896,19 +927,19 @@ class ReadingDlg(QDialog):
books = makeBooksString() books = makeBooksString()
for book in books: for book in books:
booksStringList.append(book) booksStringList.append(book)
self.bookEdit.addItems(booksStringList) self.bookEdit.addItems(booksStringList)
self.chapterEdit = QLineEdit() self.chapterEdit = QLineEdit()
self.pagesEdit = QLineEdit() self.pagesEdit = QLineEdit()
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies # Buddies
self.weekLabel.setBuddy(self.weekEdit) self.weekLabel.setBuddy(self.weekEdit)
self.courseLabel.setBuddy(self.courseEdit) self.courseLabel.setBuddy(self.courseEdit)
self.bookLabel.setBuddy(self.bookEdit) self.bookLabel.setBuddy(self.bookEdit)
self.chapterLabel.setBuddy(self.chapterEdit) self.chapterLabel.setBuddy(self.chapterEdit)
self.pagesLabel.setBuddy(self.pagesEdit) self.pagesLabel.setBuddy(self.pagesEdit)
# Layout # Layout
self.layout = QGridLayout() self.layout = QGridLayout()
self.layout.addWidget(self.weekLabel, 0, 0) self.layout.addWidget(self.weekLabel, 0, 0)
self.layout.addWidget(self.courseLabel, 1, 0) self.layout.addWidget(self.courseLabel, 1, 0)
@ -938,20 +969,20 @@ class ReadingDlg(QDialog):
chapter = unicode(self.chapterEdit.text()) chapter = unicode(self.chapterEdit.text())
pages = unicode(self.pagesEdit.text()) pages = unicode(self.pagesEdit.text())
self.close() self.close()
course = getCourseFromDB(getCourseCode(courseFull)) course = getCourseFromDB(getCourseCode(courseFull))
book = getBookWithTitleFromDB(bookTitle) book = getBookWithTitleFromDB(bookTitle)
global semester global semester
addNewReadingToDB(semester, week, course, book, chapter, pages, False) addNewReadingToDB(semester, week, course, book, chapter, pages, False)
reading = ReadingModel(week, course, book, chapter, pages, False) reading = ReadingModel(week, course, book, chapter, pages, False)
table = getMain().reading.readingTable table = getMain().reading.readingTable
row = table.rowCount() row = table.rowCount()
table.insertRow(row) table.insertRow(row)
getMain().reading.addReadingToTable(row, reading) getMain().reading.addReadingToTable(row, reading)
table.sortItems(0, Qt.AscendingOrder) table.sortItems(0, Qt.AscendingOrder)
### The reading model ### The reading model
@ -1020,11 +1051,11 @@ class ScheduleTab(QWidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super(ScheduleTab, self).__init__(parent) super(ScheduleTab, self).__init__(parent)
# Widgets # Widgets
self.addScheduleButton = QPushButton("Add lesson") self.addScheduleButton = QPushButton("Add lesson")
self.deleteScheduleButton = QPushButton("Delete lesson") self.deleteScheduleButton = QPushButton("Delete lesson")
# Make the table # Make the table
self.makeTable() self.makeTable()
# Layout # Layout
@ -1032,7 +1063,7 @@ class ScheduleTab(QWidget):
self.hlayout = QHBoxLayout() self.hlayout = QHBoxLayout()
self.hlayout.addWidget(self.addScheduleButton) self.hlayout.addWidget(self.addScheduleButton)
self.hlayout.addWidget(self.deleteScheduleButton) self.hlayout.addWidget(self.deleteScheduleButton)
self.hlayout.addStretch() self.hlayout.addStretch()
self.vlayout.addWidget(self.scheduleTable) self.vlayout.addWidget(self.scheduleTable)
self.vlayout.addLayout(self.hlayout) self.vlayout.addLayout(self.hlayout)
self.setLayout(self.vlayout) self.setLayout(self.vlayout)
@ -1072,21 +1103,21 @@ class ScheduleTab(QWidget):
def addLessonToTable(self, lesson): def addLessonToTable(self, lesson):
row = lesson.getTime() - 8 row = lesson.getTime() - 8
column = self.getColumn(lesson.getDay()) column = self.getColumn(lesson.getDay())
course = lesson.getCourse().getFull() course = lesson.getCourse().getFull()
type = lesson.getType() type = lesson.getType()
room = lesson.getRoom() room = lesson.getRoom()
olditem = self.scheduleTable.item(row, column) olditem = self.scheduleTable.item(row, column)
newtext = "%s\n%s\n%s" % (course, type, room) newtext = "%s\n%s\n%s" % (course, type, room)
if olditem: if olditem:
oldtext = olditem.text() oldtext = olditem.text()
text = QString(oldtext + "\n" + newtext) text = QString(oldtext + "\n" + newtext)
collision = True collision = True
else: else:
text = QString(newtext) text = QString(newtext)
collision = False collision = False
item = QTableWidgetItem(text) item = QTableWidgetItem(text)
item.setBackground(self.getBackground(QString("%s" % type), lesson.getCourse(), collision)) item.setBackground(self.getBackground(QString("%s" % type), lesson.getCourse(), collision))
self.scheduleTable.setItem(row, column, item) self.scheduleTable.setItem(row, column, item)
## Return the column specified by the day ## Return the column specified by the day
def getColumn(self, dayString): def getColumn(self, dayString):
@ -1134,7 +1165,7 @@ class ScheduleDlg(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super(ScheduleDlg, self).__init__(parent) super(ScheduleDlg, self).__init__(parent)
# Labels # Labels
self.dayLabel = QLabel(self.trUtf8("&Day")) self.dayLabel = QLabel(self.trUtf8("&Day"))
self.fromLabel = QLabel(self.trUtf8("&From")) self.fromLabel = QLabel(self.trUtf8("&From"))
self.toLabel = QLabel(self.trUtf8("&To")) self.toLabel = QLabel(self.trUtf8("&To"))
@ -1142,7 +1173,7 @@ class ScheduleDlg(QDialog):
self.typeLabel = QLabel(self.trUtf8("Ty&pe")) self.typeLabel = QLabel(self.trUtf8("Ty&pe"))
self.roomLabel = QLabel(self.trUtf8("&Room")) self.roomLabel = QLabel(self.trUtf8("&Room"))
# Widgets # Widgets
self.dayEdit = QComboBox() self.dayEdit = QComboBox()
self.dayEdit.addItems(getMain().days) self.dayEdit.addItems(getMain().days)
self.fromEdit = QSpinBox() self.fromEdit = QSpinBox()
@ -1153,17 +1184,17 @@ class ScheduleDlg(QDialog):
self.toEdit.setSingleStep(01.00) self.toEdit.setSingleStep(01.00)
self.courseEdit = QComboBox() self.courseEdit = QComboBox()
courses = makeCoursesString() courses = makeCoursesString()
coursesStringList = QStringList() coursesStringList = QStringList()
for course in courses: for course in courses:
coursesStringList.append(course) coursesStringList.append(course)
self.courseEdit.addItems(coursesStringList) self.courseEdit.addItems(coursesStringList)
self.typeEdit = QComboBox() self.typeEdit = QComboBox()
types = [self.trUtf8("Lecture"), self.trUtf8("Assignment lecture"), self.trUtf8("Assignment help"), self.trUtf8("Lab"), self.trUtf8("Seminar"), self.trUtf8("Other")] types = [self.trUtf8("Lecture"), self.trUtf8("Assignment lecture"), self.trUtf8("Assignment help"), self.trUtf8("Lab"), self.trUtf8("Seminar"), self.trUtf8("Other")]
self.typeEdit.addItems(types) self.typeEdit.addItems(types)
self.roomEdit = QLineEdit() self.roomEdit = QLineEdit()
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies # Buddies
self.dayLabel.setBuddy(self.dayEdit) self.dayLabel.setBuddy(self.dayEdit)
self.fromLabel.setBuddy(self.fromEdit) self.fromLabel.setBuddy(self.fromEdit)
self.toLabel.setBuddy(self.toEdit) self.toLabel.setBuddy(self.toEdit)
@ -1171,7 +1202,7 @@ class ScheduleDlg(QDialog):
self.typeLabel.setBuddy(self.typeEdit) self.typeLabel.setBuddy(self.typeEdit)
self.roomLabel.setBuddy(self.roomEdit) self.roomLabel.setBuddy(self.roomEdit)
# Layout # Layout
self.layout = QGridLayout() self.layout = QGridLayout()
self.layout.addWidget(self.dayLabel, 0, 0) self.layout.addWidget(self.dayLabel, 0, 0)
self.layout.addWidget(self.fromLabel, 1, 0) self.layout.addWidget(self.fromLabel, 1, 0)
@ -1192,17 +1223,17 @@ class ScheduleDlg(QDialog):
self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
# Set the title # Set the title
self.setWindowTitle(self.trUtf8("Add new lesson")) self.setWindowTitle(self.trUtf8("Add new lesson"))
## Accept the dialog and add the specified lesson ## Accept the dialog and add the specified lesson
def accept(self): def accept(self):
day = unicode(self.dayEdit.currentText()) day = unicode(self.dayEdit.currentText())
fromtime = self.fromEdit.value() fromtime = self.fromEdit.value()
totime = self.toEdit.value() totime = self.toEdit.value()
courseFull = unicode(self.courseEdit.currentText()) courseFull = unicode(self.courseEdit.currentText())
type = unicode(self.typeEdit.currentText()) type = unicode(self.typeEdit.currentText())
room = unicode(self.roomEdit.text()) room = unicode(self.roomEdit.text())
course = getCourseFromDB(getCourseCode(courseFull)) course = getCourseFromDB(getCourseCode(courseFull))
@ -1249,7 +1280,7 @@ class ScheduleModel():
## Return the room the lesson is in ## Return the room the lesson is in
def getRoom(self): def getRoom(self):
return self.room return self.room
### The Add Course dialog ### The Add Course dialog
@ -1259,7 +1290,7 @@ class CourseDlg(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super(CourseDlg, self).__init__(parent) super(CourseDlg, self).__init__(parent)
# The books # The books
self.books = [] self.books = []
# Labels # Labels
@ -1273,13 +1304,13 @@ class CourseDlg(QDialog):
self.titleEdit = QLineEdit() self.titleEdit = QLineEdit()
self.shortEdit = QLineEdit() self.shortEdit = QLineEdit()
self.booksEdit = QListWidget() self.booksEdit = QListWidget()
self.updateList() self.updateList()
self.booksEdit.setSelectionMode(QAbstractItemView.ExtendedSelection) self.booksEdit.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.newBook = QPushButton("Add new book") self.newBook = QPushButton("Add new book")
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies # Buddies
self.codeLabel.setBuddy(self.codeEdit) self.codeLabel.setBuddy(self.codeEdit)
self.titleLabel.setBuddy(self.titleEdit) self.titleLabel.setBuddy(self.titleEdit)
self.shortLabel.setBuddy(self.shortEdit) self.shortLabel.setBuddy(self.shortEdit)
self.booksLabel.setBuddy(self.booksEdit) self.booksLabel.setBuddy(self.booksEdit)
@ -1289,22 +1320,22 @@ class CourseDlg(QDialog):
self.layout.addWidget(self.codeLabel, 0, 0) self.layout.addWidget(self.codeLabel, 0, 0)
self.layout.addWidget(self.titleLabel, 1, 0) self.layout.addWidget(self.titleLabel, 1, 0)
self.layout.addWidget(self.shortLabel, 2, 0) self.layout.addWidget(self.shortLabel, 2, 0)
self.layout.addWidget(self.booksLabel, 3, 0) self.layout.addWidget(self.booksLabel, 3, 0)
self.layout.addWidget(self.codeEdit, 0, 1) self.layout.addWidget(self.codeEdit, 0, 1)
self.layout.addWidget(self.titleEdit, 1, 1) self.layout.addWidget(self.titleEdit, 1, 1)
self.layout.addWidget(self.shortEdit, 2, 1) self.layout.addWidget(self.shortEdit, 2, 1)
self.layout.addWidget(self.booksEdit, 3, 1) self.layout.addWidget(self.booksEdit, 3, 1)
self.layout.addWidget(self.newBook, 4, 0) self.layout.addWidget(self.newBook, 4, 0)
self.layout.addWidget(self.buttonBox, 4, 1, 1, 2) self.layout.addWidget(self.buttonBox, 4, 1, 1, 2)
self.setLayout(self.layout) self.setLayout(self.layout)
# Connect statements # Connect statements
self.connect(self.newBook, SIGNAL("pressed()"), getMain().addBook) self.connect(self.newBook, SIGNAL("pressed()"), getMain().addBook)
self.connect(getMain(), SIGNAL("newBook"), self.updateList) self.connect(getMain(), SIGNAL("newBook"), self.updateList)
self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
# Set the title # Set the title
self.setWindowTitle(self.trUtf8("Add new course")) self.setWindowTitle(self.trUtf8("Add new course"))
## Update the book list ## Update the book list
@ -1327,14 +1358,14 @@ class CourseDlg(QDialog):
courseCode = unicode(self.codeEdit.text()) courseCode = unicode(self.codeEdit.text())
courseTitle = unicode(self.titleEdit.text()) courseTitle = unicode(self.titleEdit.text())
courseShort = unicode(self.shortEdit.text()) courseShort = unicode(self.shortEdit.text())
courseBooks = self.booksEdit.selectedItems() courseBooks = self.booksEdit.selectedItems()
color = getRandomColor() color = getRandomColor()
global colors global colors
while color in colors: while color in colors:
color = getRandomColor() color = getRandomColor()
colors.append(color) colors.append(color)
books = [] books = []
for book in courseBooks: for book in courseBooks:
books.append(getBookWithTitleFromDB("%s" % book.text())) books.append(getBookWithTitleFromDB("%s" % book.text()))
course = CourseModel(courseCode, courseTitle, courseShort, color, books) course = CourseModel(courseCode, courseTitle, courseShort, color, books)
addNewCourseToDB(courseCode, courseTitle, courseShort, color, books) addNewCourseToDB(courseCode, courseTitle, courseShort, color, books)
@ -1399,13 +1430,13 @@ class BookDlg(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super(BookDlg, self).__init__(parent) super(BookDlg, self).__init__(parent)
# Labels # Labels
self.titleLabel = QLabel(self.trUtf8("&Title")) self.titleLabel = QLabel(self.trUtf8("&Title"))
self.authorLabel = QLabel(self.trUtf8("&Author")) self.authorLabel = QLabel(self.trUtf8("&Author"))
self.editionLabel = QLabel(self.trUtf8("&Edition")) self.editionLabel = QLabel(self.trUtf8("&Edition"))
self.isbnLabel = QLabel(self.trUtf8("&ISBN")) self.isbnLabel = QLabel(self.trUtf8("&ISBN"))
# Widgets # Widgets
self.titleEdit = QLineEdit() self.titleEdit = QLineEdit()
self.authorEdit = QLineEdit() self.authorEdit = QLineEdit()
self.editionEdit = QSpinBox() self.editionEdit = QSpinBox()
@ -1413,13 +1444,13 @@ class BookDlg(QDialog):
self.isbnEdit = QLineEdit() self.isbnEdit = QLineEdit()
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies # Buddies
self.titleLabel.setBuddy(self.titleEdit) self.titleLabel.setBuddy(self.titleEdit)
self.authorLabel.setBuddy(self.authorEdit) self.authorLabel.setBuddy(self.authorEdit)
self.editionLabel.setBuddy(self.editionEdit) self.editionLabel.setBuddy(self.editionEdit)
self.isbnLabel.setBuddy(self.isbnEdit) self.isbnLabel.setBuddy(self.isbnEdit)
# Layout # Layout
self.layout = QGridLayout() self.layout = QGridLayout()
self.layout.addWidget(self.titleLabel, 0, 0) self.layout.addWidget(self.titleLabel, 0, 0)
self.layout.addWidget(self.authorLabel, 1, 0) self.layout.addWidget(self.authorLabel, 1, 0)
@ -1436,7 +1467,7 @@ class BookDlg(QDialog):
self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
# Set the title # Set the title
self.setWindowTitle(self.trUtf8("Add new book")) self.setWindowTitle(self.trUtf8("Add new book"))
# Accept the dialog and add the specified book # Accept the dialog and add the specified book
@ -1460,10 +1491,10 @@ class BookModel():
## Initialize the book model ## Initialize the book model
def __init__(self, isbn, title, author, edition): def __init__(self, isbn, title, author, edition):
self.isbn = isbn self.isbn = isbn
self.title = title self.title = title
self.author = author self.author = author
self.edition = edition self.edition = edition
# Return the ISBN number of the book # Return the ISBN number of the book
def getIsbn(self): def getIsbn(self):
@ -1521,11 +1552,11 @@ def initAssignmentDB(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE Assignment ( CREATE TABLE Assignment (
date DATETIME, date DATETIME,
course TEXT, course TEXT,
number INT, number INT,
description TEXT, description TEXT,
complete TEXT, complete TEXT,
term TEXT, term TEXT,
year INT, year INT,
PRIMARY KEY (course, number) PRIMARY KEY (course, number)
) )
@ -1536,8 +1567,8 @@ def initReadingDB(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE Reading ( CREATE TABLE Reading (
week INT, week INT,
course TEXT, course TEXT,
book INT, book INT,
chapter TEXT, chapter TEXT,
pages TEXT, pages TEXT,
done BOOLEAN, done BOOLEAN,
@ -1553,7 +1584,7 @@ def initScheduleDB(cursor):
CREATE TABLE Lesson ( CREATE TABLE Lesson (
day TEXT, day TEXT,
time INT, time INT,
course TEXT, course TEXT,
type TEXT, type TEXT,
room TEXT, room TEXT,
term TEXT, term TEXT,
@ -1592,8 +1623,8 @@ def initCourseUsesBook(cursor):
CREATE TABLE CourseUsesBook ( CREATE TABLE CourseUsesBook (
courseCode TEXT, courseCode TEXT,
bookIsbn TEXT, bookIsbn TEXT,
PRIMARY KEY (courseCode, bookIsbn) PRIMARY KEY (courseCode, bookIsbn)
) )
''') ''')
# Add things to the database # Add things to the database
@ -1624,7 +1655,7 @@ def addNewAssignmentToDB(semester, datetime, course, number, description, comple
cursor.execute(''' cursor.execute('''
INSERT INTO Assignment (date, course, number, description, complete, term, year) INSERT INTO Assignment (date, course, number, description, complete, term, year)
VALUES (datetime(?), ?, ?, ?, ?, ?, ?) VALUES (datetime(?), ?, ?, ?, ?, ?, ?)
''', (timestring, course.getCode(), number, description, complete, term, year)) ''', (timestring, course.getCode(), number, description, complete, term, year))
exitDB(conn) exitDB(conn)
@ -1785,15 +1816,15 @@ def getCoursesFromDB():
courses = [] courses = []
for row in cursor.fetchall(): for row in cursor.fetchall():
courses.append(CourseModel(row[0], row[1], row[2], QColor(row[3], row[4], row[5]), [])) courses.append(CourseModel(row[0], row[1], row[2], QColor(row[3], row[4], row[5]), []))
for course in courses: for course in courses:
cursor.execute(''' cursor.execute('''
SELECT bookIsbn SELECT bookIsbn
FROM CourseUsesBook FROM CourseUsesBook
WHERE courseCode = ? WHERE courseCode = ?
''', (course.getCode(),)) ''', (course.getCode(),))
fetched = cursor.fetchall() fetched = cursor.fetchall()
for fetchedRow in fetched: for fetchedRow in fetched:
cursor.execute(''' cursor.execute('''
SELECT * SELECT *
@ -1850,7 +1881,7 @@ def getBooksFromDB():
books = [] books = []
for row in cursor.fetchall(): for row in cursor.fetchall():
books.append(BookModel(row[0], row[1], row[2], row[3])) books.append(BookModel(row[0], row[1], row[2], row[3]))
exitDB(conn) exitDB(conn)