Discussion:
DataViewCtrl: can't add more than 256 items
d***@gmail.com
2014-09-21 04:45:00 UTC
Permalink
Hi, in my application I use a DataViewCtrl as a tree with a DataViewModel
that retrieves the data from a database. New items can be added to the
model and the control with a menu action.

My problem is:
* If the initial database has less than 256 items, I can add items up to
the 256th, then the error below appears.
* It the initial database has 256 items or more, it displays all of them
correctly, but then when I try to add 1 more, the error below appears.

The following error happens exactly when I call the model's ItemAdded
method:

#############################################
Traceback (most recent call last):
File
"/mnt/archive/Development/outspline/src/outspline/interfaces/wxgui/tree.py",
line 45, in GetParent
if not item.IsOk():
File "/usr/lib/python2.7/site-packages/wx-3.0-gtk2/wx/dataview.py", line
105, in IsOk
return _dataview.DataViewItem_IsOk(*args, **kwargs)
PyAssertionError: C++ assertion "posInModel != (-1)" failed at
./src/gtk/dataview.cpp(3646) in ItemAdded(): adding non-existent item?
#############################################

Unfortunately I've tried hours and hours to make a minimal script to
reproduce the same error, but to no avail :( However 256 is a rather
special number in programming (1 byte of something?), maybe somebody can
help me understand where it comes from because I'm starting to get
desperate :P

My system is:
wxPython 3.0.1.1
wxGTK 3.0.1
GTK 2.24.24
Arch Linux x86_64

Thank you
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Dario Giovannetti
2014-09-21 07:01:30 UTC
Permalink
Post by d***@gmail.com
Hi, in my application I use a DataViewCtrl as a tree with a
DataViewModel that retrieves the data from a database. New items can
be added to the model and the control with a menu action.
* If the initial database has less than 256 items, I can add items up
to the 256th, then the error below appears.
* It the initial database has 256 items or more, it displays all of
them correctly, but then when I try to add 1 more, the error below
appears.
The following error happens exactly when I call the model's ItemAdded
#############################################
File
"/mnt/archive/Development/outspline/src/outspline/interfaces/wxgui/tree.py",
line 45, in GetParent
File "/usr/lib/python2.7/site-packages/wx-3.0-gtk2/wx/dataview.py",
line 105, in IsOk
return _dataview.DataViewItem_IsOk(*args, **kwargs)
PyAssertionError: C++ assertion "posInModel != (-1)" failed at
./src/gtk/dataview.cpp(3646) in ItemAdded(): adding non-existent item?
#############################################
Unfortunately I've tried hours and hours to make a minimal script to
reproduce the same error, but to no avail :( However 256 is a rather
special number in programming (1 byte of something?), maybe somebody
can help me understand where it comes from because I'm starting to get
desperate :P
wxPython 3.0.1.1
wxGTK 3.0.1
GTK 2.24.24
Arch Linux x86_64
Thank you
--
You received this message because you are subscribed to a topic in the
Google Groups "wxPython-users" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/wxpython-users/JG9fB2BoDKA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
Never mind, I've found it: since I'm retrieving the data from an SQLite
database, I was making it simple (too simple) and storing only the ids
of the items in the DataViewModel, e.g. `self.ObjectToItem(dbid)`, where
`dbid` is a simple _integer_, which is only what I needed to retrieve
the data in the database in the model.

But that's wrong, don't do it. Always use proper objects, like in the
demos by the way, e.g.:

##############################
class DBItem(object):
def __init__(self, id_):
self.id_ = id_

def get_id(self):
return self.id_
##############################

Then instantiate the class as needed and store those objects in the
DataViewModel instead of the integers.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...