Re: [PyQt] Fast way to display an array in a table?

2009-05-29 Thread V. Armando Solé

David Douard wrote:

Le jeudi 28 mai 2009 20:57:50 Vicente Sole, vous avez écrit :
  

Hello,

I am writing a generic data handling application in which I need to be
able to show the contents of a numpy array in a sort of
table/spreadsheet. The array can be big (1024 x 1024 floats or may be
even more).

Is there a faster way of filling a table than looping through all the
array elements and introducing them in the table cells one by one?




You should use a QTableView with a model you write (which should derivate from 
QAbstractTableModel) like the file attached

Wow! Thanks a lot.

Armando


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Fast way to display an array in a table?

2009-05-28 Thread Vicente Sole

Hello,

I am writing a generic data handling application in which I need to be  
able to show the contents of a numpy array in a sort of  
table/spreadsheet. The array can be big (1024 x 1024 floats or may be  
even more).


Is there a faster way of filling a table than looping through all the  
array elements and introducing them in the table cells one by one?


Thanks for any hint.

Armando
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Fast way to display an array in a table?

2009-05-28 Thread David Douard
Le jeudi 28 mai 2009 20:57:50 Vicente Sole, vous avez écrit :
 Hello,

 I am writing a generic data handling application in which I need to be
 able to show the contents of a numpy array in a sort of
 table/spreadsheet. The array can be big (1024 x 1024 floats or may be
 even more).

 Is there a faster way of filling a table than looping through all the
 array elements and introducing them in the table cells one by one?


You should use a QTableView with a model you write (which should derivate from 
QAbstractTableModel) like the file attached.

-- 
David DouardLOGILAB, Paris (France), +33 1 45 32 03 12
Formations Python, Numpy, Debian :   http://www.logilab.fr/formations
Développement logiciel sur mesure : http://www.logilab.fr/services
Informatique scientifique : http://www.logilab.fr/science

import numpy
from PyQt4 import QtCore, QtGui
Qt = QtCore.Qt

class NumpyModel(QtCore.QAbstractTableModel):
def __init__(self, narray, parent=None):
QtCore.QAbstractTableModel.__init__(self, parent)
self._array = narray

def rowCount(self, parent=None):
return self._array.shape[0]

def columnCount(self, parent=None):
return self._array.shape[1]

def data(self, index, role=Qt.DisplayRole):
if index.isValid():
if role == Qt.DisplayRole:
row = index.row()
col = index.column()
return QtCore.QVariant(%.5f%self._array[row, col])
return QtCore.QVariant()

if __name__ == __main__:
a = QtGui.QApplication([])
w = QtGui.QTableView()
d = numpy.random.normal(0,1, (1000,1000))
m = NumpyModel(d)
w.setModel(m)

w.show()
a.exec_()


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt