[PyKDE] strange problems with lxml and PyQt4

Andreas Pakulat apaku at gmx.de
Thu Jan 12 01:57:02 GMT 2006


Hi,

following Traceback:

Traceback (most recent call last):
  File "/home/andreas/projects/pyfilmdbsimpleui/widgets/pictureformatwidget.py", line 105, in on_removePictureFormat_clicked
    model.removeRows(index.row(), 1, index.parent())
  File "/home/andreas/projects/pyfilmdbsimpleui/widgets/generaltablemodel.py", line 77, in removeRows
    del self.datalist[row:row+count]
  File "etree.pyx", line 354, in etree._Element.__delslice__
NotImplementedError: QAbstractItemModel.parent() is abstract and must be overridden


with the following implemenation:

    def removeRows(self, row, count, parent = QtCore.QModelIndex()):
        if not self.datalist or len(self.datalist) < count:
            return False
        self.beginRemoveRows(QtCore.QModelIndex(), row, count+row-1)
        del self.datalist[row:row+count]
        self.endRemoveRows()
        return True

self is a subclass of QAbstractItemModel.
self.datalist is an element of a XML tree created by lxml

What am I doing wrong here?

Something similar happens when I insert rows via insertRows function:

    def insertRows(self, row, count, parent = QtCore.QModelIndex()):
        if not self.datalist:
            return False
        
        self.beginInsertRows( parent, row, count+row-1)
        for i in range(0, count):
            self.datalist.insert(row+i, common.buildElement(self.datalist, self.elementname))
        self.endInsertRows()
        return True

The really strange thing with insert is: It works if in the List nothing
is selected but I get a traceback similar to the one above when I first
select an item.

Oh and the methods that call insertRows and removeRows are:

    def on_removePictureFormat_clicked(self):
        list = self.pictureFormats.selectionModel().selectedIndexes()
        model = self.pictureFormats.model()
        for index in list:
            model.removeRows(index.row(), 1, index.parent())

    def on_addPictureFormat_clicked(self):
        self.pictureFormats.model().insertRows(self.pictureFormats.model().rowCount(), 1)

Hope somebody has a hint for me.

Andreas

-- 
You will have a long and unpleasant discussion with your supervisor.




More information about the PyQt mailing list