[PyKDE] strange problems with lxml and PyQt4

Phil Thompson phil at riverbankcomputing.co.uk
Thu Jan 12 09:48:24 GMT 2006


On Thursday 12 January 2006 1:57 am, Andreas Pakulat wrote:
> 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.

You need to post a short, but complete, example that demonstrates the problem. 
When people select code fragments to post, but can't find the error, its 
usually because they are looking in the wrong place.

Phil




More information about the PyQt mailing list