from PyQt4.QtCore import *
from PyQt4.QtGui import *
+from PyQt4.QtSql import *
class EditPerson(QDialog):
def __init__(self, parent=None, db=None):
QDialog.__init__(self,parent)
self.db = db
+
+ self.model = QSqlTableModel(self, self.db)
+ self.model.setEditStrategy(QSqlTableModel.OnManualSubmit)
+ self.model.setTable("people")
+ self.model.select()
+ self.model.setHeaderData(self.model.fieldIndex("forename"), Qt.Horizontal, QVariant("First Name"))
+ self.model.setHeaderData(self.model.fieldIndex("surname"), Qt.Horizontal, QVariant("Last Name"))
+
+ self.tableview = QTableView(self)
+ self.tableview.setSelectionBehavior(QAbstractItemView.SelectRows)
+ self.tableview.setSelectionMode(QAbstractItemView.SingleSelection)
+ self.tableview.setEditTriggers(QAbstractItemView.NoEditTriggers)
+ self.tableview.setModel(self.model)
+
+ for i in xrange(self.model.columnCount()):
+ self.tableview.hideColumn(i)
+ self.tableview.showColumn(self.model.fieldIndex("forename"))
+ self.tableview.showColumn(self.model.fieldIndex("surname"))
+ self.tableview.resizeColumnsToContents()
+
self.setWindowTitle("Edit records")
self.toplayout = QHBoxLayout() # Master layout
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.leftpanel.addWidget(self.tableview)
self.rightpanel = QVBoxLayout() # Contains fields and buttons
self.setupForm()
self.pb_save.setEnabled(True)
self.pb_saveclose.setEnabled(True)
def updateTable(self):
+ self.model.select()
print "Text changed"
def resetPressed(self):
self.fillForm([])
from chooseaction import ChooseAction
class MainApp (QMainWindow):
- schema = "CREATE TABLE people ( id INTEGER PRIMARY KEY AUTOINCREMENT, netid TEXT NOT NULL, surname TEXT NOT NULL, forename 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);"
+ 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);"
def __init__(self, Parent=None):
QMainWindow.__init__(self, Parent)
self.setWindowTitle("Whitepages V3")