in reply to Text Tags with Tk::Hlist ??

Thank you very much zentara for your quick help. I am aware of the Tk::Itemstyle technique to 'condition' the Hlist widget. However, it does not provide options for callbacks on the specified widget (or maybe I'm wrong).

Is it possible to include a callback to a subroutine for the Hlist item on a row basis ?? Say for example, I would like to display details of the current entry (like row no,etc).

Replies are listed 'Best First'.
Re^2: Text Tags with Tk::Hlist ??
by zentara (Cardinal) on Aug 21, 2014 at 18:42 UTC
    You are looking for the -browsecmd. With the HList, you usually have to devise a system of looping thru all possible selections. For a fully functional example of using the HList, ItemStyle with images, and looping thru entries, see ztkdb-sql where it's all done. A similar, but smaller version is at ztkdb.

    What you have to watch out for, is that HList keeps an internal counter of added entries, and you need to learn to reuse them by reconfiguring them with $hlist->selectionSet( 0 ), or whichever row you want to modify. This is important in paging. If you don't use selectionSet(), you risk the internal counter continually increasing and causing unwanted memory gains.

    Finally, carefully read thru the perldoc for Tk::HList, and see all it's methods, they are not easy to understand until you practice using them.

    #!/usr/bin/perl use Tk; use Tk::HList; use YAML; $top = new MainWindow; $hlist = $top->Scrolled("HList", -header => 1, -columns => 4, -scrollbars => 'osoe', -command => sub{print 1}, -width => 70, -selectbackground => 'SeaGreen3', -browsecmd => \&browseThis, )->pack(-expand => 1, -fill => 'both'); $hlist->header('create', 0, -text => 'From'); $hlist->header('create', 1, -text => 'Subject'); $hlist->header('create', 2, -text => 'Date'); $hlist->header('create', 3, -text => 'Size'); $hlist->add(0); $hlist->itemCreate(0, 0, -text => "eserte\@cs.tu-berlin.de"); $hlist->itemCreate(0, 1, -text => "Re: HList?"); $hlist->itemCreate(0, 2, -text => "1999-11-20"); $hlist->itemCreate(0, 3, -text => "1432"); $hlist->add(1); $hlist->itemCreate(1, 0, -text => "dummy\@foo.com"); $hlist->itemCreate(1, 1, -text => "Re: HList?"); $hlist->itemCreate(1, 2, -text => "1999-11-21"); $hlist->itemCreate(1, 3, -text => "2335"); MainLoop; sub browseThis{ for my $column (0..3){ print $hlist->itemCget( $hlist->selectionGet, $column, 'text' ) +, "\n"; } } =head1 my $listArrayRef = []; my @selectedindices = $hlist->info('selection'); foreach my $r (@selectedindices) { push @{$listArrayRef}, getRowArrayRef($hlist, $r); print Dump(@{$listArrayRef}),"\n"; } sub getRowArrayRef { my ($hlist, $r) = @_; my @row; foreach my $c (0 .. $hlist->cget(-columns) -1) { push @row, $hlist->itemCget($r, $c, '-text'); } return \@row; } } =cut

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh