Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: data structure problem

by kcott (Abbot)
on Nov 08, 2012 at 06:36 UTC ( #1002824=note: print w/ replies, xml ) Need Help??


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


Comment on Re: data structure problem
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002824]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (21)
As of 2014-10-30 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls