Re: Gtk2::TreeModel::foreach callback not getting any arguments?



On Saturday, September 20, 2003, at 05:00 PM, Dan Lyke wrote:

First: I'm browsing a rather large tree which could have a lot of
images, so I want to be able to load and unload images as the tree
gets browsed. I'm doing a:

$treestore->foreach($iterator, forEach, ['populate', $self->{-nodemapping}]);

on the expand message, but although my "forEach" callback is getting
called, it isn't getting any arguments. Any hints?

um... yeah, how is that working at all? i can't find any foreach method that takes an iterator.

there's these two:
   $treemodel->foreach (\&func, $data);
http://developer.gnome.org/doc/API/2.0/gtk/GtkTreeModel.html#gtk-tree- model-foreach
   $treeselection->selected_foreach (\&func, $data);
http://developer.gnome.org/doc/API/2.0/gtk/GtkTreeSelection.html#gtk- tree-selection-selected-foreach

remember also that you have to give a code *reference* either via anonymous subs or taking references to named subs:

   $coderef = sub { };      # an anonymous subroutine.

   $coderef = \&named_sub;  # note the all-important backslash!
                            # if you use & only then you're just
                            # calling it.


Which leads me to: Is there a better way to store metadata in a
TreeStore than just put it in an unused column?

if it's per-row metadata, no. and it's not so much unused as unshown. ;)

if it's per-model data, then you can just put it in a key within the $model itself, like

    $model->{foo} = $bar;


I'm using a string
right now, which means that when I get it back out it's unblessed, and
I have to run it back through a hash to figure out which object it was
originally associated with.

you can put any perl scalar, including blessed or unblessed references, in a column of type Glib::Scalar.

--
muppet <scott at asofyet dot org>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]