From: Drew Fisher Date: Wed, 8 Jul 2009 06:46:10 +0000 (-0700) Subject: Keep EditPerson within the main window - it has no need to be a modal dialog. X-Git-Url: http://git.zarvox.org/shortlog/%7B%7B%20url_for%28%27main.login_page%27%29%20%7D%7D?a=commitdiff_plain;h=55912d76d2feb22092e56d7db5cd089cc2029238;p=wp3.git Keep EditPerson within the main window - it has no need to be a modal dialog. --- diff --git a/chooseaction.py b/chooseaction.py index b45d47c..4433855 100644 --- a/chooseaction.py +++ b/chooseaction.py @@ -29,9 +29,7 @@ class ChooseAction (QWidget): wiz.exec_() wiz = None def editPerson(self): - ep = EditPerson(self,self.db) - ep.exec_() - ep = None + self.emit(QtCore.SIGNAL("editPerson()")) def importPhotos(self): pass def exportDocument(self): diff --git a/editperson.py b/editperson.py index a54fd2c..9422a85 100644 --- a/editperson.py +++ b/editperson.py @@ -2,9 +2,9 @@ from PyQt4.QtCore import * 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) @@ -73,8 +73,8 @@ class EditPerson(QDialog): 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() @@ -238,7 +238,24 @@ class EditPerson(QDialog): 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())) @@ -251,7 +268,7 @@ class EditPerson(QDialog): 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 @@ -264,7 +281,7 @@ class EditPerson(QDialog): 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(): diff --git a/mainapp.py b/mainapp.py index 6a5674a..d7539f3 100644 --- a/mainapp.py +++ b/mainapp.py @@ -3,6 +3,7 @@ from PyQt4.QtGui import * 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);" @@ -16,7 +17,11 @@ class MainApp (QMainWindow): 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() @@ -36,6 +41,8 @@ class MainApp (QMainWindow): 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): @@ -71,7 +78,11 @@ class MainApp (QMainWindow): # 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__" :