At the moment a QStandardItemModel is being used to support QTableView, but a future need to process large CSV files with > 50,000 rows + facilitates the need for an alternative method.

I have read several great PyQt based articles on the subject (see below) of using a QAbstractTableModel to hold the data which will then provide QtableView with items 'on demand', yet novice programing skills are making the transition anything but progressive.

http://www.saltycrane.com/blog/2007/...delqtableview/
http://sateeshkumarb.wordpress.com/2...-data-in-pyqt/
https://gist.githubusercontent.com/M...09/combobox.py

Below are the primary bits of code (currently without QAbstractTableModel implemented) called by another piece of software, in all their existing error glory.

Qt Code:
  1. import csv
  2. import sys
  3. from PyQt4 import QtGui, QtCore
  4. from PyQt4.QtCore import Qt, QVariant
  5. global xLoc
  6. global yLoc
  7. global itemIdxs
  8.  
  9. class CSVeditor(QtGui.QDialog, QtGui.QWidget):
  10. def __init__(self, fileName, horizHeaders, vertHeaders, parent=None):
  11. super(CSVeditor, self).__init__(parent)
  12.  
  13. self.horizHeaders = horizHeaders
  14. self.fileName = fileName
  15. self.model = QtGui.QStandardItemModel(self)
  16. self.model.setHorizontalHeaderLabels(horizHeaders)
  17.  
  18. self.tableView = QtGui.QTableView(self)
  19. self.tableView.setModel(self.model)
  20. self.tableView.horizontalHeader().setStretchLastSection(False)
  21. self.tableView.setAlternatingRowColors(True)
  22. self.tableView.hideColumn(0)
  23. self.tableView.hideColumn(1)
  24. self.tableView.hideColumn(2)
  25. self.tableView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
  26. selectionModel = self.tableView.selectionModel()
  27. selectionModel.selectionChanged.connect(self.selRange)
  28. shortcut = QtGui.QShortcut(self)
  29. shortcut.setKey("Enter")
  30. self.connect(shortcut, QtCore.SIGNAL("activated()"), self.shareChanges)
  31. self.tableView.clicked.connect(self.Release)
  32.  
  33. # autoLoad CSV from workspace [to be edited for dropdown CSV upload selection(s)]
  34. with open(fileName, "rb") as fileInput:
  35. for idx, row in enumerate(csv.reader(fileInput)):
  36. header = 0
  37. if idx is header:
  38. pass
  39. elif idx>0:
  40. items = [QtGui.QStandardItem(field) for field in row]
  41. self.model.appendRow(items)
  42. self.model.setVerticalHeaderLabels(vertHeaders)
  43. self.show()
  44.  
  45. # index of selected range, and parent item (last index) for batch application of user-value changes
  46. def selRange(self,selected,deselected):
  47. selectedIdx = self.tableView.selectedIndexes()
  48. idxCol = []
  49. idxRow = []
  50. for row in selectedIdx:
  51. idxRow.append(row.row())
  52. for column in selectedIdx:
  53. idxCol.append(column.column())
  54. global itemIdxs
  55. itemIdxs = zip(idxRow,idxCol)
  56.  
  57. def shareChanges(self):
  58. self.tableView.clicked.connect(self.Release)
  59. try:
  60. updatedVal = self.model.data(self.model.index(xLoc,yLoc+3))
  61. print xLoc,yLoc,updatedVal
  62. except AttributeError:
  63. pass
  64. readOnlyCols = [0]
  65. try:
  66. for i in itemIdxs:
  67. row = i[0]
  68. col = i[1]
  69. if col in readOnlyCols:
  70. pass
  71. else:
  72. self.model.setData(self.model.index(row,col), updatedVal, Qt.DisplayRole)
  73. except AttributeError:
  74. print ":("
  75. pass
  76.  
  77. # button induced save-change to CSV (NO UNDO YET!)
  78. def writeCsv(self, fileName):
  79. with open(fileName, "wb") as fileOutput:
  80. writer = csv.writer(fileOutput)
  81. writer.writerow(self.horizHeaders)
  82. for rowNumber in range(self.model.rowCount()):
  83. fields = [self.model.data(self.model.index(rowNumber,columnNumber),QtCore.Qt.DisplayRole) for columnNumber in range(self.model.columnCount())]
  84. writer.writerow(fields)
  85. print ':)'
  86.  
  87. @QtCore.pyqtSlot()
  88. def on_pushButtonWrite_clicked(self):
  89. self.writeCsv(self.fileName)
  90.  
  91. def Cancel(self):
  92. self.close()
  93.  
  94. def closeEvent(self,event):
  95. self.deleteLater()
  96.  
  97. def Release(self,index):
  98. global xLoc
  99. global yLoc
  100. xLoc,yLoc = index.row(),(index.column()-3)
To copy to clipboard, switch view to plain text mode 

Is it feasible to chop shop existing, or start from scratch rather?