On 04.04.07 14:09:16, Andreas Pakulat wrote:
> On 04.04.07 02:14:05, Andreas Pakulat wrote:
> > Hi,
> >
> > just updated to python2.5 and latest snapshots of pyqt4/sip/eric4
> > (20070402) and trying to start it I get:
> >
> > An unhandled exception occurred. Please report the problem using the error
> > reporting dialog or via email to <[EMAIL PROTECTED]>. A log has been
> > written to "/home/andreas/.eric4/eric4_error.log".
>
> This seems to be a serious bug in BrowserModel.py, it created indices
> using createIndex( row, column, item ) and later on it uses indices that
> are given to it (for example in the item() function) to retrieve the
> item from a dict. This can't work, using createIndex() will set the
> internalPointer() of that index, but internalId() will return some
> "arbitrary" value (i.e. -1.....). So BrowserModel.py needs to be fixed
> to be consistent, either always use createIndex(row,col,id(item)) or
> always use internalPointer() instead of internalId().
Ok, I talked to Phil on the pyqt list and it seems internalId() is not
reliable in Python due to the fact that in Python id() uses a long,
while in C++ createIndex uses a quint32 and internalId in C++ uses a
quint64 (which is probably a bug anyway). So I created a patch which
fixes BrowserModel and unless I'm mistaken also ProjectBrowserModel, by
using internalPointer and the object-overload of createIndex together
with a list of objects instead of a dict.
Andreas
--
Communicate! It can't make things any worse.
diff -u --exclude '*pyc' -ur eric4-snapshot-20070402/eric/eric4.py eric4-snapshot-20070402.new/eric/eric4.py
--- eric4-snapshot-20070402/eric/eric4.py 2007-03-25 13:47:37.000000000 +0200
+++ eric4-snapshot-20070402.new/eric/eric4.py 2007-04-05 17:54:00.000000000 +0200
@@ -12,6 +12,8 @@
"""
import sys
+sys.path.append("/home/andreas/compiling/python/eric/eric4-snapshot-20070402/")
+sys.path.append("/home/andreas/compiling/python/eric/eric4-snapshot-20070402/eric")
import os
import traceback
from StringIO import StringIO
diff -u --exclude '*pyc' -ur eric4-snapshot-20070402/eric/Project/ProjectBrowserModel.py eric4-snapshot-20070402.new/eric/Project/ProjectBrowserModel.py
--- eric4-snapshot-20070402/eric/Project/ProjectBrowserModel.py 2007-02-10 21:34:26.000000000 +0100
+++ eric4-snapshot-20070402.new/eric/Project/ProjectBrowserModel.py 2007-04-05 18:21:17.000000000 +0200
@@ -200,7 +200,7 @@
"""
QAbstractItemModel.__init__(self, parent)
- self.item_dict = {}
+ self.item_dict = []
rootData = QVariant(self.trUtf8("Name"))
self.rootItem = BrowserItem(None, rootData)
@@ -247,19 +247,19 @@
@param role role of data (Qt.ItemDataRole)
@return requested data (QVariant)
"""
- if not index.isValid():
+ if not index.isValid() or index.internalPointer() not in self.item_dict:
return QVariant()
if role == Qt.TextColorRole:
if index.column() == 0:
try:
- return self.item_dict[index.internalId()].getTextColor()
+ return index.internalPointer().getTextColor()
except AttributeError:
return QVariant()
elif role == Qt.BackgroundColorRole:
try:
col = self.itemBackgroundColors[\
- self.item_dict[index.internalId()].vcsState]
+ index.internalPointer().vcsState]
if col.isValid():
return QVariant(col)
else:
@@ -465,8 +465,7 @@
if parentItem is None:
parentItem = self.rootItem
- for childId in parentItem.children():
- itm = self.item_dict[childId]
+ for itm in parentItem.children():
if QString(itm.data(column)) == QString(text):
return itm
@@ -630,12 +629,12 @@
if childItem is not None:
self.beginRemoveRows(parentIndex, childItem.row(), childItem.row())
# step 1: remove all children of childItem
- ids = self.__getChildIds(childItem)
+ ids = self.__getChilds(childItem)
for id_ in ids:
- del self.item_dict[id_]
+ del self.item_dict[self.item_dict.index(id_)]
# step 2: remove the childItem
- parentItem.removeChild(id(childItem))
- del self.item_dict[id(childItem)]
+ parentItem.removeChild(childItem)
+ del self.item_dict[self.item_dict.index(childItem)]
self.endRemoveRows()
def __getChildIds(self, item):
@@ -647,7 +646,7 @@
ids = []
for id_ in item.children():
- ids += self.__getChildIds(self.item_dict[id_])
+ ids += self.__getChildIds(id_)
ids += item.children()
return ids
@@ -670,7 +669,7 @@
self.beginRemoveRows(index, 0, itm.childCount() - 1)
ids = self.__getChildIds(itm)
for id_ in ids:
- del self.item_dict[id_]
+ del self.item_dict[self.item_dict.index(id_)]
itm.removeChildren()
self.endRemoveRows()
Utilities.ModuleParser.resetParsedModule(os.path.join(self.project.ppath, name))
@@ -776,8 +775,8 @@
if itm:
state = " "
for id_ in itm.children():
- if state < self.item_dict[id_].vcsState:
- state = self.item_dict[id_].vcsState
+ if state < id_.vcsState:
+ state = id_.vcsState
if state != itm.vcsState:
itm.setVcsState(state)
index1 = self.createIndex(itm.row(), 0, itm)
@@ -798,7 +797,7 @@
continue
self.itemBackgroundColors[code] = color
- for itm in self.item_dict.values():
+ for itm in self.item_dict:
if itm.vcsState == code:
index1 = self.createIndex(itm.row(), 0, itm)
index2 = self.createIndex(itm.row(),
@@ -811,7 +810,7 @@
color = Preferences.getProjectBrowserColour("Highlighted")
if self.highLightColor.name() != color.name():
self.highLightColor = color
- for itm in self.item_dict.values():
+ for itm in self.item_dict:
if itm.bold:
index1 = self.createIndex(itm.row(), 0, itm)
index2 = self.createIndex(itm.row(),
diff -u --exclude '*pyc' -ur eric4-snapshot-20070402/eric/UI/BrowserModel.py eric4-snapshot-20070402.new/eric/UI/BrowserModel.py
--- eric4-snapshot-20070402/eric/UI/BrowserModel.py 2007-03-18 14:08:11.000000000 +0100
+++ eric4-snapshot-20070402.new/eric/UI/BrowserModel.py 2007-04-05 18:14:13.000000000 +0200
@@ -41,7 +41,7 @@
"""
QAbstractItemModel.__init__(self, parent)
- self.item_dict = {}
+ self.item_dict = []
rootData = QVariant(self.trUtf8("Name"))
self.rootItem = BrowserItem(None, rootData)
@@ -67,16 +67,16 @@
@param role role of data (Qt.ItemDataRole)
@return requested data (QVariant)
"""
- if not index.isValid():
+ if not index.isValid() or index.internalPointer() not in self.item_dict:
return QVariant()
-
+
if role == Qt.DisplayRole:
- item = self.item_dict[index.internalId()]
+ item = index.internalPointer()
if index.column() < item.columnCount():
return QVariant(item.data(index.column()))
elif role == Qt.DecorationRole:
if index.column() == 0:
- return QVariant(self.item_dict[index.internalId()].getIcon())
+ return QVariant(index.internalPointer().getIcon())
## elif role == Qt.ToolTipRole:
## if index.column() == 0:
## return QVariant(self.item_dict[index.internalId()].data(index.column()))
@@ -90,7 +90,7 @@
@param index index of the data to retrieve (QModelIndex)
@return requested flags (Qt.ItemFlags)
"""
- if not index.isValid():
+ if not index.isValid() or index.internalPointer() not in self.item_dict:
return Qt.ItemIsEnabled
return Qt.ItemIsEnabled | Qt.ItemIsSelectable
@@ -121,18 +121,18 @@
@param parent index of parent item (QModelIndex)
@return index object (QModelIndex)
"""
- if not parent.isValid():
+ if not parent.isValid() or parent.internalPointer() not in self.item_dict:
parentItem = self.rootItem
else:
try:
- parentItem = self.item_dict[parent.internalId()]
+ parentItem = parent.internalPointer()
except KeyError:
return QModelIndex()
try:
if not parentItem.isPopulated():
self.populateItem(parentItem)
- childItem = self.item_dict[parentItem.child(row)]
+ childItem = parentItem.child(row)
except IndexError:
childItem = None
except KeyError:
@@ -149,10 +149,10 @@
@param index index of the item (QModelIndex)
@return index of parent item (QModelIndex)
"""
- if not index.isValid():
+ if not index.isValid() or index.internalPointer() not in self.item_dict:
return QModelIndex()
- childItem = self.item_dict[index.internalId()]
+ childItem = index.internalPointer()
parentItem = childItem.parent()
if parentItem == self.rootItem:
@@ -167,10 +167,10 @@
@param parent index of parent item (QModelIndex)
@return number of rows (integer)
"""
- if not parent.isValid():
+ if not parent.isValid() or parent.internalPointer() not in self.item_dict:
parentItem = self.rootItem
else:
- parentItem = self.item_dict[parent.internalId()]
+ parentItem = parent.internalPointer()
if not parentItem.isPopulated(): # lazy population
self.populateItem(parentItem)
@@ -186,12 +186,12 @@
@param parent index of parent item (QModelIndex)
@return flag indicating the presence of child items (boolean)
"""
- if not parent.isValid():
+ if not parent.isValid() or parent.internalPointer() not in self.item_dict:
return self.rootItem.childCount() > 0
- elif self.item_dict[parent.internalId()].isLazyPopulated():
+ elif parent.internalPointer().isLazyPopulated():
return True
else:
- return self.item_dict[parent.internalId()].childCount() > 0
+ return parent.internalPointer().childCount() > 0
def clear(self):
"""
@@ -208,10 +208,9 @@
@param index index of the data to retrieve (QModelIndex)
@return requested item reference (BrowserItem)
"""
- if not index.isValid():
+ if not index.isValid() or index.internalPointer() not in self.item_dict:
return None
-
- return self.item_dict[index.internalId()]
+ return index.internalPointer()
def __populateModel(self):
"""
@@ -243,11 +242,11 @@
return
# remove old entry
- id_ = id(self.progDir)
+ id_ = self.progDir
self.beginRemoveRows(QModelIndex(), self.progDir.row(), self.progDir.row())
self.rootItem.removeChild(id_)
self.endRemoveRows()
- del self.item_dict[id_]
+ del self.item_dict[self.item_dict.index(id_)]
self.progDir = None
itm = BrowserDirectoryItem(self.rootItem, dirname)
@@ -271,16 +270,16 @@
@param index index of the toplevel directory to be removed (QModelIndex)
"""
- if not index.isValid():
+ if not index.isValid() or index.internalPointer() not in self.item_dict:
return
- id_ = index.internalId()
+ id_ = index.internalPointer()
self.beginRemoveRows(index.parent(), index.row(), index.row())
self.rootItem.removeChild(id_)
self.endRemoveRows()
- self.toplevelDirs.removeAll(self.item_dict[id_].dirName())
- del self.item_dict[id_]
+ self.toplevelDirs.removeAll(id_.dirName())
+ del self.item_dict[self.item_dict.index(id_)]
def saveToplevelDirs(self):
"""
@@ -296,9 +295,8 @@
@param itm reference to item to add (BrowserItem)
@param parentItem reference to item to add to (BrowserItem)
"""
- id_ = id(itm)
- self.item_dict[id_] = itm
- parentItem.appendChild(id_)
+ self.item_dict.append( itm )
+ parentItem.appendChild( itm )
def addItem(self, itm, parent = QModelIndex()):
"""
@@ -307,10 +305,10 @@
@param itm item to add (BrowserItem)
@param parent index of parent item (QModelIndex)
"""
- if not parent.isValid():
+ if not parent.isValid() or parent.internalPointer() not in self.item_dict:
parentItem = self.rootItem
else:
- parentItem = self.item_dict[parent.internalId()]
+ parentItem = parent.internalPointer()
cnt = parentItem.childCount()
self.beginInsertRows(parent, cnt, cnt)
self._addItem(itm, parentItem)
@@ -604,7 +602,7 @@
@return row number (integer)
"""
- return self.parentItem.childItems.index(id(self))
+ return self.parentItem.childItems.index(self)
def type(self):
"""
_______________________________________________
Eric mailing list
[email protected]
http://www.riverbankcomputing.com/mailman/listinfo/eric