tirilane
/
egon
Archived
1
0
Fork 0

It workses! Except the semesters. I'm getting there.

This commit is contained in:
Tiril Anette Langfeldt Rødland 2008-06-15 19:21:39 +00:00
parent 016cdcfd54
commit d50b7af349
2 changed files with 182 additions and 74 deletions

BIN
egon.db

Binary file not shown.

256
egon.py
View File

@ -40,6 +40,9 @@ class MainWindow(QMainWindow):
# The program name
self.title = "Egon"
# The days
self.days = [self.trUtf8("Monday"), self.trUtf8("Tuesday"), self.trUtf8("Wednesday"), self.trUtf8("Thursday"), self.trUtf8("Friday")]
# The tabs
self.assignment = AssignmentTab()
self.reading = ReadingTab()
@ -223,7 +226,30 @@ class MainWindow(QMainWindow):
self.asdlg.show()
def deleteLesson(self):
pass
table, row, column = self.getScheduleTableRowAndColumn()
day, course, time = self.getDayCourseAndTime()
removeLessonFromDB(day, course, time)
table.setItem(row, column, QTableWidgetItem())
def getDayCourseAndTime(self):
table, row, column = self.getScheduleTableRowAndColumn()
item = table.item(row, column)
text = item.text()
textlist = text.split('\n')
courseFull = textlist[0]
coursecode = getCourseCode(courseFull)
day = self.getDayFromTable(column)
time = row + 8
return day, coursecode, time
def getScheduleTableRowAndColumn(self):
table = self.schedule.scheduleTable
row = table.currentRow()
column = table.currentColumn()
return table, row, column
def getDayFromTable(self, column):
return self.days[column]
def helpAbout(self):
QMessageBox.about(self, "About %s" % self.title, u"""
@ -861,15 +887,14 @@ class ScheduleTab(QWidget):
self.scheduleTable.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
def addLessonToTable(self, lesson):
rows = self.getRows(lesson.getFromTime(), lesson.getToTime())
row = lesson.getTime() - 8
column = self.getColumn(lesson.getDay())
course = lesson.getCourse().getFull()
type = lesson.getType()
room = lesson.getRoom()
for row in rows:
item = QTableWidgetItem(QString("%s\n %s\n %s" % (course, type, room)))
item.setBackground(self.getBackground(QString("%s" % type), lesson.getCourse()))
self.scheduleTable.setItem(row, column, item)
item = QTableWidgetItem(QString("%s\n%s\n%s" % (course, type, room)))
item.setBackground(self.getBackground(QString("%s" % type), lesson.getCourse()))
self.scheduleTable.setItem(row, column, item)
def getColumn(self, dayString):
day = QString("%s" % dayString)
@ -886,13 +911,6 @@ class ScheduleTab(QWidget):
else:
return -1
def getRows(self, fromtime, totime):
rows = []
for i in range(fromtime, totime):
rows.append(i-8)
return rows
def getBackground(self, type, course):
if type.compare(QString(self.trUtf8("Lecture"))) == 0:
brush = QBrush(Qt.HorPattern)
@ -926,8 +944,7 @@ class ScheduleDlg(QDialog):
self.roomLabel = QLabel(self.trUtf8("&Room"))
self.dayEdit = QComboBox()
days = [self.trUtf8("Monday"), self.trUtf8("Tuesday"), self.trUtf8("Wednesday"), self.trUtf8("Thursday"), self.trUtf8("Friday")]
self.dayEdit.addItems(days)
self.dayEdit.addItems(getMain().days)
self.fromEdit = QSpinBox()
self.fromEdit.setRange(08.15, 18.15)
self.fromEdit.setSingleStep(01.00)
@ -984,18 +1001,19 @@ class AddScheduleDlg(ScheduleDlg):
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())
self.close()
course = getCourseFromDB(getCourseCode(courseFull))
addNewLessonToDB(day, fromTime, toTime, course, type, room)
getMain().schedule.addLessonToTable(ScheduleModel(day, fromTime, toTime, course, type, room))
for t in range(fromtime, totime):
addNewLessonToDB(SemesterModel("fall", 2008), day, t, course, type, room)
getMain().schedule.addLessonToTable(ScheduleModel(day, t, course, type, room))
self.close()
class EditScheduleDlg(ScheduleDlg):
@ -1019,16 +1037,14 @@ class EditScheduleDlg(ScheduleDlg):
class ScheduleModel():
day = ""
fromTime = 0
toTime = 0
time = 0
course = None
type = ""
room = ""
def __init__(self, day, fromTime, toTime, course, type, room):
def __init__(self, day, time, course, type, room):
self.day = day
self.fromTime = fromTime
self.toTime = toTime
self.time = time
self.course = course
self.type = type
self.room = room
@ -1039,17 +1055,11 @@ class ScheduleModel():
def setDay(self, day):
self.day = day
def getFromTime(self):
return self.fromTime
def getTime(self):
return self.time
def setFromTime(self, fromTime):
self.fromTime = fromTime
def getToTime(self):
return self.toTime
def setToTime(self, toTime):
self.toTime = toTime
def setTime(self, fromTime):
self.time = time
def getCourse(self):
return self.course
@ -1085,19 +1095,15 @@ class CourseDlg(QDialog):
self.codeEdit = QLineEdit()
self.titleEdit = QLineEdit()
self.shortEdit = QLineEdit()
self.bookList = QListWidget()
self.booksEdit = QPushButton(self.trUtf8("Add new book"))
self.bookMenu = QMenu()
booksDB = getBooksFromDB()
actions = []
for book in booksDB:
actions.append(QAction(QString(book.getTitle()), self.bookMenu))
for action in actions:
self.bookMenu.addAction(action)
self.connect(action, SIGNAL("triggered()"), self.addNewBookToCourse)
self.booksEdit.setMenu(self.bookMenu)
self.booksEdit = QListWidget()
self.updateList()
self.booksEdit.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.codeLabel.setBuddy(self.codeEdit)
self.newBook = QPushButton("Add new book")
self.connect(self.newBook, SIGNAL("pressed()"), getMain().addBook)
self.connect(getMain(), SIGNAL("newBook"), self.updateList)
self.codeLabel.setBuddy(self.codeEdit)
self.titleLabel.setBuddy(self.titleEdit)
self.shortLabel.setBuddy(self.shortEdit)
self.booksLabel.setBuddy(self.booksEdit)
@ -1110,10 +1116,19 @@ class CourseDlg(QDialog):
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.bookList, 3, 1)
self.layout.addWidget(self.booksEdit, 4, 1)
self.layout.addWidget(self.booksEdit, 3, 1)
self.layout.addWidget(self.newBook, 4, 0)
self.setLayout(self.layout)
def updateList(self):
self.booksEdit.clear()
booksDB = getBooksFromDB()
booksStringList = QStringList()
for book in booksDB:
booksStringList.append(book.getTitle())
self.booksEdit.addItems(booksStringList)
self.booksEdit.sortItems()
def addNewBookToCourse(self):
book = getBookWithTitleFromDB(booktitle)
self.books.append(book)
@ -1126,7 +1141,7 @@ class AddCourseDlg(CourseDlg):
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
self.layout.addWidget(buttonBox, 5, 0, 1, 2)
self.layout.addWidget(buttonBox, 4, 1, 1, 2)
self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
@ -1137,21 +1152,18 @@ class AddCourseDlg(CourseDlg):
courseCode = unicode(self.codeEdit.text())
courseTitle = unicode(self.titleEdit.text())
courseShort = unicode(self.shortEdit.text())
courseBooks = self.books
courseBooks = self.booksEdit.selectedItems()
color = getRandomColor()
global colors
while color in colors:
color = getRandomColor()
colors.append(color)
course = CourseModel(courseCode, courseTitle, courseShort, color, courseBooks)
books = []
for book in courseBooks:
books.append(getBookWithTitleFromDB("%s" % book.text()))
course = CourseModel(courseCode, courseTitle, courseShort, color, books)
addNewCourseToDB(courseCode, courseTitle, courseShort, color, books)
self.close()
for book in courseBooks:
self.addNewBookCourse(book)
addNewCourseToDB(courseCode, courseTitle, courseShort, color, courseBooks)
def addNewBookCourse(self, book):
self.books.append(book)
self.bookList.addItem(book.getTitle())
class CourseModel():
@ -1247,8 +1259,9 @@ class AddBookDlg(BookDlg):
bookAuthor = unicode(self.authorEdit.text())
bookEdition = self.editionEdit.value()
bookIsbn = unicode(self.isbnEdit.text())
self.close()
addNewBookToDB(bookIsbn, bookTitle, bookAuthor, bookEdition)
getMain().emit(SIGNAL("newBook"))
self.close()
class BookModel():
@ -1277,6 +1290,22 @@ class BookModel():
return self.edition
class SemesterModel():
term = ""
year = 0
def __init__(self, term, year):
self.term = term
self.year = year
def getTerm(self):
return self.term
def getYear(self):
return self.year
class CalendarTab(QWidget):
def __init__(self, parent=None):
@ -1297,14 +1326,27 @@ def initDB():
def initNewDB():
cursor, conn = initDB()
initSemesterDB(cursor)
initAssignmentDB(cursor)
initReadingDB(cursor)
initScheduleDB(cursor)
initBookDB(cursor)
initCourseDB(cursor)
initAssignmentInSemester(cursor)
initReadingInSemester(cursor)
initScheduleInSemester(cursor)
initCourseUsesBook(cursor)
exitDB(conn)
def initSemesterDB(cursor):
cursor.execute('''
CREATE TABLE Semester (
term TEXT,
year INT,
PRIMARY KEY (term, year)
)
''')
def initAssignmentDB(cursor):
cursor.execute('''
CREATE TABLE Assignment (
@ -1320,7 +1362,7 @@ def initAssignmentDB(cursor):
def initReadingDB(cursor):
cursor.execute('''
CREATE TABLE Reading (
week TEXT,
week INT,
course TEXT,
book INT,
chapter TEXT,
@ -1334,12 +1376,11 @@ def initScheduleDB(cursor):
cursor.execute('''
CREATE TABLE Lesson (
day TEXT,
fromtime INT,
totime INT,
time INT,
course TEXT,
type TEXT,
room TEXT,
PRIMARY KEY (course, day, fromtime)
PRIMARY KEY (course, day, time)
)
''')
@ -1365,6 +1406,41 @@ 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 (
@ -1374,7 +1450,7 @@ def initCourseUsesBook(cursor):
)
''')
def addNewAssignmentToDB(datetime, course, number, description, complete):
def addNewAssignmentToDB(semester, datetime, course, number, description, complete):
cursor, conn = initDB()
day = datetime.date().day()
@ -1389,11 +1465,14 @@ def addNewAssignmentToDB(datetime, 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()))
exitDB(conn)
return 'ok'
def addNewReadingToDB(week, course, book, chapter, pages, done):
def addNewReadingToDB(semester, week, course, book, chapter, pages, done):
cursor, conn = initDB()
cursor.execute('''
@ -1401,15 +1480,25 @@ def addNewReadingToDB(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()))
exitDB(conn)
def addNewLessonToDB(day, fromtime, totime, course, type, room):
def addNewLessonToDB(semester, day, time, course, type, room):
cursor, conn = initDB()
cursor.execute('''
INSERT INTO Lesson (day, fromtime, totime, course, type, room)
VALUES (?, ?, ?, ?, ?, ?)
''', (day, fromtime, totime, course.getCode(), type, room))
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()))
exitDB(conn)
@ -1503,7 +1592,7 @@ def getLessonsFromDB():
lessons = []
for row in cursor.fetchall():
lessons.append(ScheduleModel(row[0], row[1], row[2], getCourseFromDB(row[3]), row[4], row[5]))
lessons.append(ScheduleModel(row[0], row[1], getCourseFromDB(row[2]), row[3], row[4]))
exitDB(conn)
@ -1548,6 +1637,8 @@ def getCourseFromDB(courseCode):
WHERE code = ?
''', (courseCode,))
course = None
for row in cursor.fetchall():
course = CourseModel(row[0], row[1], row[2], QColor(row[3], row[4], row[5]), [])
@ -1683,6 +1774,23 @@ def removeReadingFromDB(week, coursecode, bookisbn):
exitDB(conn)
def removeLessonFromDB(daystring, coursecode, fromTime):
cursor, conn = initDB()
day = "%s" % daystring
course = "%s" % coursecode
time = "%s" % fromTime
cursor.execute('''
DELETE
FROM Lesson
WHERE day = ?
AND course = ?
AND time = ?
''', (day, course, time))
exitDB(conn)
def exitDB(conn):
conn.commit()
conn.close()