I'm still having difficulty in understanding three lines of the code:
1. $w->selectionIncludes( '@' . $Ev->x . "," . $Ev->y )
2. $w->selectionSet( '@' . $Ev->x . "," . $Ev->y )
3. my ($rc) = @{ $w->curselection };
Sometimes its just better to accept some things as internal magic. :-)
What I believe what is happening is that since it is in the sub for Motion, it is resetting the Ev at a low level so that the eventloop always picks up the change.
Just regard it as low-level manipulation of the widget, which is rarely seen up at the Perl programmers vantage point.
Have you tried commenting them out to see what effect each line has? Maybe perl/tk HLIST selections options will shed some light.
| [reply] [d/l] |
Hello Zentara,
Thank you for the quick response. Yes it is true that working with an abstract understanding helps many times. Therefore I have no problems accepting some things as internal magic so long as I understand what values and in what format I need to pass when calling these subroutines. For example, in the earlier mentioned thread: http://perlmonks.com/?node_id=840707 (i) what values and in what format I pass to select a column and be able to retrieve the column number that was selected (ii) similarly how to select an individual cell and retrieve the row,col of that cell.
But without even knowing what values and in what format to pass, I'm having difficulty even for abstract understanding at the programmer level. Yes, I did earlier try commenting out each of these three calls but the program fails to work. I'm taking a look at the HList selection example thread you mentioned. I hope it helps.
Meanwhile if somebody can tell me what values (and format) I need to pass to these three subroutines to get column selection, individual cell selection etc., it will be whole lot useful. Also, what does the @{...} syntax do ?? (the one used while calling curselection sub)
Thanks again
| [reply] |
Also, what does the @{...} syntax do
Besides confuse you? heh heh . Seriously, I'm not the expert on it, but it is an array dereference. The part in brackets {..} represent an hashref ( a hash reference), which is how stuff is stored in an object. The @ part tells it that the hashref is an array, and needs an array to put it in for display. Google for Perl Dereferencing for alot of tutorials and explanations.
As to your other question, how to get the n'th column from any row selected in the HList widget, this recently posted script shows the way.
#!/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
| [reply] [d/l] |