tirilane
/
egon
Archived
1
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
egon/main.py

256 lines
9.9 KiB
Python
Executable File

#!/usr/bin/env python
#coding: utf-8
import os
import platform
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from pysqlite2 import dbapi2 as sqlite
#import qrc_resources
from qrc_resources import *
from assignment import *
from reading import *
from schedule import *
from calendar import *
from book import *
from course import *
#from db import *
import db
__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 tabs
assignment = AssignmentTab()
reading = ReadingTab()
schedule = ScheduleTab()
# Set the tabs in the middle
self.tabs = QTabWidget()
self.tabs.addTab(assignment, "&Assignments")
self.tabs.addTab(reading, "&Reading List")
self.tabs.addTab(schedule, "&Schedule")
self.tabs.setTabShape(QTabWidget.Triangular)
self.tabs.setTabPosition(QTabWidget.North)
self.setCentralWidget(self.tabs)
# Set the title
self.setWindowTitle(self.title)
# The calendar
self.calendarFrame = QFrame()
self.calendarFrame.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken)
self.calendarDockWidget = QDockWidget("Calendar", self)
self.calendarDockWidget.setVisible(False)
self.calendarDockWidget.setObjectName("CalendarDockWidget")
self.calendarDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea|Qt.RightDockWidgetArea|Qt.BottomDockWidgetArea)
self.calendar = QCalendarWidget()
self.calendarLayout = QVBoxLayout()
self.calendarLayout.addWidget(self.calendar)
self.calendarFrame.setLayout(self.calendarLayout)
self.calendarFrame.hide()
self.calendarDockWidget.setWidget(self.calendarFrame)
# Actions
fileNewAction = self.createAction("&New", self.fileNew, QKeySequence.New, ":filenew", "Create a new plan")
fileOpenAction = self.createAction("&Open", self.fileOpen, QKeySequence.Open, ":fileopen", "Open an existing plan")
fileSaveAction = self.createAction("&Save", self.fileSave, QKeySequence.Save, ":filesave", "Save semester plan")
fileSaveAsAction = self.createAction("Save as...", self.fileSaveAs, None, ":filesaveas", "Save plan as...")
filePrintAction = self.createAction("&Print", self.filePrint, QKeySequence.Print, ":fileprint", "Print plan")
fileQuitAction = self.createAction("&Quit", self.close, "Ctrl+Q", ":filequit", "Quit program")
editAddCourse = self.createAction("A&dd course", self.addCourse, "Ctrl+D", None, "Add a new course")
editAddBook = self.createAction("Add &book", self.addBook, "Ctrl+B", None, "Add a new book")
editAddAssignment = self.createAction("Add &assignment", self.addAssignment, "Ctrl+A", None, "Add a new assignment")
editAddReading = self.createAction("Add &reading", self.addReading, "Ctrl+R", None, "Add a new reading")
editAddLesson = self.createAction("Add &lesson", self.addLesson, "Ctrl+L", None, "Add a new lesson")
editShowCalendar = self.createAction("&Calendar", self.showCalendar, "Ctrl+C", None, "Show the calendar")
helpAboutScheduler = self.createAction("&About %s" % self.title)
# Menus
self.fileMenu = self.menuBar().addMenu("&File")
self.editMenu = self.menuBar().addMenu("&Edit")
self.helpMenu = self.menuBar().addMenu("&Help")
# Add actions to the menus
self.addActions(self.fileMenu, (fileNewAction, fileOpenAction, None, fileSaveAction, fileSaveAsAction, None, filePrintAction, None, fileQuitAction))
self.addActions(self.editMenu, (editAddCourse, editAddBook, None, editAddAssignment, None, editAddReading, None, editAddLesson, None, editShowCalendar))
self.addActions(self.helpMenu, (helpAboutScheduler, None))
# Connect statements
self.connect(editAddCourse, SIGNAL("triggered()"), self.addCourse)
self.connect(editAddBook, SIGNAL("triggered()"), self.addBook)
self.connect(editAddAssignment, SIGNAL("triggered()"), self.addAssignment)
self.connect(editAddReading, SIGNAL("triggered()"), self.addReading)
self.connect(editAddLesson, SIGNAL("triggered()"), self.addLesson)
self.connect(editShowCalendar, SIGNAL("pressed()"), self.showCalendar)
self.connect(helpAboutScheduler, SIGNAL("triggered()"), self.helpAbout)
self.connect(assignment.addAssignmentButton, SIGNAL("pressed()"), self.addAssignment)
self.connect(assignment.editAssignmentButton, SIGNAL("pressed()"), self.editAssignment)
self.connect(assignment.assignmentDoneButton, SIGNAL("pressed()"), self.doneAssignment)
self.connect(reading.addReadingButton, SIGNAL("pressed()"), self.addReading)
self.connect(reading.editReadingButton, SIGNAL("pressed()"), self.editReading)
self.connect(schedule.addScheduleButton, SIGNAL("pressed()"), self.addLesson)
self.connect(schedule.editScheduleButton, SIGNAL("pressed()"), self.editLesson)
# The toolbars
fileToolbar = self.addToolBar("File")
fileToolbar.setObjectName("FileToolBar")
self.addActions(fileToolbar, (fileNewAction, fileOpenAction, None, fileSaveAction, fileSaveAsAction, None, filePrintAction, None, fileQuitAction))
editToolbar = self.addToolBar("Edit")
editToolbar.setObjectName("EditToolBar")
self.addActions(editToolbar, (editAddCourse, editAddBook, None, editShowCalendar))
self.courses = db.getCourses()
self.makeCoursesString(self.courses)
def addCourse(self):##, code, title, short):
self.acdlg = AddCourseDlg()
self.acdlg.show()
def addBook(self):##, isbn, title, author, edition, course):
self.abdlg = AddBookDlg()
self.abdlg.show()
def addAssignment(self):
self.aadlg = AddAssignmentDlg()
self.aadlg.show()
def editAssignment(self):
self.eadlg = EditAssignmentDlg()
self.connect(self.eadlg, SIGNAL("changed()"), self.refreshTable)
self.eadlg.show()
def doneAssignment(self):
pass
def addReading(self):
self.ardlg = AddReadingDlg()
self.ardlg.show()
def editReading(self):
self.erdlg = EditReadingDlg()
self.connect(self.erdlg, SIGNAL("changed()"), self.refreshTable)
self.erdlg.show()
def doneReading(self):
pass
def addLesson(self):
self.asdlg = AddScheduleDlg()
self.asdlg.show()
def editLesson(self):
self.esdlg = EditScheduleDlg()
self.connect(self.esdlg, SIGNAL("changed()"), self.refreshTable)
self.esdlg.show()
def helpAbout(self):
QMessageBox.about(self, "About %s" % self.title, u"""<b>%s</b> v %s
<p>Copyright &copy; 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:
if action is None:
target.addSeparator()
else:
target.addAction(action)
def fileNew(self):
model = Model()
def fileOpen(self):
pass
def fileSave(self):
pass
def fileSaveAs(self):
pass
def filePrint(self):
pass
def updateFileMenu(self):
self.fileMenu.clear()
self.addActions(self.fileMenu, self.fileMenuActions[:-1])
current = QString(self.filename) if self.filename is not None else None
def createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"):
action = QAction(text, self)
if icon is not None:
iconfile = "/home/tiril/koding/schedule/images/%s.png" % icon
action.setIcon(QIcon(iconfile))
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if slot is not None:
self.connect(action, SIGNAL(signal), slot)
if checkable:
action.setCheckable(True)
return action
def showCalendar(self):
if self.calendarDockWidget.isVisible():
self.removeDockWidget(self.calendarDockWidget)
else:
self.addDockWidget(Qt.BottomDockWidgetArea, self.calendarDockWidget)
self.calendarDockWidget.setVisible(True)
def refreshTable(self):
pass
def addNewCourse(self, course):
self.courses.append(course)
db.addNewCourse(course.getCode(), course.getTitle(), course.getShort())
self.addNewCourseString(course)
def getCourses(self):
return self.courses
def addNewCourseString(self, course):
self.coursesString.append(course.getFull())
def makeCoursesString(self, courses):
if courses:
for c in courses:
addNewCourseString(course)
def getCoursesString(self):
return self.coursesString
class Model:
def __init__(self, parent=None):
self.assignmentModel = AssignmentModel()
self.readingModel = ReadingModel()
self.scheduleModel = ScheduleModel()
def main():
app = QApplication(sys.argv)
form = MainWindow()
app.setOrganizationName("PVV")
app.setOrganizationDomain("pvv.ntnu.no")
app.setApplicationName(form.title)
form.show()
app.exec_()
main()