deesler has asked for the wisdom of the Perl Monks concerning the following question:

I am using the Tk::TableMatrix class, which I have set up to select an entire row at a time. Now, I want to retrieve (or figure out) the row number which is selected. I know that it is staring me in the face from the man page, but I can't see it. Can anyone point me to how I retrieve the selection from the TableMatrix ? Thanks in advance
  • Comment on I can't find my reading glasses, yes, that's it.

Replies are listed 'Best First'.
Re: I can't find my reading glasses, yes, that's it.
by zentara (Cardinal) on Feb 27, 2009 at 21:08 UTC
    deesler you're a dork...:-)

    #!/usr/bin/perl use strict; use Tk; use Tk::TableMatrix; my $mw = MainWindow->new(); my $tm = $mw->TableMatrix( -state => 'disabled', -browsecommand => \&brscmd, )->pack(); MainLoop; sub brscmd { my ($previous_index, $actual_index) = @_; my ($row, $col) = split ',', $actual_index; print "r$row c$col\n"; }

    I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
Re: I can't find my reading glasses, yes, that's it.
by ig (Vicar) on Feb 28, 2009 at 01:20 UTC

    From Tk::TableMatrix

    $table->curselection(?value?)

    With no arguments, it returns the sorted indices of the currently selected cells. Otherwise it sets all the selected cells to the given value. The set has no effect if there is no associated Tcl array or the state is disabled.

Re: I can't find my reading glasses, yes, that's it.
by deesler (Novice) on Feb 27, 2009 at 22:25 UTC
    I thought of using "-browsecmd". I had already bound a callback to <Double-Button-1>, i.e. if the user double-clicks on a row, go do something.

    I just checked, and Perl/Tk does chain the callbacks in the right order, i.e. the browsecommand callback gets called before the double click callback, so I can cache the row, and retrieve it in the second callback to use it. I was just wondering if there is a way to directly access the active row(cell), without relying on the use of the browse command? That way, I would just retrieve it in my double-click callback, and be on my way.

    This will certainly work (Thanks), it just would be nice to be able to retrieve the selected row/cell whenever you wanted it, without having to update your stored value whenever the user clicks in the TableMatrix.
      Here's a better example. There is also another technique, where you can get the "closet cell" to the x,y value of the mouse position, then you can do a "hover over" selection bound to mouse motion.

      I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
Re: I can't find my reading glasses, yes, that's it.
by shmem (Chancellor) on Feb 27, 2009 at 20:49 UTC

    Re title: bootstrap problem. Get your glasses to find them. ;-)

    *scnr*