in reply to Can't locate object method "get_row_data_from_path" via package "Gtk2::Ex::Simple::List"

When the user clicks on the list, I only want to know which row has been selected.

The code you posted runs fine here, so I don't know what your problem is. The following shows how to do row selection.

#!/usr/bin/perl -w use Data::Dumper; use Gtk2 -init; use Gtk2::Ex::Simple::List; my $win = Gtk2::Window->new; $win->set_title ('Gtk2::Ex::Simple::List exapmle'); $win->set_border_width (6); $win->set_default_size (500, 300); $win->signal_connect (delete_event => sub { Gtk2->main_quit; }); my $hbox = Gtk2::HBox->new (0, 6); $win->add ($hbox); my $scwin = Gtk2::ScrolledWindow->new; $hbox->pack_start ($scwin, 1, 1, 0); $scwin->set_policy (qw/automatic automatic/); my $slist = Gtk2::Ex::Simple::List->new ( 'Name' => 'text', ); $slist->get_selection->set_mode ('multiple'); @{$slist->{data}} = ('a'..'z'); $scwin->add ($slist); my $vbox = Gtk2::VBox->new (0, 6); $hbox->pack_start($vbox, 0, 1, 0); my $button = Gtk2::Button -> new('What\'s Selected by indices?'); $button -> signal_connect(clicked => \&report_indices, $window); # pack quit button into $main_vbox $vbox -> pack_start($button, 0, 1, 0); my $button1 = Gtk2::Button -> new('What\'s Selected by value?'); $button1 -> signal_connect(clicked => \&report_items, $window); # pack quit button into $main_vbox $vbox -> pack_start($button1, 0, 1, 0); my $button2 = Gtk2::Button -> new('Delete a value(s)'); $button2 -> signal_connect(clicked => \&del_items, $window); # pack quit button into $main_vbox $vbox -> pack_start($button2, 0, 1, 0); my $button3 = Gtk2::Button -> new('Insert values at pos 2'); $button3 -> signal_connect(clicked => \&add_items, $window); # pack quit button into $main_vbox $vbox -> pack_start($button3, 0, 1, 0); my $button4 = Gtk2::Button -> new('Overwrite values at pos 2'); $button4 -> signal_connect(clicked => \&rpl_items, $window); # pack quit button into $main_vbox $vbox -> pack_start($button4, 0, 1, 0); # finally, a button to end it all $btn = Gtk2::Button->new_from_stock ('gtk-quit'); $btn->signal_connect (clicked => sub { Gtk2->main_quit; }); $vbox->pack_end($btn, 0, 1, 0); $win->show_all; Gtk2->main; sub del_items { my @indices = $slist -> get_selected_indices; #need to sort numerically, and splice off the highest numbers first + foreach my $i (reverse sort {$a<=>$b} @indices ) { print "$i\n"; splice @{ $slist->{data} }, $i, 1; } } sub add_items { my @new; for(1..5){push @new,int rand 100} # adds 5 elements at pos 2, shifting others over + splice @{ $slist->{data} }, 2, 0, @new; } sub rpl_items { my @new; for(1..5){push @new,int rand 100} # adds 5 elements at pos 2, removing previous items + splice @{ $slist->{data} }, 2, 5, @new; } sub report_indices { my @indices = $slist -> get_selected_indices; foreach my $i (@indices) { print $i . "\n"; # I'd rather print the actual data here. } } sub report_items { my @indices = $slist -> get_selected_indices; foreach my $i (@indices) { print $slist->{data}[$i][0] . ' '; } print "\n"; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh
  • Comment on Re: Can't locate object method "get_row_data_from_path" via package "Gtk2::Ex::Simple::List"
  • Download Code