from PyQt4.QtGui import *
from PyQt4.QtSql import *
-class EditPerson(QDialog):
+class EditPerson(QWidget):
def __init__(self, parent=None, db=None):
- QDialog.__init__(self,parent)
+ QWidget.__init__(self,parent)
self.db = db
self.model = QSqlTableModel(self, self.db)
self.room_lab = QLabel("Room number:")
self.bday_lab = QLabel("Birthday:")
self.dorm_lab = QLabel("Dorm:")
- self.photo = QLabel("Photo goes here")
- self.photo.setScaledContents(True)
+ self.photo = QLabel("No record selected")
+ self.photo.setScaledContents(False)
self.currentimage = QImage()
self.displayimage = QImage()
self.displaypixmap = QPixmap()
def closePressed(self):
print "Closing"
self.model.revertAll()
- self.reject()
+ # Wipe contents of all lineedits, destroy current_record and current_index
+ self.search_bar.clear()
+ self.current_record = QSqlRecord()
+ self.current_index = -1
+ self.surname.clear()
+ self.firstname.clear()
+ self.phone.clear()
+ self.email.clear()
+ self.major.clear()
+ self.netid.clear()
+ self.year.setCurrentIndex(0)
+ self.month.setCurrentIndex(0)
+ self.day.setCurrentIndex(0)
+ self.dorm.setCurrentIndex(0)
+ self.room.clear()
+ self.photo.setText("No record selected")
+ self.model.select()
+ self.emit(SIGNAL("done()"))
def savePressed(self):
print "Saving"
self.current_record.setValue("netid",QVariant(self.netid.text()))
self.current_record.setValue("dorm",QVariant(self.dorm.currentText()))
y = self.year.currentText().toInt()[0]
m = self.month.currentIndex() + 1
- d = self.day.currentText().toInt()[0] + 1
+ d = self.day.currentText().toInt()[0]
bday = QDate(y,m,d)
self.current_record.setValue("birthday", QVariant(bday.toString(Qt.ISODate)) )
self.current_record.setValue("mtime", QVariant(QDateTime.currentDateTime().toString(Qt.ISODate)) ) # update modification time
self.pb_saveclose.setEnabled(False)
def saveClosePressed(self):
self.savePressed()
- self.accept()
+ self.closePressed()
def changePhoto(self):
fileName = QFileDialog.getOpenFileName(self, "Select Photo", ".", "Images (*.jpg *.png)" )
if not fileName.isEmpty():
from PyQt4.QtSql import *
from chooseaction import ChooseAction
+from editperson import EditPerson
class MainApp (QMainWindow):
schema = "CREATE TABLE people ( id INTEGER PRIMARY KEY AUTOINCREMENT, forename TEXT NOT NULL, surname TEXT NOT NULL, netid TEXT NOT NULL, email TEXT, birthday TEXT, phone TEXT, major TEXT, dorm TEXT, room INTEGER, photo BLOB, createtime TEXT NOT NULL, mtime TEXT NOT NULL);"
q = QSqlQuery(self.db)
q.exec_(MainApp.schema)
- self.center = ChooseAction(self,self.db)
+ self.center = QStackedWidget()
+ self.chooseaction = ChooseAction(self,self.db)
+ self.editperson = EditPerson(self,self.db)
+ self.center.addWidget(self.chooseaction)
+ self.center.addWidget(self.editperson)
self.setCentralWidget(self.center)
self.createActions()
QtCore.QObject.connect( self.fileImportAction, QtCore.SIGNAL("triggered()"), self.mergeWizard)
self.fileQuitAction = QAction("&Quit",self)
QtCore.QObject.connect( self.fileQuitAction, QtCore.SIGNAL("triggered()"), self.quit)
+ QtCore.QObject.connect( self.chooseaction, QtCore.SIGNAL("editPerson()"), self.editPersonSlot)
+ QtCore.QObject.connect( self.editperson, QtCore.SIGNAL("done()"), self.returnToMainMenu)
def createMenus(self):
# You could do cleanup, like closing/flushing the database, an "Are you sure you want to quit?"
# modal dialog, or saving the window layout/state.
qApp.quit()
-
+ def returnToMainMenu(self):
+ self.center.setCurrentWidget(self.chooseaction)
+ def editPersonSlot(self):
+ self.editperson.model.select() # update the table
+ self.center.setCurrentWidget(self.editperson)
if __name__ == "__main__" :