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