<table cellspacing='0' cellpadding='0' border='0' ><tr><td style='font: inherit;'>Ulrich,<br><br>Try pqsheet--I think it is a stalled project but it may have what you need.<br><br>Brian<br><br>--- On <b>Thu, 5/22/08, ulrichD <i><ulrich@dorda.net></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">From: ulrichD <ulrich@dorda.net><br>Subject: [PyQt] beginner, array setdata, write back<br>To: pyqt@riverbankcomputing.com<br>Date: Thursday, May 22, 2008, 9:32 AM<br><br><pre>I'm a novice to pyqt and search for something so basic, it's<br>embarrassing.<br>Unfortunately I still couldn't find any answer in the net (probably<br>don't<br>even know what to search for)<br>(in addition i hope I know dontt post twice now, the first time I got an<br>mail saying it was rejected)<br><br>I simply want a gui to show me the content of an numpy array. When I change<br>a value in the gui, i want this
to be written back into the array.<br><br>I tried something like:<br><br><br>XXXXXXXXXXXXXXXXXXXXXXXXXX<br>from __future__ import division<br>import sys<br>from math import *<br>from PyQt4.QtCore import *<br>from PyQt4 import QtCore<br>from PyQt4.QtGui import *<br><br>class sheet(QDialog): #By inheriting QDialog we get a blank form, that is,<br>a gray rectangle, and some convenient behaviors and methods<br> def __init__(self, arr, parent=None): #A widget that has no parent<br>becomes a top-level window<br> QWidget.__init__(self) <br> <br> tablemodel = MyTableModel(arr, self) <br> self.tabmod=tablemodel<br>        tableview = QTableView() <br> tableview.setModel(tablemodel) <br> <br> layout = QVBoxLayout(self) <br> layout.addWidget(tableview) <br> self.setLayout(layout)         <br>        <br>class MyTableModel(QAbstractTableModel): <br> def __init__(self, datain, parent=None): <br>
QAbstractTableModel.__init__(self, parent) <br> self.arraydata = datain <br> <br> def rowCount(self, parent): <br> return len(self.arraydata) <br> <br> def columnCount(self, parent): <br> return len(self.arraydata[0]) <br> <br> def data(self, index, role): <br> if not index.isValid(): <br> return QVariant() <br> elif role != Qt.DisplayRole: <br> return QVariant() <br> return QVariant(self.arraydata[index.row()][index.column()])<br> <br> def isEditable(self, index):<br> """ Return true if the index is editable.<br>"""<br> return True<br> <br> def flags(self, index): #function is called to chaeck if itmes are<br>changable etc, index is a PyQt4.QtCore.QModelIndex object<br> if not index.isValid():<br> return QtCore.Qt.ItemIsEnabled<br> <br> ret_flags = QtCore.Qt.ItemIsSelectable |<br>QtCore.QAbstractItemModel.flags(self,
index)<br> if self.isEditable(index):<br> #print index.row() #returns the selected elements row<br>         #print index.column()<br>         ret_flags = ret_flags | QtCore.Qt.ItemIsEditable <br> return ret_flags<br> <br><br> def setData(self, index, value, role):<br> """ if a item is edited, this command is called<br> value.toString() constains the new value<br> cahnge here to have it evaluate stuff!"""<br> self.arraydata[index.row(),index.column()]=value.toString() <br>#<<<<<<<<<<< the problem (i think)<br><br><br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>if this file is called ugui.py, it hem run it from the shell with<br><br>import ugui<br>arr=rand(3,3)<br>form = ugui.sheet(arr)<br>form.show()<br><br>I think I encounter two problems: I access the newly entered data<br>incorrectely and there seems to be a variable type issue.<br><br>Maybe someone can help me out
here?<br>-- <br>View this message in context:<br>http://www.nabble.com/beginner%2C-array-setdata%2C-write-back-tp17406877p17406877.html<br>Sent from the PyQt mailing list archive at Nabble.com.<br><br>_______________________________________________<br>PyQt mailing list PyQt@riverbankcomputing.com<br>http://www.riverbankcomputing.com/mailman/listinfo/pyqt</pre></blockquote></td></tr></table><br>