tirilane
/
egon
Archived
1
0
Fork 0

Must fix coursesUsesBooks et al.

This commit is contained in:
Tiril Anette Langfeldt Rødland 2008-06-14 17:48:48 +00:00
parent aed97f6601
commit 90cec9c695
2 changed files with 45 additions and 22 deletions

BIN
egon.db

Binary file not shown.

65
egon.py
View File

@ -11,6 +11,7 @@ import sys
import string import string
import datetime import datetime
import time import time
import random
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
#from PyQt4 import QtGui #from PyQt4 import QtGui
@ -29,7 +30,7 @@ coursesString = []
books = [] books = []
booksString = [] booksString = []
chosenDay = QDate() chosenDay = QDate()
colors = []
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
@ -887,14 +888,11 @@ class ScheduleTab(QWidget):
def getRows(self, fromtime, totime): def getRows(self, fromtime, totime):
rows = [] rows = []
fromTime = string.atoi(fromtime) for i in range(fromtime, totime):
toTime = string.atoi(totime) rows.append(i-8)
for i in range(fromTime, toTime):
rows.append(i)
return rows return rows
## Type skal bestemme brush, fag skal bestemme farge!!! Må skrive om course slik at farge velges ved adding
def getBackground(self, type, course): def getBackground(self, type, course):
if type.compare(QString(self.trUtf8("Lecture"))) == 0: if type.compare(QString(self.trUtf8("Lecture"))) == 0:
brush = QBrush(Qt.HorPattern) brush = QBrush(Qt.HorPattern)
@ -997,6 +995,7 @@ class AddScheduleDlg(ScheduleDlg):
course = getCourseFromDB(getCourseCode(courseFull)) course = getCourseFromDB(getCourseCode(courseFull))
addNewLessonToDB(day, fromTime, toTime, course, type, room) addNewLessonToDB(day, fromTime, toTime, course, type, room)
getMain().schedule.addLessonToTable(ScheduleModel(day, fromTime, toTime, course, type, room))
class EditScheduleDlg(ScheduleDlg): class EditScheduleDlg(ScheduleDlg):
@ -1020,8 +1019,8 @@ class EditScheduleDlg(ScheduleDlg):
class ScheduleModel(): class ScheduleModel():
day = "" day = ""
fromTime = "" fromTime = 0
toTime = "" toTime = 0
course = None course = None
type = "" type = ""
room = "" room = ""
@ -1137,9 +1136,16 @@ class AddCourseDlg(CourseDlg):
courseTitle = unicode(self.titleEdit.text()) courseTitle = unicode(self.titleEdit.text())
courseShort = unicode(self.shortEdit.text()) courseShort = unicode(self.shortEdit.text())
courseBooks = self.books courseBooks = self.books
course = CourseModel(courseCode, courseTitle, courseShort, courseBooks) color = getRandomColor()
global colors
while color in colors:
color = getRandomColor()
colors.append(color)
course = CourseModel(courseCode, courseTitle, courseShort, color, courseBooks)
self.close() self.close()
addNewCourseToDB(courseCode, courseTitle, courseShort, courseBooks) for book in courseBooks:
self.addNewBookCourse(book)
addNewCourseToDB(courseCode, courseTitle, courseShort, color, courseBooks)
def addNewBookCourse(self, book): def addNewBookCourse(self, book):
self.books.append(book) self.books.append(book)
@ -1154,11 +1160,12 @@ class CourseModel():
full = "" full = ""
books = [] books = []
def __init__(self, code, title, short, books): def __init__(self, code, title, short, color, books):
self.code = code self.code = code
self.title = title self.title = title
self.short = short self.short = short
self.setFull(code, title) self.setFull(code, title)
self.color = color
self.books = books self.books = books
def getCode(self): def getCode(self):
@ -1176,6 +1183,9 @@ class CourseModel():
def getFull(self): def getFull(self):
return self.full return self.full
def getColor(self):
return self.color
def addBook(self, book): def addBook(self, book):
books.append(book) books.append(book)
@ -1322,8 +1332,8 @@ def initScheduleDB(cursor):
cursor.execute(''' cursor.execute('''
CREATE TABLE Lesson ( CREATE TABLE Lesson (
day TEXT, day TEXT,
fromtime TEXT, fromtime INT,
totime TEXT, totime INT,
course TEXT, course TEXT,
type TEXT, type TEXT,
room TEXT, room TEXT,
@ -1346,7 +1356,10 @@ def initCourseDB(cursor):
CREATE TABLE Course ( CREATE TABLE Course (
code TEXT PRIMARY KEY, code TEXT PRIMARY KEY,
title TEXT, title TEXT,
short TEXT short TEXT,
red INT,
green INT,
blue INT
) )
''') ''')
@ -1398,13 +1411,17 @@ def addNewLessonToDB(day, fromtime, totime, course, type, room):
exitDB(conn) exitDB(conn)
def addNewCourseToDB(code, title, short, books): def addNewCourseToDB(code, title, short, color, books):
cursor, conn = initDB() cursor, conn = initDB()
red = color.red()
green = color.green()
blue = color.blue()
cursor.execute(''' cursor.execute('''
INSERT INTO Course (code, title, short) INSERT INTO Course (code, title, short, red, green, blue)
VALUES (?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
''', (code, title, short)) ''', (code, title, short, red, green, blue))
for book in books: for book in books:
cursor.execute(''' cursor.execute('''
@ -1500,7 +1517,7 @@ def getCoursesFromDB():
courses = [] courses = []
for row in cursor.fetchall(): for row in cursor.fetchall():
courses.append(CourseModel(row[0], row[1], row[2], [])) courses.append(CourseModel(row[0], row[1], row[2], QColor(row[3], row[4], row[5]), []))
for course in courses: for course in courses:
cursor.execute(''' cursor.execute('''
@ -1530,7 +1547,7 @@ def getCourseFromDB(courseCode):
''', (courseCode,)) ''', (courseCode,))
for row in cursor.fetchall(): for row in cursor.fetchall():
course = CourseModel(row[0], row[1], row[2], []) course = CourseModel(row[0], row[1], row[2], QColor(row[3], row[4], row[5]), [])
cursor.execute(''' cursor.execute('''
SELECT bookIsbn SELECT bookIsbn
@ -1674,7 +1691,7 @@ def getCourseCode(courseFull):
def addNewCourse(course): def addNewCourse(course):
courses.append(course) courses.append(course)
addNewCourseToDB(course.getCode(), course.getTitle(), course.getShort()) addNewCourseToDB(course.getCode(), course.getTitle(), course.getShort(), course.getColor())
addNewCourseString(course) addNewCourseString(course)
def getCourses(): def getCourses():
@ -1736,6 +1753,12 @@ def emptyBooks():
books = [] books = []
booksString = [] booksString = []
def getRandomColor():
return QColor(getRandomColorPart(), getRandomColorPart(), getRandomColorPart())
def getRandomColorPart():
return random.random()*256
def getMain(): def getMain():
global main global main
return main return main