NAME
Tk::GridColumns - Columns widget for Tk
SYNOPSIS
use Tk::GridColumns; # load the module
# to create a new Tk::GridColumns widget, use the following syntax,
# all options are optional, each default is shown here:
my $gc = new Tk::GridColumns ( # create a Tk::GridColumns widget
$top, # the frame/window to put it in
-scrollbars => 'ose', # change the scrollbars for the Pane
-relief => 'sunken', # change the relief for the Pane
-bd => 2, # change the borderwidth for the Pane
-background => 'white', # change the background for the Pane
-header_font => '{Arial} 10 {bold}', # change the header font
-header_cmd => Tk::GridColumns->generate_header_cmd, # change the header command
-item_scrollbars => 'osoe', # change the scrollbars for each item
-item_relief => 'sunken', # change the relief for each item
-item_bd => 2, # change the borderwidth for each item
-item_background => Tk::NORMAL_BG, # change the background for each item
-item_font => '{Arial} 10 {normal}', # change the font for each item
-item_padx => 1, # change the x-padding for each item
-item_pady => 1, # change the y-padding for each item
-item_draw_cmd => Tk::GridColumns->generate_item_draw_cmd, # change the item draw command
);
$gc->generate_header_cmd; # returns a sub to sort the grid, parameters are: object, column to sort after
$gc->generate_item_draw_cmd; # returns a sub to create a Tk::ROText widget with content and restricted width and height, paraneters are: object, content
$gc->set_opt( %opt ); # change options
$gc->get_opt( @keys ); # get option values
$gc->set_data( $data ); # set grid data
$gc->get_data; # get grid data
$gc->set_header( $head ); # set header data
$gc->get_header; # get header data
$gc->set_weight( $m, @cols ); # set column's ( @cols ) weight to $m
$gc->get_weight; # get the actual weight for some columns, unspecified columns have the weight 0
$gc->get_frame; # get the frame the items and the header is gridded on
$gc->get_grid; # get the widget hash, all displayed widgets can get found in this hash
$gc->add_row( @cols ); # add a data row to the GC ( after this operation you should refresh the items )
$gc->get_item( $x, $y ); # get the widget gridded at position $x, $y
$gc->get_head( $x ); # get the caption gridded at position $x, 0
$gc->refresh_header; # refresh the header
$gc->refresh_items; # refresh the items
$gc->refresh; # refresh header and items
$gc->del_header; # delete the actual header ( after this operation you should refresh the header )
$gc->del_items; # delete the actual items ( after this operation you should refresh the items )
$gc->draw_header; # draw the actual header ( after this operation you should refresh the header )
$gc->draw_items; # draw the actual items ( after this operation you should refresh the items )
# the following is NOT supported
#my $gc = $top -> GridColumns( %opt ); # this is NOT supported
DESCRIPTION
EXPORT
None by default.
Header Command
As you can see in the synopsis you can specify your own '-header_cmd'. This command will get 2 parameters on call, the object and the column the caption that has been clicked is gridded in. If you need extra data from the user, you can use the header to get it:
$gc->set_opt(
-header_cmd => sub {
my( $self, $x ) = @_; # pick object and column
my $capt = $self->get_header->[$x]; # get caption at column $x
my @extra = @{$capt->[1..$#{$capt}]}; # get the extra infos
},
);
If you want to get the old command back use the generate_header_cmd() method, which will return the default sub:
$gc->set_opt(
-header_cmd => $gc->generate_header_cmd,
);
Item draw command
As you can see in the synopsis you can specify your own '-item_draw_cmd'. This command will get 2 parameters on call, the object and the item to display. Inside this sub you have to create and return a Tk widget which displays the item, but don't pack() ( or grid() or place() or form() ) it. The returned widget will get gridded to the right position by the module.
If you want to get the old command back use the generate_item_draw_cmd() method, which will return the default sub:
$gc->set_opt(
-item_draw_cmd => $gc->generate_item_draw_cmd,
);
For an example of such a command, please look for the generate_item_draw_cmd() subroutine in hte module's code.
SEE ALSO
Tk::Columns, Tk::MListbox, Tk::Table
AUTHOR
Matthias Wienand, <matthias.wienand@googlemail.com>
COPYRIGHT AND LICENSE
Standard Perl license.
Copyright (C) 2008 by Matthias Wienand
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.