Hi Amblikai,
Here's how you could create a data structure defining regions to reveal/hide when the corresponding RadioButton is pressed.
First, assign variables to your RadioButtons. For example:
my $rb1 = $frame->Radiobutton(
-variable=>\$output_select,
-value=>'netlist',
-text=>'Generate Netlist',
) ->pack(-side=>'left');
my $rb2 = $frame->Radiobutton(
-variable=>\$output_select,
-value=>'template',
-text=>'Generate Template',
) ->pack(-side=>'right');
Later in the program, after you've defined ALL the widgets which you want to hide/reveal (but before the
MainLoop), create your data structure:
# Data structure to control 'hideable' regions
#
# Each key is a valid RadioButton. Each value is a list of widgets
# to REVEAL when that RadioButton is clicked, at which time all other
# widgets ((in other Array Refs) will be hidden.
##
my $a_reveal = [
[ $rb1 => [ $netlist_args_frame, $import_args_frame, $options_fram
+e ] ],
[ $rb2 => [ $template_args_frame ] ],
];
assign_hideable_widgets($a_reveal);
Finally, in your subroutine section, create the subroutine which sets up the callbacks for each RadioButton, to hide or reveal the specific widgets (in this case, they're all
LabFrames):
sub assign_hideable_widgets {
my ($a_reveal) = @_;
# Return if no hideable regions defined
@$a_reveal or return;
# Save all hideable regions
my $a_all = [ ]; # List of all widgets
my $h_seen = { }; # Hash all widgets seen
my $h_reveal = { }; # Maps RadioButton to widgets to reveal
my $h_packinfo = { }; # Saves each widget's pack information
# Create closure to hide/reveal desired regions
my $c_hide = sub {
my ($rb) = @_;
# First, unpack everything
map { $_->packForget } @$a_all;
# Next, pack selected widgets for this RadioButton
my $a_reveal = $h_reveal->{$rb};
foreach my $w (@$a_reveal) {
my $a_pack = $h_packinfo->{$w};
$w->pack(@$a_pack);
}
};
# Iterate each RadioButton and the widget(s) it reveals
foreach my $a_item (@$a_reveal) {
my ($rb, $a_reveal) = @$a_item;
$h_reveal->{$rb} = $a_reveal;
# Save all widgets and their pack info
foreach my $w (@$a_reveal) {
$h_seen->{$w}++ or push @$a_all, $w;
$h_packinfo->{$w} = [ $w->packInfo ];
}
$rb->bind("<Button-1>" => sub { $c_hide->($rb) });
}
}
say
substr+lc crypt(qw $i3 SI$),4,5
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.