]> git.zarvox.org Git - wp3.git/commitdiff
Add EditPerson UI. This may get refactored into the central widget/widget stack...
authorDrew Fisher <drew.m.fisher@gmail.com>
Sat, 4 Jul 2009 16:16:40 +0000 (11:16 -0500)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sat, 4 Jul 2009 16:16:40 +0000 (11:16 -0500)
chooseaction.py
editperson.py [new file with mode: 0644]
mainapp.py

index fed660040a29a6f9f6c0be4620949d7bc23c8d15..2009419f2bf6a436ad598a6fcc94db26d79e7cf6 100644 (file)
@@ -1,6 +1,7 @@
 from PyQt4 import QtCore
 from PyQt4.QtGui import *
 from newpersonwizard import NewPersonWizard
+from editperson import EditPerson
 
 class ChooseAction (QWidget):
        def __init__(self, parent=None):
@@ -17,7 +18,19 @@ class ChooseAction (QWidget):
                self.layout.addWidget(self.pb3,3,1,1,1)
                self.layout.addWidget(self.pb4,4,1,1,1)
                QtCore.QObject.connect(self.pb1, QtCore.SIGNAL("clicked()"), self.addPerson)
+               QtCore.QObject.connect(self.pb2, QtCore.SIGNAL("clicked()"), self.editPerson)
+               QtCore.QObject.connect(self.pb3, QtCore.SIGNAL("clicked()"), self.importPhotos)
+               QtCore.QObject.connect(self.pb4, QtCore.SIGNAL("clicked()"), self.exportDocument)
                self.setLayout(self.layout)
        def addPerson(self):
                wiz = NewPersonWizard()
                wiz.exec_()
+               wiz = None
+       def editPerson(self):
+               ep = EditPerson()
+               ep.exec_()
+               ep = None
+       def importPhotos(self):
+               pass
+       def exportDocument(self):
+               pass
diff --git a/editperson.py b/editperson.py
new file mode 100644 (file)
index 0000000..d2936aa
--- /dev/null
@@ -0,0 +1,189 @@
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
+class EditPerson(QDialog):
+       def __init__(self, parent=None):
+               QDialog.__init__(self,parent)
+               self.setWindowTitle("Edit records")
+               self.toplayout = QHBoxLayout() # Master layout
+               
+               self.leftpanel = QVBoxLayout() # Contains user search and select
+               self.search_label = QLabel("F&ilter:")
+               self.search_bar = QLineEdit()
+               self.search_label.setBuddy(self.search_bar)
+               self.searchpair = QHBoxLayout()
+               self.searchpair.addWidget(self.search_label)
+               self.searchpair.addWidget(self.search_bar)
+               self.persontable = QLabel("<center>Table of people goes here</center>")
+               self.leftpanel.addLayout(self.searchpair)
+               self.leftpanel.addWidget(self.persontable)
+               
+               self.rightpanel = QVBoxLayout() # Contains fields and buttons
+               self.setupForm()
+
+
+               self.rightpanel.addLayout(self.formlayout)
+               self.rightpanel.addLayout(self.buttonlayout)
+
+               self.toplayout.addLayout(self.leftpanel)
+               self.toplayout.addSpacing(10)
+               self.toplayout.addLayout(self.rightpanel)
+
+               self.setLayout(self.toplayout)
+               self.setupActions()
+               self.resize(800,600)
+               self.show()
+               
+
+       def setupForm(self):
+               # Text labels
+               self.netid_lab = QLabel("NetID:")
+               self.year_lab = QLabel("Year:")
+               self.month_lab = QLabel("Month:")
+               self.day_lab = QLabel("Day:")
+               self.firstname_lab = QLabel("Preferred name:")
+               self.surname_lab = QLabel("Last name:")
+               self.email_lab = QLabel("Email:")
+               self.phone_lab = QLabel("Phone:")
+               self.major_lab = QLabel("Major:")
+               self.hometown_lab = QLabel("Hometown:")
+               self.room_lab = QLabel("Room number:")
+               self.bday_lab = QLabel("Birthday:")
+               self.dorm_lab = QLabel("Dorm:")
+               self.photo = QLabel("<center>Photo goes here</center>")
+               self.photo.setScaledContents(True)
+               self.pb_changephoto = QPushButton("Select &photo")
+               # Personal info
+               self.surname = QLineEdit()
+               self.firstname = QLineEdit()
+               self.phone = QLineEdit()
+               self.email = QLineEdit()
+               self.major = QLineEdit()
+               self.netid = QLineEdit()
+               # Birthday
+               self.year = QComboBox()
+               self.month = QComboBox()
+               self.day = QComboBox()
+               # Residence locations
+               self.dorm = QComboBox()
+               self.room = QLineEdit()
+               # Fill the comboboxes with values, set valid field types
+               years = QStringList(["1987","1988","1989","1990","1991","1992","1993","1994"])
+               months = QStringList(["January","February","March","April","May","June","July","August","September","October","November","December"])
+               days = QStringList(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"])
+               dorms = QStringList(["Clements","Lechner","McFadden"])
+               self.year.addItems(years)
+               self.month.addItems(months)
+               self.day.addItems(days)
+               self.dorm.addItems(dorms)
+               self.phone.setInputMask("(999)-999-9999")
+               self.major.setMaxLength(4)
+               self.room.setMaxLength(3)
+               # Create and fill the UI
+               self.formlayout = QGridLayout()
+               self.bday_layout = QHBoxLayout()
+               self.bday_layout.addWidget(self.year)
+               self.bday_layout.addWidget(self.month)
+               self.bday_layout.addWidget(self.day)
+               self.formlayout.addWidget(self.netid_lab, 0, 0)
+               self.formlayout.addWidget(self.netid, 0, 1)
+               self.formlayout.addWidget(self.firstname_lab, 1, 0)
+               self.formlayout.addWidget(self.firstname, 1, 1)
+               self.formlayout.addWidget(self.surname_lab, 2, 0)
+               self.formlayout.addWidget(self.surname, 2, 1)
+               self.formlayout.addWidget(self.email_lab, 3, 0)
+               self.formlayout.addWidget(self.email, 3, 1)
+               self.formlayout.addWidget(self.phone_lab, 4, 0)
+               self.formlayout.addWidget(self.phone, 4, 1)
+               self.formlayout.addWidget(self.bday_lab,5,0)
+               self.formlayout.addLayout(self.bday_layout,5,1)
+               self.formlayout.addWidget(self.major_lab, 6, 0)
+               self.formlayout.addWidget(self.major, 6, 1)
+               self.formlayout.addWidget(self.dorm_lab, 7, 0)
+               self.formlayout.addWidget(self.dorm, 7, 1)
+               self.formlayout.addWidget(self.room_lab, 8, 0)
+               self.formlayout.addWidget(self.room, 8, 1)
+               self.formlayout.addWidget(self.photo,9,0,1,2)
+               self.formlayout.addWidget(self.pb_changephoto,10,0,1,2)
+               self.buttonlayout = QHBoxLayout()
+               self.pb_cancel = QPushButton("&Cancel")
+               self.pb_save = QPushButton("&Save")
+               self.pb_saveclose = QPushButton("Save && Clos&e")
+               self.pb_reset = QPushButton("&Reset")
+               self.pb_save.setEnabled(False)
+               self.pb_saveclose.setEnabled(False)
+               self.pb_reset.setEnabled(False)
+               self.buttonlayout.addWidget(self.pb_reset)
+               self.buttonlayout.addWidget(self.pb_cancel)
+               self.buttonlayout.addWidget(self.pb_save)
+               self.buttonlayout.addWidget(self.pb_saveclose)
+               self.pb_changephoto.setEnabled(False)
+       def setupActions(self):
+               # Update filtered table
+               QObject.connect(self.search_bar, SIGNAL("textChanged(QString)"), self.updateTable )
+               # Map buttons to actions
+               QObject.connect(self.pb_reset, SIGNAL("clicked()"), self.resetPressed )
+               QObject.connect(self.pb_cancel, SIGNAL("clicked()"), self.closePressed )
+               QObject.connect(self.pb_saveclose, SIGNAL("clicked()"), self.saveClosePressed )
+               QObject.connect(self.pb_save, SIGNAL("clicked()"), self.savePressed )
+               QObject.connect(self.pb_changephoto, SIGNAL("clicked()"), self.changePhoto )
+               # Changes to the record enable buttons
+               QObject.connect(self.netid, SIGNAL("textChanged(QString)"), self.formChanged )
+               QObject.connect(self.firstname, SIGNAL("textChanged(QString)"), self.formChanged )
+               QObject.connect(self.surname, SIGNAL("textChanged(QString)"), self.formChanged )
+               QObject.connect(self.email, SIGNAL("textChanged(QString)"), self.formChanged )
+               QObject.connect(self.phone, SIGNAL("textChanged(QString)"), self.formChanged )
+               QObject.connect(self.major, SIGNAL("textChanged(QString)"), self.formChanged )
+               QObject.connect(self.room, SIGNAL("textChanged(QString)"), self.formChanged )
+               QObject.connect(self.year, SIGNAL("currentIndexChanged(int)"), self.formChanged )
+               QObject.connect(self.month, SIGNAL("currentIndexChanged(int)"), self.formChanged )
+               QObject.connect(self.day, SIGNAL("currentIndexChanged(int)"), self.formChanged )
+               QObject.connect(self.dorm, SIGNAL("currentIndexChanged(int)"), self.formChanged )
+
+       def formChanged(self):
+               # Do this only if a record has been selected
+               self.pb_reset.setEnabled(True)
+               self.pb_save.setEnabled(True)
+               self.pb_saveclose.setEnabled(True)
+       def updateTable(self):
+               print "Text changed"
+       def resetPressed(self):
+               self.fillForm([])
+               self.pb_reset.setEnabled(False)
+               self.pb_save.setEnabled(False)
+               self.pb_saveclose.setEnabled(False)
+               print "Resetting form"
+       def closePressed(self):
+               print "Closing"
+               self.reject()
+       def savePressed(self):
+               print "Saving"
+               self.pb_reset.setEnabled(False)
+               self.pb_save.setEnabled(False)
+               self.pb_saveclose.setEnabled(False)
+       def saveClosePressed(self):
+               self.savePressed()
+               self.accept()
+       def changePhoto(self):
+               fileName = QFileDialog.getOpenFileName(self, "Select Photo", ".", "Images (*.jpg *.png)" )
+               if not fileName.isEmpty():
+                       print "opening", fileName
+                       self.currentimage = QImage()
+                       self.currentimage.load(fileName)
+                       self.displayimage = self.currentimage.scaled(self.photo.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
+                       self.displaypixmap = QPixmap.fromImage(self.displayimage)
+                       self.photo.setPixmap(self.displaypixmap)
+
+       def fillForm(self, args):
+               print "Filling form"
+
+       def recordSelected(self):
+               print "New record selected"
+               self.fillForm([])
+               self.pb_changephoto.setEnabled(True)
+
+
+if __name__ == "__main__":
+       a = QApplication([""])
+       w = EditPerson()
+       a.exec_()
index c28cadf9ca190ae1aa28ee1f7bab460a87cef040..328210b372d35c05aa4059154e8d869025d94d16 100644 (file)
@@ -9,7 +9,6 @@ class MainApp (QMainWindow):
                self.setWindowTitle("Whitepages V3")
 
                self.center = ChooseAction(self)
-               #self.center = QLabel("<center><h1>Filler</h1></center>")
                self.setCentralWidget(self.center)
 
                self.createActions()