Simon Cozens > Gtk-HandyCList > Gtk::HandyCList

Download:
Gtk-HandyCList-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Gtk::HandyCList - A more Perl-friendly Columned List

SYNOPSIS ^

  use Gtk::HandyCList;
  my $vbox = new Gtk::VBox(0,5);
  my $scrolled_window = new Gtk::ScrolledWindow( undef, undef );
  $vbox->pack_start( $scrolled_window, 1, 1, 0 );
  $scrolled_window->set_policy( 'automatic', 'always' );

  my $list = Gtk::HandyCList->new( qw(Name Date Cost) );
  $list->data( [ "Foo", "29/05/78", 12.33],
               [ "Bar", "01/01/74", 104.21],
               # ...
             );
  $list->sizes( Name => 100, Date => "30%", Cost => "40%" );
  $list->sortfuncs( Name => "alpha", Date => \&date_sort, Cost => "number");

DESCRIPTION ^

This is a version of Gtk::CList which takes care of some common things for the programmer. For instance, it keeps track of what's stored in the list, so you don't need to keep a separate array; when the column titles are clicked, the list will be re-sorted according to user-supplied functions or some default rules. It allows you to reference columns by name, instead of by number.

METHODS ^

new(@titles)

This is equivalent to Gtk::CList->new_with_titles, but initialises all the data structures required for HandyCList.

data(@data)

A get-set method to retrieve and/or set the data in the table. The data is specified as an array of rows, and each row may either be an array reference or a hash reference. If a hash reference, the keys of the hash must correspond to the columns of the table.

Example: You may either say this, using array references:

  my $list = Gtk::HandyCList->new( qw(Name Date Cost) );
  $list->data( [ "Foo", "29/05/78", 12.33],
               [ "Bar", "01/01/74", 104.21] );

or this, using hash references:

  my $list = Gtk::HandyCList->new( qw(Name Date Cost) );
  $list->data( { Name => "Foo", Date => "29/05/78", Cost => 12.33 },
               { Name => "Bar", Date => "01/01/74", Cost =>104.21 } );

The data will be returned as an array of hash references.

clear

Remove all entries from the list.

append(@items)

Append some items to the list; semantics of @items are the same as for the data method above.

prepend(@items)

Append some items to the start of the list

sortfuncs(@functions | %functions )

HandyCList automatically takes care of sorting the columns in the list for you when the user clicks on the column titles. To do this, though, you need to provide indication of how the data should be sorted. You may provide either a list or a hash (keyed to columns as before) of subroutine references or the strings "alpha" or "number" for alphabetic and numeric comparison respectively.

Subroutine references here are not the same as you would hand to sort: they must take two arguments and compare them, instead of comparing the implicit variables $a and $b.

refresh

Make sure that the data displayed in the list is the same as the data you'd get back from $list->data. You probably won't need to call this, unless you're doing freaky things.

sizes(@columns | %columns)

Set the size of each column as a number of pixels or as a percentage. At least one of the columns must be given as a number of pixels. Percentages should be strings like "40%", not floating point numbers.

selection

Return data regarding what is currently selected. The return value is a hashref, the keys being the (0-based) row numbers selected, the values being hashrefs themselves, from column name to column data.

hide (@columns)

Prevent certain columns from being displayed.

unhide (@columns)

Re-allow display of certain columns

AUTHOR ^

Simon Cozens, simon@cpan.org

SEE ALSO ^

GNOME, Gtk::CList

syntax highlighting: