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.

385
egon.py
View File

@ -18,7 +18,7 @@ from pysqlite2 import dbapi2 as sqlite
from qrc_resources import *
__version__ = "0.0.2"
__version__ = "0.9.0"
main = None
@ -66,7 +66,7 @@ class MainWindow(QMainWindow):
self.calendarDockWidget.setObjectName("CalendarDockWidget")
self.calendarDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea|Qt.RightDockWidgetArea|Qt.BottomDockWidgetArea)
self.calendar = QCalendarWidget()
self.calendar.setFirstDayOfWeek(Qt.Monday)
self.calendar.setFirstDayOfWeek(Qt.Monday)
self.calendarLayout = QVBoxLayout()
self.calendarLayout.addWidget(self.calendar)
self.calendarFrame.setLayout(self.calendarLayout)
@ -75,8 +75,8 @@ class MainWindow(QMainWindow):
# The semesters
global semester, semesters, termList
termList = QStringList()
termList.append(self.trUtf8("Spring"))
termList = QStringList()
termList.append(self.trUtf8("Spring"))
termList.append(self.trUtf8("Autumn"))
semesters = getSemestersFromDB()
semester = self.getLatestSemester(semesters)
@ -121,7 +121,6 @@ class MainWindow(QMainWindow):
self.connect(self.reading.readingDoneButton, SIGNAL("pressed()"), self.doneReading)
self.connect(self.schedule.addScheduleButton, SIGNAL("pressed()"), self.addLesson)
self.connect(self.schedule.deleteScheduleButton, SIGNAL("pressed()"), self.deleteLesson)
self.connect(self.calendar, SIGNAL("selectionChanged()"), self.changeDay)
# The toolbars
fileToolbar = self.addToolBar("File")
@ -134,23 +133,33 @@ class MainWindow(QMainWindow):
# Set the title
self.setMainWindowTitle()
# The courses
# The courses
courses = getCourses()
makeCoursesString()
# This window
global main
main = self
# 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
def getLatestSemester(self, semesters):
if len(semesters) == 0:
return None
global termList
max = semesters[0]
for s in semesters:
for s in semesters:
if s.getYear() > max.getYear():
max = s
if s.getYear() == max.getYear():
@ -183,10 +192,10 @@ class MainWindow(QMainWindow):
def completeAssignment(self, completionLevel):
course, number = self.getCourseAndNumber()
table, row = self.getAssignmentTableAndRow()
updateAssignmentCompletion(course, number, completionLevel)
updateAssignmentCompletion(course, number, completionLevel)
item = QTableWidgetItem(QString(completionLevel))
item.setBackground(self.assignment.makeBrush(completionLevel))
table.setItem(row, 4, item)
table.setItem(row, 4, item)
table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
## Return the assignment table and its current row
@ -202,7 +211,7 @@ class MainWindow(QMainWindow):
numberItem = table.item(row, 2)
courseFull = courseItem.text()
number = numberItem.text()
course = getCourseCode(courseFull)
course = getCourseCode(courseFull)
return course, number
# Reading
@ -235,11 +244,11 @@ class MainWindow(QMainWindow):
table.setItem(row, 6, item)
table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
week = (table.item(row, 0).text().toInt())[0]
courseFull = table.item(row, 1).text()
courseCode = QString(getCourseCode(courseFull))
courseFull = table.item(row, 1).text()
courseCode = QString(getCourseCode(courseFull))
bookTitle = table.item(row, 2).text()
book = getBookWithTitleFromDB(bookTitle)
bookIsbn = book.getIsbn()
book = getBookWithTitleFromDB(bookTitle)
bookIsbn = book.getIsbn()
updateReadingDone(week, courseCode, bookIsbn, True)
## Return the reading table and its current row
@ -327,24 +336,14 @@ class MainWindow(QMainWindow):
## Make and open the About dialog
def helpAbout(self):
QMessageBox.about(self, "About %s" % self.title, u"""
<b>%s</b> v %s
<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
<b>%s</b> v %s
<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>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>Developer: Tiril Anette Langfeldt Rødland, tirilane@pvv.ntnu.no
""" % (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()
<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()))
## Updates the File menu
def updateFileMenu(self):
self.fileMenu.clear()
@ -402,15 +401,15 @@ class NewSemesterDlg(QDialog):
self.termLabel = QLabel(self.trUtf8("Term"))
self.yearLabel = QLabel(self.trUtf8("Year"))
# Widgets
self.termEdit = QComboBox()
# Widgets
self.termEdit = QComboBox()
self.yearEdit = QSpinBox()
self.termEdit.addItems(getMain().getTermList())
self.yearEdit.setRange(2000, 2050)
self.yearEdit.setSingleStep(1)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Layout
# Layout
layout = QGridLayout()
layout.addWidget(self.termLabel, 0, 0)
layout.addWidget(self.termEdit, 0, 1)
@ -425,14 +424,14 @@ class NewSemesterDlg(QDialog):
# Set the title
self.setWindowTitle(self.trUtf8("New semester"))
## Accept the dialog and add the specified semester
def accept(self):
term = unicode(self.termEdit.currentText())
year = self.yearEdit.value()
global semester
semester = SemesterModel(term, year)
addNewSemesterToDB(term, year)
global semester
semester = SemesterModel(term, year)
addNewSemesterToDB(term, year)
getMain().load(semester)
getMain().setMainWindowTitle()
self.close()
@ -458,7 +457,7 @@ class OpenSemesterDlg(QDialog):
layout = QVBoxLayout()
layout.addWidget(self.semesterList)
layout.addStretch()
layout.addWidget(self.buttonBox)
layout.addWidget(self.buttonBox)
self.setLayout(layout)
# Connect statements
@ -467,7 +466,7 @@ class OpenSemesterDlg(QDialog):
# Set the title
self.setWindowTitle(self.trUtf8("Open semester"))
## Accept the dialog and open the specified semester
def accept(self):
text = self.semesterList.currentItem().text()
@ -552,13 +551,13 @@ class AssignmentTab(QWidget):
# Widgets
self.addAssignmentButton = QPushButton("Add assignment")
self.completeAssignmentBox = QComboBox()
self.completeAssignmentBox = QComboBox()
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")]
self.completeAssignmentBox.addItems(completeTypes)
# Make the table
self.makeTable()
self.makeTable()
# Layout
self.vlayout = QVBoxLayout()
@ -576,31 +575,31 @@ class AssignmentTab(QWidget):
self.assignmentTable = QTableWidget(0, 5, self)
self.assignmentTable.clear()
self.assignmentHeaderList = QStringList()
self.assignmentHeaderList.append(self.trUtf8("Date"))
self.assignmentHeaderList.append(self.trUtf8("Course"))
self.assignmentHeaderList.append(self.trUtf8("Number"))
self.assignmentHeaderList.append(self.trUtf8("Description"))
self.assignmentHeaderList.append(self.trUtf8("Complete"))
self.assignmentTable.setHorizontalHeaderLabels(self.assignmentHeaderList)
self.assignmentHeaderList = QStringList()
self.assignmentHeaderList.append(self.trUtf8("Date"))
self.assignmentHeaderList.append(self.trUtf8("Course"))
self.assignmentHeaderList.append(self.trUtf8("Number"))
self.assignmentHeaderList.append(self.trUtf8("Description"))
self.assignmentHeaderList.append(self.trUtf8("Complete"))
self.assignmentTable.setHorizontalHeaderLabels(self.assignmentHeaderList)
self.assignmentTable.setAlternatingRowColors(True)
self.assignmentTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.assignmentTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.assignmentTable.setSelectionMode(QAbstractItemView.SingleSelection)
selected = None
selected = None
## Add the assignments of the semester to the table
def updateTable(self, semester, current=None):
self.assignments = getAssignmentsFromDB(semester)
rows = len(self.assignments)
self.assignmentTable.setRowCount(rows)
for row in range(rows):
self.assignmentTable.setRowCount(rows)
for row in range(rows):
self.addAssignmentToTable(row)
self.assignmentTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
self.assignmentTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
self.assignmentTable.sortItems(0, Qt.AscendingOrder)
## Add new assignment to Table
@ -608,15 +607,15 @@ class AssignmentTab(QWidget):
if assignment == None:
assignment = self.assignments[row]
complete = QString(assignment.getComplete())
complete = QString(assignment.getComplete())
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, 2, QTableWidgetItem(QString("%i" % assignment.getNumber())))
self.assignmentTable.setItem(row, 3, QTableWidgetItem(QString("%s" % assignment.getDescription())))
completeItem = QTableWidgetItem(complete)
completeItem = QTableWidgetItem(complete)
completeItem.setBackground(brush)
self.assignmentTable.setItem(row, 4, completeItem)
@ -643,7 +642,7 @@ class AssignmentTab(QWidget):
brush.setColor(QColor(Qt.red))
else:
brush.setStyle(Qt.NoBrush)
return brush
return brush
### The Add Assignment dialog
@ -653,53 +652,53 @@ class AssignmentDlg(QDialog):
def __init__(self, parent=None):
super(AssignmentDlg, self).__init__(parent)
# Labels
# Labels
self.dateLabel = QLabel(self.trUtf8("&Date"))
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.completeLabel = QLabel(self.trUtf8("&Complete"))
# Widgets
self.dateEdit = QLineEdit("DD.MM.YYYY HH:MM")
self.dateEdit.setSelection(0, 16)
self.dateEdit = QLineEdit("DD.MM.YYYY HH:MM")
self.dateEdit.setSelection(0, 16)
self.courseEdit = QComboBox()
self.courseEdit.addItems(makeCoursesString())
self.numberEdit = QSpinBox()
self.numberEdit.setRange(1, 20)
self.courseEdit.addItems(makeCoursesString())
self.numberEdit = QSpinBox()
self.numberEdit.setRange(1, 20)
self.descriptionEdit = QLineEdit()
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")]
self.completeEdit.addItems(completeTypes)
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.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies
# Buddies
self.dateLabel.setBuddy(self.dateEdit)
self.courseLabel.setBuddy(self.courseEdit)
self.numberLabel.setBuddy(self.numberEdit)
self.numberLabel.setBuddy(self.numberEdit)
self.descriptionLabel.setBuddy(self.descriptionEdit)
self.completeLabel.setBuddy(self.completeEdit)
# Layout
# Layout
self.layout = QGridLayout()
self.layout.addWidget(self.dateLabel, 0, 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.completeLabel, 4, 0)
self.layout.addWidget(self.dateEdit, 0, 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.completeEdit, 4, 1)
self.layout.addWidget(self.buttonBox, 5, 0, 1, 2)
self.setLayout(self.layout)
# Connect statements
# Connect statements
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"))
## Return an array with the values of the widgets
@ -721,6 +720,13 @@ class AssignmentDlg(QDialog):
description = assignmentList[3]
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:
dateList = dateString.split('.')
timeList = ['00', '00']
@ -728,23 +734,48 @@ class AssignmentDlg(QDialog):
dateTime = dateString.split()
dateList = dateTime[0].split('.')
timeList = dateTime[1].split(':')
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)
print dateList, timeList
course = getCourseFromDB(getCourseCode(courseFull))
if dateList[1] > '13':
dateMessage = QErrorMessage()
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.")))
global semester
addNewAssignmentToDB(semester, datetime, course, number, description, complete)
course = getCourseFromDB(getCourseCode(courseFull))
assignment = AssignmentModel(datetime, course, number, description, complete)
table = getMain().assignment.assignmentTable
row = table.rowCount()
table.insertRow(row)
getMain().assignment.addAssignmentToTable(row, assignment)
table.sortItems(0, Qt.AscendingOrder)
try:
global semester
addNewAssignmentToDB(semester, datetime, course, number, description, complete)
assignment = AssignmentModel(datetime, course, number, description, complete)
except UnboundLocalError, e:
pass
table = getMain().assignment.assignmentTable
row = table.rowCount()
table.insertRow(row)
getMain().assignment.addAssignmentToTable(row, assignment)
table.sortItems(0, Qt.AscendingOrder)
self.close()
@ -798,7 +829,7 @@ class ReadingTab(QWidget):
self.deleteReadingButton = QPushButton(self.trUtf8("Delete pages"))
self.readingDoneButton = QPushButton(self.trUtf8("Done"))
# Make the table
# Make the table
self.makeTable()
# Layout
@ -816,15 +847,15 @@ class ReadingTab(QWidget):
def makeTable(self, current=None):
self.readingTable = QTableWidget(0, 7, self)
self.readingTable.clear()
self.readingHeaderList = QStringList()
self.readingHeaderList.append(self.trUtf8("Week"))
self.readingHeaderList.append(self.trUtf8("Course"))
self.readingHeaderList.append(self.trUtf8("Book"))
self.readingHeaderList.append(self.trUtf8("Chapter"))
self.readingHeaderList.append(self.trUtf8("Pages"))
self.readingHeaderList.append(self.trUtf8("Number of pages"))
self.readingHeaderList = QStringList()
self.readingHeaderList.append(self.trUtf8("Week"))
self.readingHeaderList.append(self.trUtf8("Course"))
self.readingHeaderList.append(self.trUtf8("Book"))
self.readingHeaderList.append(self.trUtf8("Chapter"))
self.readingHeaderList.append(self.trUtf8("Pages"))
self.readingHeaderList.append(self.trUtf8("Number of pages"))
self.readingHeaderList.append(self.trUtf8("Done"))
self.readingTable.setHorizontalHeaderLabels(self.readingHeaderList)
self.readingTable.setHorizontalHeaderLabels(self.readingHeaderList)
self.readingTable.setAlternatingRowColors(True)
self.readingTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.readingTable.setSelectionBehavior(QAbstractItemView.SelectRows)
@ -851,7 +882,7 @@ class ReadingTab(QWidget):
if reading.getDone():
doneString = self.trUtf8("Done")
brush.setColor(Qt.green)
brush.setColor(Qt.green)
else:
doneString = self.trUtf8("Not done")
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, 1, QTableWidgetItem(QString(reading.getCourse().getFull())))
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, 5, QTableWidgetItem(QString("%i" % reading.getNumberOfPages())))
self.readingTable.setItem(row, 5, QTableWidgetItem(QString("%i" % reading.getNumberOfPages())))
item = QTableWidgetItem(QString(doneString))
item.setBackground(brush)
item = QTableWidgetItem(QString(doneString))
item.setBackground(brush)
self.readingTable.setItem(row, 6, item)
@ -875,14 +906,14 @@ class ReadingDlg(QDialog):
def __init__(self, parent=None):
super(ReadingDlg, self).__init__(parent)
# Labels
# Labels
self.weekLabel = QLabel(self.trUtf8("&Week"))
self.courseLabel = QLabel(self.trUtf8("&Course"))
self.bookLabel = QLabel(self.trUtf8("&Book"))
self.chapterLabel = QLabel(self.trUtf8("Cha&pter"))
self.pagesLabel = QLabel(self.trUtf8("&Pages"))
# Widgets
# Widgets
self.weekEdit = QSpinBox()
self.weekEdit.setRange(1, 52)
self.courseEdit = QComboBox()
@ -896,19 +927,19 @@ class ReadingDlg(QDialog):
books = makeBooksString()
for book in books:
booksStringList.append(book)
self.bookEdit.addItems(booksStringList)
self.bookEdit.addItems(booksStringList)
self.chapterEdit = QLineEdit()
self.pagesEdit = QLineEdit()
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies
# Buddies
self.weekLabel.setBuddy(self.weekEdit)
self.courseLabel.setBuddy(self.courseEdit)
self.bookLabel.setBuddy(self.bookEdit)
self.chapterLabel.setBuddy(self.chapterEdit)
self.pagesLabel.setBuddy(self.pagesEdit)
# Layout
# Layout
self.layout = QGridLayout()
self.layout.addWidget(self.weekLabel, 0, 0)
self.layout.addWidget(self.courseLabel, 1, 0)
@ -938,20 +969,20 @@ class ReadingDlg(QDialog):
chapter = unicode(self.chapterEdit.text())
pages = unicode(self.pagesEdit.text())
self.close()
self.close()
course = getCourseFromDB(getCourseCode(courseFull))
book = getBookWithTitleFromDB(bookTitle)
book = getBookWithTitleFromDB(bookTitle)
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)
table = getMain().reading.readingTable
row = table.rowCount()
table.insertRow(row)
getMain().reading.addReadingToTable(row, reading)
table.sortItems(0, Qt.AscendingOrder)
table.insertRow(row)
getMain().reading.addReadingToTable(row, reading)
table.sortItems(0, Qt.AscendingOrder)
### The reading model
@ -1020,11 +1051,11 @@ class ScheduleTab(QWidget):
def __init__(self, parent=None):
super(ScheduleTab, self).__init__(parent)
# Widgets
# Widgets
self.addScheduleButton = QPushButton("Add lesson")
self.deleteScheduleButton = QPushButton("Delete lesson")
# Make the table
# Make the table
self.makeTable()
# Layout
@ -1032,7 +1063,7 @@ class ScheduleTab(QWidget):
self.hlayout = QHBoxLayout()
self.hlayout.addWidget(self.addScheduleButton)
self.hlayout.addWidget(self.deleteScheduleButton)
self.hlayout.addStretch()
self.hlayout.addStretch()
self.vlayout.addWidget(self.scheduleTable)
self.vlayout.addLayout(self.hlayout)
self.setLayout(self.vlayout)
@ -1058,7 +1089,7 @@ class ScheduleTab(QWidget):
self.scheduleTable.setSelectionBehavior(QAbstractItemView.SelectItems)
self.scheduleTable.setSelectionMode(QAbstractItemView.SingleSelection)
selected = None
## Add the lessons of the semester to the table
def updateTable(self, semester):
self.schedule = getLessonsFromDB(semester)
@ -1072,21 +1103,21 @@ class ScheduleTab(QWidget):
def addLessonToTable(self, lesson):
row = lesson.getTime() - 8
column = self.getColumn(lesson.getDay())
course = lesson.getCourse().getFull()
type = lesson.getType()
room = lesson.getRoom()
olditem = self.scheduleTable.item(row, column)
course = lesson.getCourse().getFull()
type = lesson.getType()
room = lesson.getRoom()
olditem = self.scheduleTable.item(row, column)
newtext = "%s\n%s\n%s" % (course, type, room)
if olditem:
oldtext = olditem.text()
text = QString(oldtext + "\n" + newtext)
collision = True
text = QString(oldtext + "\n" + newtext)
collision = True
else:
text = QString(newtext)
collision = False
collision = False
item = QTableWidgetItem(text)
item.setBackground(self.getBackground(QString("%s" % type), lesson.getCourse(), collision))
self.scheduleTable.setItem(row, column, item)
item.setBackground(self.getBackground(QString("%s" % type), lesson.getCourse(), collision))
self.scheduleTable.setItem(row, column, item)
## Return the column specified by the day
def getColumn(self, dayString):
@ -1134,7 +1165,7 @@ class ScheduleDlg(QDialog):
def __init__(self, parent=None):
super(ScheduleDlg, self).__init__(parent)
# Labels
# Labels
self.dayLabel = QLabel(self.trUtf8("&Day"))
self.fromLabel = QLabel(self.trUtf8("&From"))
self.toLabel = QLabel(self.trUtf8("&To"))
@ -1142,7 +1173,7 @@ class ScheduleDlg(QDialog):
self.typeLabel = QLabel(self.trUtf8("Ty&pe"))
self.roomLabel = QLabel(self.trUtf8("&Room"))
# Widgets
# Widgets
self.dayEdit = QComboBox()
self.dayEdit.addItems(getMain().days)
self.fromEdit = QSpinBox()
@ -1153,17 +1184,17 @@ class ScheduleDlg(QDialog):
self.toEdit.setSingleStep(01.00)
self.courseEdit = QComboBox()
courses = makeCoursesString()
coursesStringList = QStringList()
coursesStringList = QStringList()
for course in courses:
coursesStringList.append(course)
self.courseEdit.addItems(coursesStringList)
self.typeEdit = QComboBox()
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)
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.roomEdit = QLineEdit()
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies
# Buddies
self.dayLabel.setBuddy(self.dayEdit)
self.fromLabel.setBuddy(self.fromEdit)
self.toLabel.setBuddy(self.toEdit)
@ -1171,7 +1202,7 @@ class ScheduleDlg(QDialog):
self.typeLabel.setBuddy(self.typeEdit)
self.roomLabel.setBuddy(self.roomEdit)
# Layout
# Layout
self.layout = QGridLayout()
self.layout.addWidget(self.dayLabel, 0, 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("rejected()"), self, SLOT("reject()"))
# Set the title
# Set the title
self.setWindowTitle(self.trUtf8("Add new lesson"))
## Accept the dialog and add the specified lesson
def accept(self):
day = unicode(self.dayEdit.currentText())
fromtime = self.fromEdit.value()
totime = self.toEdit.value()
fromtime = self.fromEdit.value()
totime = self.toEdit.value()
courseFull = unicode(self.courseEdit.currentText())
type = unicode(self.typeEdit.currentText())
room = unicode(self.roomEdit.text())
room = unicode(self.roomEdit.text())
course = getCourseFromDB(getCourseCode(courseFull))
@ -1210,7 +1241,7 @@ class ScheduleDlg(QDialog):
for t in range(fromtime, totime):
addNewLessonToDB(semester, day, t, course, type, room)
getMain().schedule.addLessonToTable(ScheduleModel(day, t, course, type, room))
self.close()
@ -1249,7 +1280,7 @@ class ScheduleModel():
## Return the room the lesson is in
def getRoom(self):
return self.room
return self.room
### The Add Course dialog
@ -1259,7 +1290,7 @@ class CourseDlg(QDialog):
def __init__(self, parent=None):
super(CourseDlg, self).__init__(parent)
# The books
# The books
self.books = []
# Labels
@ -1273,13 +1304,13 @@ class CourseDlg(QDialog):
self.titleEdit = QLineEdit()
self.shortEdit = QLineEdit()
self.booksEdit = QListWidget()
self.updateList()
self.updateList()
self.booksEdit.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.newBook = QPushButton("Add new book")
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies
self.codeLabel.setBuddy(self.codeEdit)
self.codeLabel.setBuddy(self.codeEdit)
self.titleLabel.setBuddy(self.titleEdit)
self.shortLabel.setBuddy(self.shortEdit)
self.booksLabel.setBuddy(self.booksEdit)
@ -1289,22 +1320,22 @@ class CourseDlg(QDialog):
self.layout.addWidget(self.codeLabel, 0, 0)
self.layout.addWidget(self.titleLabel, 1, 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.titleEdit, 1, 1)
self.layout.addWidget(self.shortEdit, 2, 1)
self.layout.addWidget(self.booksEdit, 3, 1)
self.layout.addWidget(self.newBook, 4, 0)
self.layout.addWidget(self.booksEdit, 3, 1)
self.layout.addWidget(self.newBook, 4, 0)
self.layout.addWidget(self.buttonBox, 4, 1, 1, 2)
self.setLayout(self.layout)
# 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(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
# Set the title
# Set the title
self.setWindowTitle(self.trUtf8("Add new course"))
## Update the book list
@ -1327,14 +1358,14 @@ class CourseDlg(QDialog):
courseCode = unicode(self.codeEdit.text())
courseTitle = unicode(self.titleEdit.text())
courseShort = unicode(self.shortEdit.text())
courseBooks = self.booksEdit.selectedItems()
color = getRandomColor()
global colors
courseBooks = self.booksEdit.selectedItems()
color = getRandomColor()
global colors
while color in colors:
color = getRandomColor()
colors.append(color)
books = []
for book in courseBooks:
for book in courseBooks:
books.append(getBookWithTitleFromDB("%s" % book.text()))
course = CourseModel(courseCode, courseTitle, courseShort, color, books)
addNewCourseToDB(courseCode, courseTitle, courseShort, color, books)
@ -1343,7 +1374,7 @@ class CourseDlg(QDialog):
### The course model
class CourseModel():
code = ""
title = ""
short = ""
@ -1366,7 +1397,7 @@ class CourseModel():
## Return the title of the course
def getTitle(self):
return self.title
## Return the short form of the course
def getShort(self):
return self.short
@ -1399,13 +1430,13 @@ class BookDlg(QDialog):
def __init__(self, parent=None):
super(BookDlg, self).__init__(parent)
# Labels
# Labels
self.titleLabel = QLabel(self.trUtf8("&Title"))
self.authorLabel = QLabel(self.trUtf8("&Author"))
self.editionLabel = QLabel(self.trUtf8("&Edition"))
self.isbnLabel = QLabel(self.trUtf8("&ISBN"))
# Widgets
# Widgets
self.titleEdit = QLineEdit()
self.authorEdit = QLineEdit()
self.editionEdit = QSpinBox()
@ -1413,13 +1444,13 @@ class BookDlg(QDialog):
self.isbnEdit = QLineEdit()
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
# Buddies
# Buddies
self.titleLabel.setBuddy(self.titleEdit)
self.authorLabel.setBuddy(self.authorEdit)
self.editionLabel.setBuddy(self.editionEdit)
self.isbnLabel.setBuddy(self.isbnEdit)
# Layout
# Layout
self.layout = QGridLayout()
self.layout.addWidget(self.titleLabel, 0, 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("rejected()"), self, SLOT("reject()"))
# Set the title
# Set the title
self.setWindowTitle(self.trUtf8("Add new book"))
# Accept the dialog and add the specified book
@ -1460,10 +1491,10 @@ class BookModel():
## Initialize the book model
def __init__(self, isbn, title, author, edition):
self.isbn = isbn
self.isbn = isbn
self.title = title
self.author = author
self.edition = edition
self.author = author
self.edition = edition
# Return the ISBN number of the book
def getIsbn(self):
@ -1521,11 +1552,11 @@ def initAssignmentDB(cursor):
cursor.execute('''
CREATE TABLE Assignment (
date DATETIME,
course TEXT,
course TEXT,
number INT,
description TEXT,
complete TEXT,
term TEXT,
description TEXT,
complete TEXT,
term TEXT,
year INT,
PRIMARY KEY (course, number)
)
@ -1536,8 +1567,8 @@ def initReadingDB(cursor):
cursor.execute('''
CREATE TABLE Reading (
week INT,
course TEXT,
book INT,
course TEXT,
book INT,
chapter TEXT,
pages TEXT,
done BOOLEAN,
@ -1553,7 +1584,7 @@ def initScheduleDB(cursor):
CREATE TABLE Lesson (
day TEXT,
time INT,
course TEXT,
course TEXT,
type TEXT,
room TEXT,
term TEXT,
@ -1592,8 +1623,8 @@ def initCourseUsesBook(cursor):
CREATE TABLE CourseUsesBook (
courseCode TEXT,
bookIsbn TEXT,
PRIMARY KEY (courseCode, bookIsbn)
)
PRIMARY KEY (courseCode, bookIsbn)
)
''')
# Add things to the database
@ -1624,7 +1655,7 @@ def addNewAssignmentToDB(semester, datetime, course, number, description, comple
cursor.execute('''
INSERT INTO Assignment (date, course, number, description, complete, term, year)
VALUES (datetime(?), ?, ?, ?, ?, ?, ?)
VALUES (datetime(?), ?, ?, ?, ?, ?, ?)
''', (timestring, course.getCode(), number, description, complete, term, year))
exitDB(conn)
@ -1785,15 +1816,15 @@ def getCoursesFromDB():
courses = []
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:
cursor.execute('''
SELECT bookIsbn
FROM CourseUsesBook
WHERE courseCode = ?
WHERE courseCode = ?
''', (course.getCode(),))
fetched = cursor.fetchall()
fetched = cursor.fetchall()
for fetchedRow in fetched:
cursor.execute('''
SELECT *
@ -1850,7 +1881,7 @@ def getBooksFromDB():
books = []
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)