tirilane
/
egon
Archived
1
0
Fork 0

Ommodulering

This commit is contained in:
Tiril Anette Langfeldt Rødland 2008-06-05 11:30:13 +00:00
parent 14fa195810
commit ded36a2aa3
8 changed files with 214 additions and 125 deletions

View File

@ -62,7 +62,8 @@ class AssignmentDlg(QDialog):
deliveredLabel = QLabel(self.trUtf8("De&livered")) deliveredLabel = QLabel(self.trUtf8("De&livered"))
dateEdit = QLineEdit() dateEdit = QLineEdit()
courseEdit = QLineEdit() courseEdit = QComboBox()
courseEdit.addItems(MainWindow.getCoursesString())
descriptionEdit = QLineEdit() descriptionEdit = QLineEdit()
availableEdit = QCheckBox() availableEdit = QCheckBox()
begunEdit = QCheckBox() begunEdit = QCheckBox()

Binary file not shown.

View File

@ -53,3 +53,46 @@ class AddCourseDlg(CourseDlg):
self.setWindowTitle(self.trUtf8("Add new course")) self.setWindowTitle(self.trUtf8("Add new course"))
def accept(self):
courseCode = unicode(self.codeEdit.text())
courseTitle = unicode(self.titleEdit.text())
courseShort = unicode(self.shortEdit.text())
course = CourseModel(courseCode, courseTitle, courseShort)
class CourseModel():
code = ""
title = ""
short = ""
full = ""
def __init__(self, code, title, short):
self.code = code
self.title = title
self.short = short
setFull(code, title)
def setCode(self, code):
self.code = code
def getCode(self):
return self.code
def setTitle(self, title):
self.title = title
def getTitle(self):
return self.title
def setShort(self, short):
self.short = short
def getShort(self):
return self.short
def setFull(self, code, title):
self.full = code + ' ' + title
def getFull(self):
return self.full

Binary file not shown.

44
db.py
View File

@ -16,12 +16,14 @@ from calendar import *
from book import * from book import *
from course import * from course import *
def initDB(): class DB:
def initDB():
conn = sqlite.connect('egon.db') conn = sqlite.connect('egon.db')
curs = conn.cursor() curs = conn.cursor()
return curs, conn return curs, conn
def initNewDB(): def initNewDB():
cursor, conn = initDB() cursor, conn = initDB()
initAssignmentDB(cursor) initAssignmentDB(cursor)
initReadingDB(cursor) initReadingDB(cursor)
@ -30,7 +32,7 @@ def initNewDB():
initCourseDB(cursor) initCourseDB(cursor)
exitDB(conn) exitDB(conn)
def initAssignmentDB(cursor): def initAssignmentDB(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE Assignment ( CREATE TABLE Assignment (
aid INTEGER PRIMARY KEY, aid INTEGER PRIMARY KEY,
@ -43,7 +45,7 @@ def initAssignmentDB(cursor):
) )
''') ''')
def initReadingDB(cursor): def initReadingDB(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE Reading ( CREATE TABLE Reading (
rid INTEGER PRIMARY KEY, rid INTEGER PRIMARY KEY,
@ -53,7 +55,7 @@ def initReadingDB(cursor):
) )
''') ''')
def initScheduleDB(cursor): def initScheduleDB(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE Lesson ( CREATE TABLE Lesson (
lid INTEGER PRIMARY KEY, lid INTEGER PRIMARY KEY,
@ -65,7 +67,7 @@ def initScheduleDB(cursor):
) )
''') ''')
def initBookDB(cursor): def initBookDB(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE Book ( CREATE TABLE Book (
isbn TEXT PRIMARY KEY, isbn TEXT PRIMARY KEY,
@ -75,7 +77,7 @@ def initBookDB(cursor):
) )
''') ''')
def initCourseDB(cursor): def initCourseDB(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE Course ( CREATE TABLE Course (
code TEXT PRIMARY KEY, code TEXT PRIMARY KEY,
@ -84,7 +86,7 @@ def initCourseDB(cursor):
) )
''') ''')
def initAssignmentInCourse(cursor): def initAssignmentInCourse(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE assignmentInCourse ( CREATE TABLE assignmentInCourse (
assignment INTEGER, assignment INTEGER,
@ -92,7 +94,7 @@ def initAssignmentInCourse(cursor):
) )
''') ''')
def initReadingInCourse(cursor): def initReadingInCourse(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE readingInCourse ( CREATE TABLE readingInCourse (
reading INTEGER, reading INTEGER,
@ -100,7 +102,7 @@ def initReadingInCourse(cursor):
) )
''') ''')
def initLessonInCourse(cursor): def initLessonInCourse(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE lessonInCourse ( CREATE TABLE lessonInCourse (
lesson INTEGER, lesson INTEGER,
@ -108,7 +110,7 @@ def initLessonInCourse(cursor):
) )
''') ''')
def initCourseUsesBook(cursor): def initCourseUsesBook(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE courseUsesBook ( CREATE TABLE courseUsesBook (
course INTEGER, course INTEGER,
@ -116,7 +118,7 @@ def initCourseUsesBook(cursor):
) )
''') ''')
def addNewBook(isbn, title, author, edition, course): def addNewBook(isbn, title, author, edition, course):
cursor, conn = initDB() cursor, conn = initDB()
bookQuery = ''' bookQuery = '''
@ -133,7 +135,7 @@ def addNewBook(isbn, title, author, edition, course):
exitDB(conn) exitDB(conn)
def addNewCourse(code, title, short): def addNewCourse(code, title, short):
cursor, conn = initDB() cursor, conn = initDB()
courseQuery = ''' courseQuery = '''
@ -145,7 +147,21 @@ def addNewCourse(code, title, short):
exitDB(conn) exitDB(conn)
def exitDB(conn): def getCourses():
cursor, conn = initDB()
courseQuery = '''
SELECT *
FROM Course
'''
cursor.execute(courseQuery)
courses = []
for row in cursor.fetchall():
courses.append(CourseModel(row[0], row[1], row[2]))
def exitDB(conn):
conn.commit() conn.commit()
conn.close() conn.close()

BIN
db.pyc

Binary file not shown.

31
main.py
View File

@ -15,17 +15,26 @@ from schedule import *
from calendar import * from calendar import *
from book import * from book import *
from course import * from course import *
from db import *
__version__ = "0.0.1" __version__ = "0.0.1"
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
courses = []
coursesString = []
books = []
booksString = []
def __init__(self, parent=None): def __init__(self, parent=None):
super(MainWindow, self).__init__(parent) super(MainWindow, self).__init__(parent)
# The program name # The program name
self.title = "Egon" self.title = "Egon"
# The database
self.db = DB()
# The tabs # The tabs
assignment = AssignmentTab() assignment = AssignmentTab()
reading = ReadingTab() reading = ReadingTab()
@ -106,6 +115,9 @@ class MainWindow(QMainWindow):
editToolbar.setObjectName("EditToolBar") editToolbar.setObjectName("EditToolBar")
self.addActions(editToolbar, (editAddCourse, editAddBook, None, editShowCalendar)) self.addActions(editToolbar, (editAddCourse, editAddBook, None, editShowCalendar))
self.courses = self.db.getCourses()
makeCoursesString()
def addCourse(self):##, code, title, short): def addCourse(self):##, code, title, short):
self.acdlg = AddCourseDlg() self.acdlg = AddCourseDlg()
self.acdlg.show() self.acdlg.show()
@ -206,8 +218,25 @@ class MainWindow(QMainWindow):
def refreshTable(self): def refreshTable(self):
pass pass
def addNewCourse(self, course):
self.courses.append(course)
db.addNewCourse(course.getCode(), course.getTitle(), course.getShort())
self.addNewCourseString(course)
class Model(): def getCourses(self):
return self.courses
def addNewCourseString(self, course):
self.coursesString.append(course.getFull())
def makeCoursesString(self, courses):
for c in courses:
addNewCourseString(course)
def getCoursesString(self):
return self.coursesString
class Model:
def __init__(self, parent=None): def __init__(self, parent=None):
self.assignmentModel = AssignmentModel() self.assignmentModel = AssignmentModel()

BIN
main.pyc

Binary file not shown.