'list' object is not callable



  • Moving from PyQt to PySide, I'm noticing one of my views are spamming the error "TypeError: 'list' object is not callable". It seems the headers display normally, however the data method is not being executed and data is not displaying. Any insight appreciated.

    Qt 4.7.3
    PySide 1.1.0
    Python 2.7.3

    @from PySide import QtCore,QtGui

    class ScenarioOutputModel(QtCore.QAbstractItemModel):
    def init(self):
    super(ScenarioOutputModel,self).init()
    self.headers = []
    self.data = []

    def add_rows(self,rows):
        self.beginInsertRows(QtCore.QModelIndex(),self.rowCount(),(self.rowCount()+len(rows)-1))
        self.data.extend(rows)
        self.endInsertRows()
        
    def clear(self):
        self.data = []
        self.reset()
    
    def index(self,row,column,parent):
        """ Return index given a row, column, and parent index.
        param int row
        param int column
        param QModelIndex parent
        return int
        """
        return self.createIndex(row, column, QtCore.QModelIndex())
    
    def getNode(self,index):
        """ Return node of corresponding index.
        param QModelIndex index
        return Node
        """
        if index.isValid():
            node = index.internalPointer()
            if node is not None:
                return node
        return self.data
    
    def parent(self,index):
        """ Return parent index of given index.
        param QModelIndex index
        return QModelIndex
        """
        return QtCore.QModelIndex()
    
    def flags(self,index):
        return QtCore.Qt.ItemIsEnabled|QtCore.Qt.ItemIsSelectable
    
    def set_headers(self,headers):
        self.headers = headers
        self.headerDataChanged.emit(QtCore.Qt.Horizontal,0,len(headers)-1)
    
    def headerData(self,section,orientation,role=QtCore.Qt.DisplayRole):
        
        if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
            return self.headers[section]
        
        return None
    
    def rowCount(self,index=QtCore.QModelIndex()):
        return len(self.data)
    
    def columnCount(self,index=QtCore.QModelIndex()):
        return len(self.headers)
    
    def data(self,index,role=QtCore.Qt.DisplayRole):
        if not index.isValid():
            return None
        if role == QtCore.Qt.DisplayRole:
            print 'data'
            return self.data[index.row()][index.column()]
        return None
    

    if name == 'main':
    import sys
    app = QtGui.QApplication(sys.argv)

    table_view = QtGui.QTableView()
    model = ScenarioOutputModel()
    table_view.setModel(model)
    
    model.set_headers(['H%s'%s for s in range(10)])
    model.add_rows([[str(y) for y in range(10)] for x in range(10)])
    
    mw = QtGui.QMainWindow()
    mw.setCentralWidget(table_view)
    mw.show()
    
    sys.exit(app.exec_())
    

    @



  • slap forehead

    Apparently naming a local variable the same as an method was tolerated somehow in pyqt. Renaming self.data to something else relieved the issue.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.