#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; 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 ( 'Text Field' => 'text', 'Bool Field1' => 'bool', 'Bool Field2' => 'bool', 'Bool Field3' => 'bool', ); @{$slist->{data}} = ( [ '1text', TRUE, TRUE, TRUE ], [ '2text', TRUE, FALSE, TRUE ], ); # (almost) anything you can do to an array you can do to # $slist->{data} which is an array reference tied to the list model push @{$slist->{data}}, [ '9text', FALSE, FALSE, TRUE ]; # mess with selections $slist->get_selection->set_mode ('multiple'); $slist->get_selection->unselect_all; $slist->select (1, 3, 5..9); # select rows by index $slist->unselect (3, 8); # unselect rows by index my @sel = $slist->get_selected_indices; # simple way to make text columns editable my $col_num = 0; $slist->set_column_editable ($col_num, TRUE); # Allow sorting on the column #$slist->get_model->set_sort_column_id(0); #Gtk2::TreeSortable::set_sort_column_id($slist, 0, undef); $scwin->add ($slist); my $vbox = Gtk2::VBox->new (0, 6); $hbox->pack_start($vbox, 0, 1, 0); # finally, a button to end it all my $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;