I was asked to debug a production GUI perl/TK program (the developer was let go) that have no documentation and no knowledge transfer. I did some basic perl programming, but not with TK. The user had claimed that the code worked before (a few days ago) and stopped working around yesterday. The code hadn't been touched since 11/2017 and the Perl executable also didn't seem to be touch. I will tried to verify that the Tk lib also hadn't been touched. Basically, the symptom/problem is that even though the rows are "selected/highlighted" on the GUI, when the user clicked on the "Get Files" button to act on the selection, nothing happened because it didn't see the selected rows! Here are the snippets from the code (I had inserted additional comments using ### in the code)...
$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

In reply to Retrieving selections from Tk:TableMatrix by chungley2000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.