Thanks Robin, I had somehow missed this demo. I got to a relatively
good point, but I am now facing a very weird issue.
The text editor I built is a tabbed notebook, and every time the user
switches tab the dataview tree gets repopulated. Now, after a while of
this back and forth switching, I get the following:
Traceback (most recent call last):
File "C:\MyProjects\DeckEd\src\sidepages.py", line 144, in GetValue
node = self.ItemToObject(item)
File "C:\Python27\lib\site-packages\wx-2.9.3-msw\wx\dataview.py",
line 773, in ItemToObject
return self.objmapper.ItemToObject(item)
File "C:\Python27\lib\site-packages\wx-2.9.3-msw\wx\dataview.py",
line 721, in ItemToObject
oid = item.GetID()
File "C:\Python27\lib\site-packages\wx-2.9.3-msw\wx\dataview.py",
line 110, in GetID
return _dataview.DataViewItem_GetID(*args, **kwargs)
PyAssertionError: C++ assertion "Assert failure" failed at
..\..\src\msw\dcmemory.cpp(131) in wxMemoryDCImpl::DoSelect():
Couldn't select a bitmap into wxMemoryDC
And many other errors after this, seemingly related to saturations of
GDI objects (after 4 or 5 tab switches the GDI count reaches 10,000).
There are a couple of issues I am not sure about:
1) I am using DataViewIconText to render images close to the text in
the tree (BTW, why the use of wx.Icon??? It was so convenient to have
wx.Bitmap everywhere...), but if I do the following in my
PyDataViewModel:
def GetValue(self, item, col):
node = self.ItemToObject(item)
return dv.DataViewIconText(node.name, node.icon)
SWIG complains as follow:
swig/python detected a memory leak of type 'wxDataViewIconText *', no
destructor found.
The only way to make this message go away is to store the
DataViewIconText as an attribute of my node class, i.e.:
self.iconText = dv.DataViewIconText(name, icon)
and then in PyDataViewModel:
def GetValue(self, item, col):
node = self.ItemToObject(item)
return node.iconText
2) It appears that the GDI count increase without bounds every time I
call AssociateModel() to DataViewCtrl. The problem is, my model
changes completely from one tab to another, so I can't simply use
ItemsChanged() and/or ItemsDeleted() or whatever. I need to rebuild
the model from scratch and re-associate it with DVC.
If someone sees something wrong in what I am doing, please do offer
your suggestion. In the meanwhile I'll try to put together a sample
demonstrating the problem.
···
On 23 April 2012 18:36, Robin Dunn wrote:
On 4/23/12 3:01 AM, Andrea Gavana wrote:
Hi All,
in the latest application I am writing, I am currently using
CustomTreeCtrl to display a series of keywords coming from text files
rendered with StyledTextCtrl. However, some files may contain many,
many keywords and the realtime update of a lot of tree items in
CustomTreeCtrl becomes expensive. So, as much as it pains me to leave
CustomTreeCtrl, I have begun investigating the DataView stuff.
Now, I know nothing of DataView things, but I still have a couple of
questions:
1) Is there a way to implement virtual tree controls with the various
DataView classes?
2) (opportunistic-question) If it is possible, does anyone have a
sample on how to actually go for it (or some suggestions/guidances on
how to implement it)?
Take a look at the DVC_DataViewModel sample in the demo. It implements a
tree model, the key point for the hierarchy being the implementation of the
GetChildren and GetParent methods.
--
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/