Ommodulering
This commit is contained in:
parent
14fa195810
commit
ded36a2aa3
|
@ -62,7 +62,8 @@ class AssignmentDlg(QDialog):
|
|||
deliveredLabel = QLabel(self.trUtf8("De&livered"))
|
||||
|
||||
dateEdit = QLineEdit()
|
||||
courseEdit = QLineEdit()
|
||||
courseEdit = QComboBox()
|
||||
courseEdit.addItems(MainWindow.getCoursesString())
|
||||
descriptionEdit = QLineEdit()
|
||||
availableEdit = QCheckBox()
|
||||
begunEdit = QCheckBox()
|
||||
|
|
BIN
assignment.pyc
BIN
assignment.pyc
Binary file not shown.
43
course.py
43
course.py
|
@ -53,3 +53,46 @@ class AddCourseDlg(CourseDlg):
|
|||
|
||||
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
|
||||
|
|
BIN
course.pyc
BIN
course.pyc
Binary file not shown.
242
db.py
242
db.py
|
@ -16,137 +16,153 @@ from calendar import *
|
|||
from book import *
|
||||
from course import *
|
||||
|
||||
def initDB():
|
||||
conn = sqlite.connect('egon.db')
|
||||
curs = conn.cursor()
|
||||
return curs, conn
|
||||
class DB:
|
||||
|
||||
def initNewDB():
|
||||
cursor, conn = initDB()
|
||||
initAssignmentDB(cursor)
|
||||
initReadingDB(cursor)
|
||||
initScheduleDB(cursor)
|
||||
initBookDB(cursor)
|
||||
initCourseDB(cursor)
|
||||
exitDB(conn)
|
||||
def initDB():
|
||||
conn = sqlite.connect('egon.db')
|
||||
curs = conn.cursor()
|
||||
return curs, conn
|
||||
|
||||
def initAssignmentDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Assignment (
|
||||
aid INTEGER PRIMARY KEY,
|
||||
date TEXT,
|
||||
description TEXT,
|
||||
available BOOLEAN,
|
||||
begun BOOLEAN,
|
||||
finished BOOLEAN,
|
||||
delivered BOOLEAN
|
||||
)
|
||||
''')
|
||||
def initNewDB():
|
||||
cursor, conn = initDB()
|
||||
initAssignmentDB(cursor)
|
||||
initReadingDB(cursor)
|
||||
initScheduleDB(cursor)
|
||||
initBookDB(cursor)
|
||||
initCourseDB(cursor)
|
||||
exitDB(conn)
|
||||
|
||||
def initReadingDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Reading (
|
||||
rid INTEGER PRIMARY KEY,
|
||||
week TEXT,
|
||||
chapter TEXT,
|
||||
pages TEXT
|
||||
)
|
||||
''')
|
||||
def initAssignmentDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Assignment (
|
||||
aid INTEGER PRIMARY KEY,
|
||||
date TEXT,
|
||||
description TEXT,
|
||||
available BOOLEAN,
|
||||
begun BOOLEAN,
|
||||
finished BOOLEAN,
|
||||
delivered BOOLEAN
|
||||
)
|
||||
''')
|
||||
|
||||
def initScheduleDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Lesson (
|
||||
lid INTEGER PRIMARY KEY,
|
||||
day TEXT,
|
||||
fromtime TEXT,
|
||||
totime TEXT,
|
||||
type TEXT,
|
||||
room TEXT
|
||||
)
|
||||
''')
|
||||
def initReadingDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Reading (
|
||||
rid INTEGER PRIMARY KEY,
|
||||
week TEXT,
|
||||
chapter TEXT,
|
||||
pages TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
def initBookDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Book (
|
||||
isbn TEXT PRIMARY KEY,
|
||||
title TEXT,
|
||||
author TEXT,
|
||||
edition INTEGER
|
||||
)
|
||||
''')
|
||||
def initScheduleDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Lesson (
|
||||
lid INTEGER PRIMARY KEY,
|
||||
day TEXT,
|
||||
fromtime TEXT,
|
||||
totime TEXT,
|
||||
type TEXT,
|
||||
room TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
def initCourseDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Course (
|
||||
code TEXT PRIMARY KEY,
|
||||
title TEXT,
|
||||
short TEXT
|
||||
)
|
||||
''')
|
||||
def initBookDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Book (
|
||||
isbn TEXT PRIMARY KEY,
|
||||
title TEXT,
|
||||
author TEXT,
|
||||
edition INTEGER
|
||||
)
|
||||
''')
|
||||
|
||||
def initAssignmentInCourse(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE assignmentInCourse (
|
||||
assignment INTEGER,
|
||||
course INTEGER
|
||||
)
|
||||
''')
|
||||
def initCourseDB(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE Course (
|
||||
code TEXT PRIMARY KEY,
|
||||
title TEXT,
|
||||
short TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
def initReadingInCourse(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE readingInCourse (
|
||||
reading INTEGER,
|
||||
course INTEGER
|
||||
)
|
||||
''')
|
||||
def initAssignmentInCourse(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE assignmentInCourse (
|
||||
assignment INTEGER,
|
||||
course INTEGER
|
||||
)
|
||||
''')
|
||||
|
||||
def initLessonInCourse(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE lessonInCourse (
|
||||
lesson INTEGER,
|
||||
course INTEGER
|
||||
)
|
||||
''')
|
||||
def initReadingInCourse(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE readingInCourse (
|
||||
reading INTEGER,
|
||||
course INTEGER
|
||||
)
|
||||
''')
|
||||
|
||||
def initCourseUsesBook(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE courseUsesBook (
|
||||
course INTEGER,
|
||||
book TEXT
|
||||
)
|
||||
''')
|
||||
def initLessonInCourse(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE lessonInCourse (
|
||||
lesson INTEGER,
|
||||
course INTEGER
|
||||
)
|
||||
''')
|
||||
|
||||
def addNewBook(isbn, title, author, edition, course):
|
||||
cursor, conn = initDB()
|
||||
def initCourseUsesBook(cursor):
|
||||
cursor.execute('''
|
||||
CREATE TABLE courseUsesBook (
|
||||
course INTEGER,
|
||||
book TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
bookQuery = '''
|
||||
INSERT INTO Book
|
||||
VALUES (%s, %s, %s, %i)
|
||||
''' % (isbn, title, author, edition)
|
||||
courseUsesBookQuery = '''
|
||||
INSERT INTO courseUsesBook
|
||||
VALUES (%i, %s)
|
||||
''' % (course, isbn)
|
||||
def addNewBook(isbn, title, author, edition, course):
|
||||
cursor, conn = initDB()
|
||||
|
||||
cursor.execute(bookQuery)
|
||||
cursor.execute(courseUsesBookQuery)
|
||||
bookQuery = '''
|
||||
INSERT INTO Book
|
||||
VALUES (%s, %s, %s, %i)
|
||||
''' % (isbn, title, author, edition)
|
||||
courseUsesBookQuery = '''
|
||||
INSERT INTO courseUsesBook
|
||||
VALUES (%i, %s)
|
||||
''' % (course, isbn)
|
||||
|
||||
exitDB(conn)
|
||||
cursor.execute(bookQuery)
|
||||
cursor.execute(courseUsesBookQuery)
|
||||
|
||||
def addNewCourse(code, title, short):
|
||||
cursor, conn = initDB()
|
||||
exitDB(conn)
|
||||
|
||||
courseQuery = '''
|
||||
INSERT INTO Course
|
||||
VALUES (%s, %s, %s)
|
||||
''' % (code, title, short)
|
||||
def addNewCourse(code, title, short):
|
||||
cursor, conn = initDB()
|
||||
|
||||
cursor.execute(courseQuery)
|
||||
courseQuery = '''
|
||||
INSERT INTO Course
|
||||
VALUES (%s, %s, %s)
|
||||
''' % (code, title, short)
|
||||
|
||||
exitDB(conn)
|
||||
cursor.execute(courseQuery)
|
||||
|
||||
def exitDB(conn):
|
||||
conn.commit()
|
||||
conn.close()
|
||||
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.close()
|
||||
|
||||
initNewDB()
|
||||
|
|
37
main.py
37
main.py
|
@ -15,17 +15,26 @@ from schedule import *
|
|||
from calendar import *
|
||||
from book import *
|
||||
from course import *
|
||||
from db import *
|
||||
|
||||
__version__ = "0.0.1"
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
courses = []
|
||||
coursesString = []
|
||||
books = []
|
||||
booksString = []
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(MainWindow, self).__init__(parent)
|
||||
|
||||
# The program name
|
||||
self.title = "Egon"
|
||||
|
||||
# The database
|
||||
self.db = DB()
|
||||
|
||||
# The tabs
|
||||
assignment = AssignmentTab()
|
||||
reading = ReadingTab()
|
||||
|
@ -106,6 +115,9 @@ class MainWindow(QMainWindow):
|
|||
editToolbar.setObjectName("EditToolBar")
|
||||
self.addActions(editToolbar, (editAddCourse, editAddBook, None, editShowCalendar))
|
||||
|
||||
self.courses = self.db.getCourses()
|
||||
makeCoursesString()
|
||||
|
||||
def addCourse(self):##, code, title, short):
|
||||
self.acdlg = AddCourseDlg()
|
||||
self.acdlg.show()
|
||||
|
@ -149,9 +161,9 @@ class MainWindow(QMainWindow):
|
|||
|
||||
def helpAbout(self):
|
||||
QMessageBox.about(self, "About %s" % self.title, u"""<b>%s</b> v %s
|
||||
<p>Copyright © 2008 Tiril Anette Langfeldt Rødland. All rights reserved.
|
||||
<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""" % (self.title, __version__, platform.python_version(), QT_VERSION_STR, PYQT_VERSION_STR, platform.system()))
|
||||
<p>Copyright © 2008 Tiril Anette Langfeldt Rødland. All rights reserved.
|
||||
<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""" % (self.title, __version__, platform.python_version(), QT_VERSION_STR, PYQT_VERSION_STR, platform.system()))
|
||||
|
||||
def addActions(self, target, actions):
|
||||
for action in actions:
|
||||
|
@ -206,8 +218,25 @@ class MainWindow(QMainWindow):
|
|||
def refreshTable(self):
|
||||
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):
|
||||
self.assignmentModel = AssignmentModel()
|
||||
|
|
Reference in New Issue