Re: Custom TreeModel
- From: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
- To: Torsten Schoenfeld <kaffeetisch gmx de>
- Cc: gtk-perl-list gnome org
- Subject: Re: Custom TreeModel
- Date: Thu, 14 Jan 2010 08:35:42 +0100
On Thu, Jan 14, 2010 at 12:05 AM, Torsten Schoenfeld
<kaffeetisch gmx de> wrote:
On 09.01.2010 16:08, Emmanuel Rodriguez wrote:
What I've noticed is that the data stored in the Gtk2::TreeIter is
really volatile and that it doesn't survive too long after a method
returns. Furthermore, only the 2 first elements of the TreeIter make it
back to the TreeModel methods intact. I also noticed that setting
references into the last 2 fields can yield strange situations.
As Kevin said, tree iters don't keep stuff you put into them alive for you. ÂIf you want to put any non-integer thing into an iter, you need to keep it alive some other way, for example by also storing it in a cache inside the tree model. ÂThis is also shortly explained in perldoc Gtk2::TreeModel / CREATING A CUSTOM TREE MODEL.
I see that there's not way to avoid the cache. It's a bit of a pity that I can't detect when an iter is no longer needed as eventually all nodes will be duplicated into the cache.
I'm guessing that with a normal (pure Perl) tree model this will not be the case as nodes will be already in the model. Using XML::LibXML nodes is a bit peculiar as the memory management is a bit different. If I'm not mistaken XML::LibXML assumes that nodes are attached to the underlying C model and that the SVs wrapping them can be easily discarded at anytime as long as the original C structure lives.
I could rewrite this tree model with a pure Perl tree model (HTML::Tree) and add it to the Gtk2-Perl examples.
Here's a patch against your program that implements this. ÂIt also fixes an unrelated typo.
Thanks.
Â
Is the Perl sample code wrong? Maybe I missed something..
Would it make sense to add it to the Gtk2-Perl examples, perhaps someone
could find it useful.
The customlist.pl example does this in GET_ITER:
   Âmy $record = $self->{rows}[$n];
   Â...
   Âreturn [ $self->{stamp}, $n, $record, undef ];
So the reference it puts into the iter is kept alive by $self->{rows}.
I guess a better explanation in the example and maybe also in the Gtk2::TreeModel docs would be useful. ÂCare to write something up?
I will do it.
--
Emmanuel Rodriguez
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]