tirilane
/
egon
Archived
1
0
Fork 0

Egon is (almost) done. The printing function (not really important) is not implemented, and it needs documentation. But now it can actually be used.

This commit is contained in:
Tiril Anette Langfeldt Rødland 2008-06-17 13:39:39 +00:00
parent 3616dd3394
commit 6d5deaa787
2 changed files with 316 additions and 131 deletions

BIN
egon.db

Binary file not shown.

435
egon.py
View File

@ -25,12 +25,15 @@ __version__ = "0.0.2"
main = None
semesters = []
semester = None
courses = []
coursesString = []
books = []
booksString = []
chosenDay = QDate()
colors = []
termList = None
class MainWindow(QMainWindow):
@ -75,11 +78,20 @@ class MainWindow(QMainWindow):
self.calendarFrame.hide()
self.calendarDockWidget.setWidget(self.calendarFrame)
# The semesters
global semester, semesters, termList
termList = QStringList()
termList.append(self.trUtf8("Spring"))
termList.append(self.trUtf8("Autumn"))
semesters = getSemestersFromDB()
semester = self.getLatestSemester(semesters)
if semester:
print semester.getTerm(), semester.getYear()
self.load(semester)
# Actions
fileNewAction = self.createAction("&New", self.fileNew, QKeySequence.New, "filenew", "Create a new semester plan")
fileOpenAction = self.createAction("&Open", self.fileOpen, QKeySequence.Open, "fileopen", "Open an existing semester plan")
fileSaveAction = self.createAction("&Save", self.fileSave, QKeySequence.Save, "filesave", "Save semester plan")
fileSaveAsAction = self.createAction("Save as...", self.fileSaveAs, None, "filesaveas", "Save plan as...")
filePrintAction = self.createAction("&Print", self.filePrint, QKeySequence.Print, "fileprint", "Print plan")
fileQuitAction = self.createAction("&Quit", self.close, "Ctrl+Q", "filequit", "Quit program")
editAddCourse = self.createAction("Add &course", self.addCourse, "Ctrl+C", None, "Add a new course")
@ -96,7 +108,7 @@ class MainWindow(QMainWindow):
self.helpMenu = self.menuBar().addMenu("&Help")
# Add actions to the menus
self.addActions(self.fileMenu, (fileNewAction, fileOpenAction, None, fileSaveAction, fileSaveAsAction, None, filePrintAction, None, fileQuitAction))
self.addActions(self.fileMenu, (fileNewAction, fileOpenAction, None, filePrintAction, None, fileQuitAction))
self.addActions(self.editMenu, (editAddCourse, editAddBook, None, editAddAssignment, None, editAddReading, None, editAddLesson, None, editShowCalendar))
self.addActions(self.helpMenu, (helpAboutScheduler, None))
@ -121,7 +133,7 @@ class MainWindow(QMainWindow):
# The toolbars
fileToolbar = self.addToolBar("File")
fileToolbar.setObjectName("FileToolBar")
self.addActions(fileToolbar, (fileNewAction, fileOpenAction, None, fileSaveAction, fileSaveAsAction, None, filePrintAction, None, fileQuitAction))
self.addActions(fileToolbar, (fileNewAction, fileOpenAction, None, filePrintAction, None, fileQuitAction))
editToolbar = self.addToolBar("Edit")
editToolbar.setObjectName("EditToolBar")
self.addActions(editToolbar, (editAddCourse, editAddBook, None, editShowCalendar))
@ -147,6 +159,7 @@ class MainWindow(QMainWindow):
def deleteAssignment(self):
course, number = self.getCourseAndNumber()
table, row = self.getAssignmentTableAndRow()
global semester
removeAssignmentFromDB(course, number)
table.removeRow(row)
table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
@ -181,6 +194,7 @@ class MainWindow(QMainWindow):
def deleteReading(self):
week, course, book = self.getWeekCourseAndBook()
table, row = self.getReadingTableAndRow()
global semester
removeReadingFromDB(week, course, book)
table.removeRow(row)
table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
@ -228,6 +242,7 @@ class MainWindow(QMainWindow):
def deleteLesson(self):
table, row, column = self.getScheduleTableRowAndColumn()
day, course, time = self.getDayCourseAndTime()
global semester
removeLessonFromDB(day, course, time)
table.setItem(row, column, QTableWidgetItem())
@ -251,6 +266,23 @@ class MainWindow(QMainWindow):
def getDayFromTable(self, column):
return self.days[column]
def getLatestSemester(self, semesters):
if len(semesters) == 0:
return None
global termList
max = semesters[0]
for s in semesters:
if s.getYear() > max.getYear():
max = s
if s.getYear() == max.getYear():
if s.getTerm() == self.trUtf8("Autumn"):
max = s
return max
def getTermList(self):
global termList
return termList
def helpAbout(self):
QMessageBox.about(self, "About %s" % self.title, u"""
<b>%s</b> v %s
@ -273,16 +305,12 @@ class MainWindow(QMainWindow):
chosenDay = self.calendar
def fileNew(self):
pass
self.nsdlg = NewSemesterDlg()
self.nsdlg.show()
def fileOpen(self):
pass
def fileSave(self):
pass
def fileSaveAs(self):
pass
self.osdlg = OpenSemesterDlg()
self.osdlg.show()
def filePrint(self):
pass
@ -315,8 +343,10 @@ class MainWindow(QMainWindow):
self.addDockWidget(Qt.BottomDockWidgetArea, self.calendarDockWidget)
self.calendarDockWidget.setVisible(True)
def refreshTable(self):
pass
def load(self, semester):
self.assignment.updateTable(semester)
self.reading.updateTable(semester)
self.schedule.updateTable(semester)
class AssignmentTab(QWidget):
@ -332,22 +362,21 @@ class AssignmentTab(QWidget):
self.makeTable()
vlayout = QVBoxLayout()
hlayout = QHBoxLayout()
self.vlayout = QVBoxLayout()
self.hlayout = QHBoxLayout()
hlayout.addWidget(self.addAssignmentButton)
hlayout.addWidget(self.deleteAssignmentButton)
hlayout.addWidget(self.completeAssignmentBox)
hlayout.addStretch()
self.hlayout.addWidget(self.addAssignmentButton)
self.hlayout.addWidget(self.deleteAssignmentButton)
self.hlayout.addWidget(self.completeAssignmentBox)
self.hlayout.addStretch()
vlayout.addWidget(self.assignmentTable)
vlayout.addLayout(hlayout)
self.vlayout.addWidget(self.assignmentTable)
self.vlayout.addLayout(self.hlayout)
self.setLayout(vlayout)
self.setLayout(self.vlayout)
def makeTable(self, current=None):
self.assignments = getAssignmentsFromDB()
self.assignmentTable = QTableWidget(len(self.assignments), 5, self)
self.assignmentTable = QTableWidget(0, 5, self)
self.assignmentTable.clear()
self.assignmentHeaderList = QStringList()
self.assignmentHeaderList.append(self.trUtf8("Date"))
@ -361,10 +390,12 @@ class AssignmentTab(QWidget):
self.assignmentTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.assignmentTable.setSelectionMode(QAbstractItemView.SingleSelection)
selected = None
self.updateTable()
def updateTable(self, current=None):
for row in range(len(self.assignments)):
def updateTable(self, semester, current=None):
self.assignments = getAssignmentsFromDB(semester)
rows = len(self.assignments)
self.assignmentTable.setRowCount(rows)
for row in range(rows):
self.addAssignmentToTable(row)
self.assignmentTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
self.assignmentTable.sortItems(0, Qt.AscendingOrder)
@ -495,7 +526,8 @@ class AddAssignmentDlg(AssignmentDlg):
course = getCourseFromDB(getCourseCode(courseFull))
addNewAssignmentToDB(datetime, course, number, description, complete)
global semester
addNewAssignmentToDB(semester, datetime, course, number, description, complete)
assignment = AssignmentModel(datetime, course, number, description, complete)
table = getMain().assignment.assignmentTable
@ -593,22 +625,21 @@ class ReadingTab(QWidget):
self.makeTable()
vlayout = QVBoxLayout()
hlayout = QHBoxLayout()
self.vlayout = QVBoxLayout()
self.hlayout = QHBoxLayout()
hlayout.addWidget(self.addReadingButton)
hlayout.addWidget(self.deleteReadingButton)
hlayout.addWidget(self.readingDoneButton)
hlayout.addStretch()
self.hlayout.addWidget(self.addReadingButton)
self.hlayout.addWidget(self.deleteReadingButton)
self.hlayout.addWidget(self.readingDoneButton)
self.hlayout.addStretch()
vlayout.addWidget(self.readingTable)
vlayout.addLayout(hlayout)
self.vlayout.addWidget(self.readingTable)
self.vlayout.addLayout(self.hlayout)
self.setLayout(vlayout)
self.setLayout(self.vlayout)
def makeTable(self, current=None):
self.readings = getReadingsFromDB()
self.readingTable = QTableWidget(len(self.readings), 7, self)
self.readingTable = QTableWidget(0, 7, self)
self.readingTable.clear()
self.readingHeaderList = QStringList()
self.readingHeaderList.append(self.trUtf8("Week"))
@ -624,10 +655,12 @@ class ReadingTab(QWidget):
self.readingTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.readingTable.setSelectionMode(QAbstractItemView.SingleSelection)
selected = None
self.updateTable()
def updateTable(self):
for row in range(len(self.readings)):
def updateTable(self, semester):
self.readings = getReadingsFromDB(semester)
rows = len(self.readings)
self.readingTable.setRowCount(rows)
for row in range(rows):
self.addReadingToTable(row)
self.readingTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
self.readingTable.sortItems(0, Qt.AscendingOrder)
@ -731,7 +764,8 @@ class AddReadingDlg(ReadingDlg):
course = getCourseFromDB(getCourseCode(courseFull))
book = getBookWithTitleFromDB(bookTitle)
addNewReadingToDB(week, course, book, chapter, pages, False)
global semester
addNewReadingToDB(semester, week, course, book, chapter, pages, False)
reading = ReadingModel(week, course, book, chapter, pages, False)
table = getMain().reading.readingTable
@ -838,20 +872,19 @@ class ScheduleTab(QWidget):
self.makeTable()
vlayout = QVBoxLayout()
hlayout = QHBoxLayout()
self.vlayout = QVBoxLayout()
self.hlayout = QHBoxLayout()
hlayout.addWidget(self.addScheduleButton)
hlayout.addWidget(self.deleteScheduleButton)
hlayout.addStretch()
self.hlayout.addWidget(self.addScheduleButton)
self.hlayout.addWidget(self.deleteScheduleButton)
self.hlayout.addStretch()
vlayout.addWidget(self.scheduleTable)
vlayout.addLayout(hlayout)
self.vlayout.addWidget(self.scheduleTable)
self.vlayout.addLayout(self.hlayout)
self.setLayout(vlayout)
self.setLayout(self.vlayout)
def makeTable(self, current=None):
self.schedule = getLessonsFromDB()
self.scheduleTable = QTableWidget(12, 5, self)
self.scheduleTable.clear()
self.scheduleHorizontalHeaderList = QStringList()
@ -870,10 +903,12 @@ class ScheduleTab(QWidget):
self.scheduleTable.setSelectionBehavior(QAbstractItemView.SelectItems)
self.scheduleTable.setSelectionMode(QAbstractItemView.SingleSelection)
selected = None
self.updateTable()
def updateTable(self):
for l in range(len(self.schedule)):
def updateTable(self, semester):
self.schedule = getLessonsFromDB(semester)
rows = len(self.schedule)
self.scheduleTable.setRowCount(rows)
for l in range(rows):
self.addLessonToTable(self.schedule[l])
self.scheduleTable.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents)
self.scheduleTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
@ -1001,8 +1036,9 @@ class AddScheduleDlg(ScheduleDlg):
course = getCourseFromDB(getCourseCode(courseFull))
global semester
for t in range(fromtime, totime):
addNewLessonToDB(SemesterModel("fall", 2008), day, t, course, type, room)
addNewLessonToDB(semester, day, t, course, type, room)
getMain().schedule.addLessonToTable(ScheduleModel(day, t, course, type, room))
self.close()
@ -1282,10 +1318,136 @@ class BookModel():
return self.edition
class SemesterDlg(QDialog):
def __init__(self, parent=None):
super(SemesterDlg, self).__init__(parent)
self.oldLabel = QLabel(self.trUtf8("Earlier semesters:"))
self.newLabel = QLabel(self.trUtf8("New semester:"))
self.newTermLabel = QLabel(self.trUtf8("Term:"))
self.newYearLabel = QLabel(self.trUtf8("Year:"))
global semester, semesters, main
self.oldEdit = QListWidget()
self.oldEdit.addItems(semesters)
self.newTermEdit = QComboBox()
self.newTermEdit.addItems(getMain().getTermList())
self.newYearEdit = QSpinBox()
self.newYearEdit.setRange(2000, 2050)
self.newYearEdit.setSingleStep(1)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
layout = QGridLayout()
layout.addWidget(self.oldLabel, 0, 0)
layout.addWidget(self.oldEdit, 0, 1, 1, 2)
layout.addWidget(self.newLabel, 1, 0)
layout.addWidget(self.newTermLabel, 1, 1)
layout.addWidget(self.newTermEdit, 2, 1)
layout.addWidget(self.newYearLabel, 1, 2)
layout.addWidget(self.newYearEdit, 2, 2)
layout.addWidget(self.buttonBox, 3, 0, 1, 3)
layout.setColumnStretch(0, 0)
layout.setColumnStretch(1, 1)
layout.setColumnStretch(2, 1)
self.setLayout(layout)
self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
self.setWindowTitle(self.trUtf8("Choose a semester or create a new"))
def accept(self):
pass
class NewSemesterDlg(QDialog):
def __init__(self, parent=None):
super(NewSemesterDlg, self).__init__(parent)
self.termLabel = QLabel(self.trUtf8("Term"))
self.yearLabel = QLabel(self.trUtf8("Year"))
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 = QGridLayout()
layout.addWidget(self.termLabel, 0, 0)
layout.addWidget(self.termEdit, 0, 1)
layout.addWidget(self.yearLabel, 1, 0)
layout.addWidget(self.yearEdit, 1, 1)
layout.addWidget(self.buttonBox, 2, 1)
self.setLayout(layout)
self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
self.setWindowTitle(self.trUtf8("New semester"))
def accept(self):
term = unicode(self.termEdit.currentText())
year = self.yearEdit.value()
global semester
semester = SemesterModel(term, year)
addNewSemesterToDB(term, year)
getMain().load(semester)
self.close()
class OpenSemesterDlg(QDialog):
def __init__(self, parent=None):
super(OpenSemesterDlg, self).__init__(parent)
self.semesterList = QListWidget()
semesters = getSemestersFromDB()
semesterlist = QStringList()
for semester in semesters:
semesterlist.append("%s %i" % (semester.getTerm(), semester.getYear()))
self.semesterList.addItems(semesterlist)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
layout = QVBoxLayout()
layout.addWidget(self.semesterList)
layout.addStretch()
layout.addWidget(self.buttonBox)
self.setLayout(layout)
self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
self.setWindowTitle(self.trUtf8("Open semester"))
def accept(self):
text = self.semesterList.currentItem().text()
textlist = text.split(' ')
term = textlist[0]
year = textlist[1].toInt()[0]
global semester
semester = SemesterModel(term, year)
semester.setAssignments(getAssignmentsFromDB(semester))
semester.setReadings(getReadingsFromDB(semester))
semester.setLessons(getLessonsFromDB(semester))
print semester.getAssignments()
print semester.getReadings()
print semester.getLessons()
getMain().load(semester)
self.close()
class SemesterModel():
term = ""
year = 0
assignments = []
readings = []
lessons = []
def __init__(self, term, year):
self.term = term
@ -1297,6 +1459,33 @@ class SemesterModel():
def getYear(self):
return self.year
def addAssignment(self, assignment):
self.assignments.append(assignment)
def setAssignments(self, assignments):
self.assignments = assignments
def getAssignments(self):
return self.assignments
def addReading(self, reading):
self.readings.append(reading)
def setReadings(self, readings):
self.readings = readings
def getReadings(self):
return self.readings
def addLesson(self, lesson):
self.lessons.append(lesson)
def setLessons(self, lessons):
self.lessons = lessons
def getLessons(self):
return self.lessons
class CalendarTab(QWidget):
@ -1324,9 +1513,6 @@ def initNewDB():
initScheduleDB(cursor)
initBookDB(cursor)
initCourseDB(cursor)
initAssignmentInSemester(cursor)
initReadingInSemester(cursor)
initScheduleInSemester(cursor)
initCourseUsesBook(cursor)
exitDB(conn)
@ -1347,6 +1533,8 @@ def initAssignmentDB(cursor):
number INT,
description TEXT,
complete TEXT,
term TEXT,
year INT,
PRIMARY KEY (course, number)
)
''')
@ -1360,6 +1548,8 @@ def initReadingDB(cursor):
chapter TEXT,
pages TEXT,
done BOOLEAN,
term TEXT,
year INT,
PRIMARY KEY (week, course, book)
)
''')
@ -1372,6 +1562,8 @@ def initScheduleDB(cursor):
course TEXT,
type TEXT,
room TEXT,
term TEXT,
year INT,
PRIMARY KEY (course, day, time)
)
''')
@ -1398,41 +1590,6 @@ def initCourseDB(cursor):
)
''')
def initAssignmentInSemester(cursor):
cursor.execute('''
CREATE TABLE AssignmentInSemester (
course TEXT,
number INT,
term TEXT,
year INT,
PRIMARY KEY (course, number, term, year)
)
''')
def initReadingInSemester(cursor):
cursor.execute('''
CREATE TABLE ReadingInSemester (
week INT,
course TEXT,
book TEXT,
term TEXT,
year INT,
PRIMARY KEY (week, course, book, term, year)
)
''')
def initScheduleInSemester(cursor):
cursor.execute('''
CREATE TABLE ScheduleInSemester (
course TEXT,
day TEXT,
time INT,
term TEXT,
year INT,
PRIMARY KEY (course, day, time, term, year)
)
''')
def initCourseUsesBook(cursor):
cursor.execute('''
CREATE TABLE CourseUsesBook (
@ -1442,6 +1599,16 @@ def initCourseUsesBook(cursor):
)
''')
def addNewSemesterToDB(term, year):
cursor, conn = initDB()
cursor.execute('''
INSERT INTO Semester (term, year)
VALUES (?, ?)
''', (term, year))
exitDB(conn)
def addNewAssignmentToDB(semester, datetime, course, number, description, complete):
cursor, conn = initDB()
@ -1451,16 +1618,13 @@ def addNewAssignmentToDB(semester, datetime, course, number, description, comple
hour = datetime.time().hour()
minute = datetime.time().minute()
timestring = "%02i-%02i-%02i %02i:%02i" % (year, month, day, hour, minute)
term = "%s" % semester.getTerm()
year = semester.getYear()
cursor.execute('''
INSERT INTO Assignment (date, course, number, description, complete)
VALUES (datetime(?), ?, ?, ?, ?)
''', (timestring, course.getCode(), number, description, complete))
cursor.execute('''
INSERT INTO AssignmentInSemester (course, number, term, year)
VALUES (?, ?, ?, ?)
''', (course.getCode(), number, semester.getTerm(), semester.getYear()))
INSERT INTO Assignment (date, course, number, description, complete, term, year)
VALUES (datetime(?), ?, ?, ?, ?, ?, ?)
''', (timestring, course.getCode(), number, description, complete, term, year))
exitDB(conn)
@ -1468,14 +1632,9 @@ def addNewReadingToDB(semester, week, course, book, chapter, pages, done):
cursor, conn = initDB()
cursor.execute('''
INSERT INTO Reading (week, course, book, chapter, pages, done)
VALUES (?, ?, ?, ?, ?, ?)
''', (week, course.getCode(), book.getIsbn(), chapter, pages, done))
cursor.execute('''
INSERT INTO ReadingInSemester (week, course, book, term, year)
VALUES (?, ?, ?, ?, ?)
''', (week, course, book, semester.getTerm(), semester.getYear()))
INSERT INTO Reading (week, course, book, chapter, pages, done, term, year)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
''', (week, course.getCode(), book.getIsbn(), chapter, pages, done, semester.getTerm(), semester.getYear()))
exitDB(conn)
@ -1483,14 +1642,9 @@ def addNewLessonToDB(semester, day, time, course, type, room):
cursor, conn = initDB()
cursor.execute('''
INSERT INTO Lesson (day, time, course, type, room)
VALUES (?, ?, ?, ?, ?)
''', (day, time, course.getCode(), type, room))
cursor.execute('''
INSERT INTO ScheduleInSemester (course, day, time, term, year)
VALUES (?, ?, ?, ?, ?)
''', (course.getCode(), day, time, semester.getTerm(), semester.getYear()))
INSERT INTO Lesson (day, time, course, type, room, term, year)
VALUES (?, ?, ?, ?, ?, ?, ?)
''', (day, time, course.getCode(), type, room, semester.getTerm(), semester.getYear()))
exitDB(conn)
@ -1524,13 +1678,18 @@ def addNewBookToDB(isbn, title, author, edition):
exitDB(conn)
def getAssignmentsFromDB():
def getAssignmentsFromDB(semester):
cursor, conn = initDB()
term = "%s" % semester.getTerm()
year = (semester.getYear())
cursor.execute('''
SELECT *
FROM Assignment
''')
WHERE term = ?
AND year = ?
''', (term, year))
assignments = []
for row in cursor.fetchall():
@ -1558,13 +1717,18 @@ def getQDateTime(timestamp):
datetime = QDateTime(date, time)
return datetime
def getReadingsFromDB():
def getReadingsFromDB(semester):
cursor, conn = initDB()
term = "%s" % semester.getTerm()
year = semester.getYear()
cursor.execute('''
SELECT *
FROM Reading
''')
WHERE term = ?
AND year = ?
''', (term, year))
readings = []
for row in cursor.fetchall():
@ -1574,13 +1738,18 @@ def getReadingsFromDB():
return readings
def getLessonsFromDB():
def getLessonsFromDB(semester):
cursor, conn = initDB()
term = "%s" % semester.getTerm()
year = semester.getYear()
cursor.execute('''
SELECT *
FROM Lesson
''')
WHERE term = ?
AND year = ?
''', (term, year))
lessons = []
for row in cursor.fetchall():
@ -1703,6 +1872,22 @@ def getBookWithTitleFromDB(booktitle):
return book
def getSemestersFromDB():
cursor, conn = initDB()
cursor.execute('''
SELECT *
FROM Semester
''')
semesters = []
for row in cursor.fetchall():
semesters.append(SemesterModel(row[0], row[1]))
exitDB(conn)
return semesters
def updateAssignmentCompletion(coursecode, num, completion):
cursor, conn = initDB()