in reply to data structure problem
G'day perltux,
I was thinking of a hash before I'd even read as far as %hash=(preset=>\@preset, ....
Here's a bare-bones (but working) solution that doesn't use the -choices option. First, a few notes:
- The -browsecmd callback is passed the widget as the first argument. As I haven't needed that, you'll see undef in a few places. You may need to change that.
- I made some decisions about display defaults: you may want to make changes here also.
- As I was uncertain what some of the terms you used referred to, my choices for variable names may be less than meaningful.
Here's the code:
#!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my %choices = ( preset => [ qw{tom snare metal analog} ], card1 => [ qw{mellowstr brightstr string3} ], ram => [ qw{acoustic rock bass jazz strato distorted} ], ); my @list_order = qw{preset card1 ram}; my ($current_list, $current_choice); my $mw = MainWindow->new(); my $be_F = $mw->Frame()->pack(); my $ex_F = $mw->Frame()->pack(); my $list_BE = $be_F->BrowseEntry( -variable => \$current_list, -browsecmd => \&update_choices, )->pack(-side => 'left'); my $vary_BE = $be_F->BrowseEntry( -variable => \$current_choice, -browsecmd => \&make_choice, )->pack(-side => 'left'); for (@list_order) { $list_BE->insert(end => $_); } update_choices(undef, $list_order[0]); $ex_F->Button(-text => 'Exit', -command => sub { exit })->pack(); MainLoop; sub update_choices { my (undef, $list) = @_; $current_list = $list; $current_choice = $choices{$list}[0]; $vary_BE->delete(0 => 'end'); for (@{$choices{$list}}) { $vary_BE->insert(end => $_); } return; } sub make_choice { my (undef, $choice) = @_; $current_choice = $choice; return; }
-- Ken
In Section
Seekers of Perl Wisdom