chungley2000 has asked for the wisdom of the Perl Monks concerning the following question:
$mw1 = new MainWindow; $mw1 -> title("CMVC File Retriever"); #----------------------------------------------------------------- # Set up two frames: # - $frameTop - contains radio buttons for selecting table. # - $frameBottom - contains button to quit without update. #----------------------------------------------------------------- $frameTop = $mw1 -> Frame(-label => "QUERY Table (Last update as +of $update)", -relief => 'groove', -borderwidth => 1)->pack(-side => +'top', -fill => 'both'); $table = "fileview" ; # default table (turns radio button on) $frameTop -> Radiobutton(-text => "file table", -value => "fi +leview", -variable => \$table)->pack(-side => 'left'); ### Skipping some of the lines... $frameBottom -> Button( -bg => 'green', -text => "Get Files", -a +nchor => 'center', -command => \&getSelection) -> pack ( -side => 'le +ft' ) if $table eq "fileview"; ### Skipping more of the lines... my $t = $frameTop -> Scrolled ( 'Spreadsheet', -rows => $rows, -cols => $cols, -width => 150, -height => 10, -titlerows => 1, -titlecols => 2, -rowtagcommand => \&rowSub, -coltagcommand => \&colSub, -selectmode => 'extended', -variable => $arrayVar, -selecttitle => 1, ); $t -> configure ( -browsecommand => sub { my ($index) = @_ ; $currentText = $index ; $activeText = $t -> get($index) ; } ); $t -> configure ( -validate => 1, -validatecommand => sub { my ( $row, $col, $old, $new, $index ) = + @_; $activeText = $new; return 1; } ); ### ### This here is interesting since I think getting selection ### should be easy. I would expect selectioncommand is meant ### to be used to "extend" the default behavior... But I don't ### see a real problem with this approach. ### $t -> configure ( -selectioncommand => sub { my ( $NumRows, $Numcols, $selectio +n, $noCells ) = @_; $results = $selection ; # assign re +sults to var to read later print "DEBUG: I am here at selecti +oncommand with results = $results,\n"; return $selection ; # NOT sure +where this is returned, so assign above } ); ### Skip again to where we are trying to "access" the ### selection's results: #----------------------------------------------------------------- # Subroutine to get the selected data and copy it to a user dir #----------------------------------------------------------------- sub getSelection { #-------------------------------------------------------------- +--- # Get selected item and parse into values. #-------------------------------------------------------------- +--- ### The program was meant to operate on this global $results, ### but it is empty... ### It seems that selectioncommand never got executed. ### What is even more weird for me is that out of the 15/20 ### different tests that I ran to try to debug this, "twice" ### (and I don't know how to replicate it), the ### selectioncommand executed some seconds AFTER. ### I tried explicitly declared $results as a global variable ### by adding "our $results;" before the use in this AND also ### in selectioncommand's subroutine. ### The other thing that I tried is do use $table->curselection +(), ### but I don't know how to use that properly; I tried ### $table->curselection() and $frameTop->curselection(), ### but they failed. print "get Selection results are , $results,\n" ; # TESTING print Dumper($results) ; # TESTING
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Retrieving selections from Tk:TableMatrix
by Aldebaran (Curate) on Oct 10, 2018 at 22:38 UTC | |
by Aldebaran (Curate) on Oct 10, 2018 at 22:40 UTC | |
|
Re: Retrieving selections from Tk:TableMatrix
by Marshall (Canon) on Oct 11, 2018 at 00:29 UTC | |
by chungley2000 (Initiate) on Oct 12, 2018 at 13:48 UTC | |
by Marshall (Canon) on Oct 12, 2018 at 20:04 UTC | |
by Aldebaran (Curate) on Oct 18, 2018 at 05:10 UTC | |
by chungley2000 (Initiate) on Oct 19, 2018 at 06:29 UTC |