home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _3a64f166aa1a157036473f11cfb7d816 < prev    next >
Text File  |  2004-06-01  |  2KB  |  75 lines

  1. # labelframe.pl
  2.  
  3. use vars qw/$TOP/;
  4.  
  5. sub labelframe {
  6.  
  7.     # Create a top-level window that displays several Labelframe widgets.
  8.  
  9.     my($demo) = @_;
  10.     $TOP = $MW->WidgetDemo(
  11.         -geometry_manager => 'grid',
  12.         -name             => $demo,
  13.         -text             => 'Labelframes are used to group related widgets together. The label maybe either plain text or another widget.',
  14.         -title            => 'Labelframe Demonstration',
  15.         -iconname         => 'labelframe',
  16.     );
  17.  
  18.     # A group of radiobuttons in a labelframe
  19.  
  20.     my $lf1 = $TOP->Labelframe(qw/-text Value -padx 2 -pady 2/);
  21.     $lf1->grid(qw/-row 0 -column 0 -pady 2m -padx 2m/);
  22.  
  23.     my $lfdummy;
  24.     foreach my $value (1 .. 4) {
  25.     $lf1->Radiobutton(
  26.             -text     => "This is value $value" ,
  27.             -variable => \$lfdummy,
  28.             -value    => $value,
  29.         )->pack(qw/-side top -fill x -pady 2/);
  30.     }
  31.  
  32.     # A label window controlling a group of options.
  33.  
  34.     my $lf2 = $TOP->Labelframe(qw/-pady 2 -padx 2/);
  35.     $lf2->grid(qw/-row 0 -column 1 -pady 2m -padx 2m/);
  36.     my $lfdummy2;
  37.     my $cb;
  38.     $cb = $lf2->Checkbutton(
  39.         -text     => 'Use this option',
  40.         -variable =>  \$lfdummy2,
  41.         -command  => sub {&labelframe_buttons($lf2, $cb, \$lfdummy2)},
  42.         -padx     => 0,
  43.     );
  44.     $lf2->configure(-labelwidget => $cb);
  45.  
  46.     foreach my $str (qw/Option1 Option2 Option3/) {
  47.     $lf2->Checkbutton(-text => $str)->pack(qw/-side top -fill x -pady 2/);
  48.     }
  49.  
  50.     &labelframe_buttons($lf2, $cb, \$lfdummy2);
  51.  
  52.     $TOP->gridColumnconfigure([0, 1], -weight => 1);
  53.  
  54. } # end labelframe
  55.  
  56. sub  labelframe_buttons {
  57.  
  58.     # The state of the sub-Checkbuttons is dependent upon the state of
  59.     # the master -labelwidget Checkbutton.
  60.  
  61.     my ($lf, $cb, $var_ref) = @_;
  62.  
  63.     foreach my $child ($lf->children) {
  64.         next if $child == $cb;
  65.         if ($$var_ref) {
  66.             $child->configure(qw/-state normal/);
  67.         } else {
  68.             $child->configure(qw/-state disabled/);
  69.         }
  70.     }
  71.  
  72. } # end labelframe_buttons
  73.  
  74. 1;
  75.