]> git.zarvox.org Git - wp3.git/commitdiff
Keep EditPerson within the main window - it has no need to be a modal dialog.
authorDrew Fisher <drew.m.fisher@gmail.com>
Wed, 8 Jul 2009 06:46:10 +0000 (23:46 -0700)
committerDrew Fisher <drew.m.fisher@gmail.com>
Wed, 8 Jul 2009 06:46:10 +0000 (23:46 -0700)
chooseaction.py
editperson.py
mainapp.py

index b45d47c37d3b66825b5a01f347c85dc9eee3ca5a..44338557850e1e39edb0b9da47c490d9ef63278b 100644 (file)
@@ -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):
index a54fd2c6e910e2957f3a6e2518abbb0c8302a315..9422a85de1da1f8439b9ed1a20b5f0ceaf230865 100644 (file)
@@ -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():
index 6a5674a904895cde84b78e4ec9e06ffbfdab1ee5..d7539f3c7df344f9b3f9190b65b210a933097610 100644 (file)
@@ -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__" :