Re: get_selection_info equivalent for treeview?



On Mon, 2003-10-20 at 21:49, mpd wrote:
As the subject says, I'm having an annoying time getting
data out of a TreeView (actually a SimpleList) when a
mouse button is clicked on it.

the tree widget in Gtk2 uses a separate object to manage selections.
http://developer.gnome.org/doc/API/2.0/gtk/GtkTreeSelection.html
the api is very C-ish in that some of the functions return lists and/or
optional parameters and most functions write through a parameter, so the
perl api is a different from C in a couple of important places.  be sure
to have a look at the "differences" section of Gtk2::api.

fetch the selection object from the treeview:

  $treeselection = $treeview->get_selection;

the selection can have different modes, like 'single', 'multiple',
'browse', and 'extended'...

   if ($treeselection->get_mode eq 'single') {
       my $iter = $treeselection->get_selected;
       # -or-
       my ($model, $iter) = $treeselection->get_selected;
   } else {
       # fetch all selected, which may be zero or all)
       my @paths = $treeselection->get_selected_rows;
   }

if you already have an iter, e.g. you have button click coordinates, and
you ask the treeview for the iter at that position, you can find out if
that iter is selected:

   bool = $treeselection->iter_is_selected ($iter);

you can also supply a function to be run on all selected nodes, or a
function to be called just before a node is selected, so you can
determine whether it should be selected or not.


-- 
muppet <scott at asofyet dot org>




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