Re: [gtk-list] Perl/Gtk: how to get the data from a Gtk::ListItem ?
- From: Kenneth Albanowski <kjahds kjahds com>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Perl/Gtk: how to get the data from a Gtk::ListItem ?
- Date: Tue, 14 Apr 1998 20:24:21 -0400 (EDT)
On Tue, 14 Apr 1998, Des Herriott wrote:
> Hi,
>
> I'm writing a Perl Gtk program which creates a Gtk::List, and adds
> several items to it, like this (boiler-plate code omitted):
>
> @items = qw(one two three four);
> $l = new Gtk::List;
>
> for $item (@items) {
> my $li = new Gtk::ListItem($item);
> $list->add($li);
> $li->show;
> }
> $list->signal_connect('selection_changed' => \&sel_callback);
>
> Now, this works fine - the items appear in the list as I'd expect.
> Here's the callback:
>
> sub sel_callback {
> my ($w) = @_;
> my @list = $w->selection;
> my $item = $list[0];
> # now what?
> }
>
> This gives me back a Gtk::ListItem, but how do I get the original data
> from it? It seems that in C I would use gtk_object_get_data() - is this
> right? Is this missing from the Perl binding or should I be using
> something else?
You can use the get_data and set_data methods on the listitems (although I
don't believe those methods are much use at the moment, as they'll only
let you store gtk_object types).
The Perl approach is simply to store the data in the listitem:
for $item (@items) {
my $li = new Gtk::ListItem($item);
$li->{mydata} = ++$mydata;
$list->add($li);
$li->show;
}
$list->signal_connect('selection_changed' => \&sel_callback);
--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]