From d50b7af349df6d16e3e260f7877bc9942d8c4122 Mon Sep 17 00:00:00 2001 From: tirilane Date: Sun, 15 Jun 2008 19:21:39 +0000 Subject: [PATCH] It workses! Except the semesters. I'm getting there. --- egon.db | Bin 15360 -> 24576 bytes egon.py | 256 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 182 insertions(+), 74 deletions(-) diff --git a/egon.db b/egon.db index 0394b6f55847abd7b8d425dead935afeefe210f8..00000dca068ff482b0efb2f639db6aa94b3855ec 100644 GIT binary patch literal 24576 zcmeI3&u<$=6vuaV>|NW5^P{f2wXD!h0ku|LMQ#(2=%Kj5R8f<*xT#8okhQkQsZ-k< zytbeMgq-{XoH%gj!~w*CTaTznhyxO;kdU|`;Lsv2RV5@~W`B5hcGuyD1QOY|an|ei zc4y~(-n+JziTYA5%4b-zjOh8C@UR4D_I7)xLTZ+Cw9)tJTV-6n1sY%3- znBy@1)j9~C1r{Ix1pYGuQ)zmul+5gAHl>!$UuM+fb}1S0T75T z0a*W|n|p{H2*COeV*m(5mjJB)(ak+X4g}KpyddGEfWOC|<9G28KZTRl53m6O5h9RF zN;#Ct&%fAjH?=#nEnQzHjlr-_&aC7TUe}D*g+COYaj#1ITzS_u?RDki-Ug>QSIp~5 zd0jLa3$(%68>HDI2JNKhcFTEDI>tFYH(bsktI-X;M=wjbjh2>Ec#qbeXCV}q>$317HWonrB7^WrPB~x*qA;mtx zKWtv&P7XK|&m7}z)8hC-dn!Qe?|)f1BhbfZ!XtEFoDzS-r}u*~nnSX(uz*I!K&yAi zHPR)R8p2Db=&l^SkP1<>k#HXTC$UzPfhVXT4fo+bCCW zs+TG^)syVXqRLJzj4v%LiITFqfP{9hN!~DC>rh2gO&bn$^L5SXL#^Z-;nAyDRu&i0 zUfhhKY#8mWUYGO+?oo`3!?pV&X=+qG^#Toeb8VwiOeI;64Sm=*NJxCWVYg1~2+cE_ z#Ax)}JA<~~vro4h=?euCVHTn_ENX%bo| zhN1VYeS+g-*?f5D(i;-Xp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26bO4;n1}pD&^1PTx;DvOJ z{F-f>{ul9vl}BuZ69*E$D9QItWqn)cYXVq7@CDw&3N6(#Ot;V`k0&s}ex+$OO~ckr zqYG_mX9zD#35-eDXNFxgOSSu^2wHB(d{XprN7^j}TgD(-9SYic55X_^275HwJ4g#4 Ug?XSJxzrr~S;s5{u diff --git a/egon.py b/egon.py index e61725c..f622d6f 100755 --- a/egon.py +++ b/egon.py @@ -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,18 +1055,12 @@ 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 setTime(self, fromTime): + self.time = time - def getToTime(self): - return self.toTime - - def setToTime(self, toTime): - self.toTime = toTime - 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()