http://qs1969.pair.com?node_id=352377

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

Friends (and strangers :) ),
I'm trying my hand at writing a perl-tk app, mostly for the shere fun of learning it, but have hit a stumbling block that I could use some advise on. My app is pulling in data that I'd like to display in a column/row format, allowing the user to simply double click the row they want to launch a new window that does some more fancy work/processing. I like the way Tk::HList looks, and have kludged it to do the job I want, but I'm wondering if there's a better way, or if I'm perhaps not using it correctly (I've read the pods, I've abused the widgets demo where applicable, and I don't have the resources to purchase "Mastering Tk" atm).

Right now, I have a code block like:

my $hlist = $mw->Scrolled(qw/HList -columns 3 -width 70 -command main::launch_win/)->pack(qw/-expand yes -fill both/);
which works, albeit in an ugly fashion. Through newbie experimentation I see that it passes the $entryID to my sub, and I've cobbled together what I believe to be a bad hack that associates the $entryID to a key in a hash, from which I can pull the relevant pieces of data to determine which row was hit and move forward. But is there a better way? The ideal would be to double click a row and pass it a specific piece of data rather than relying on the $entryID pass - am I doing this wrong? For those that wonder, I've tried using $hlist->configure(-command => mysub($whatiwant)), but this resulted in the desired command being run immediately for every row returned (not desirable when the number of rows can be between 1 and a really really large number).

I confess that my thinking is a little too linear at times, so I don't immediately grok how to declare the command prior to having the (randomly) generated data available. Is there perhaps a better way to give the display I want with the functionality I need than by using Tk::HList?

Thank you all in advance for your time and thoughts.

z3d



"I have never written bad code. There are merely unanticipated features."