From 952ef9405e3139e3986d6f5da80729dda66df0ce Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Mon, 4 Aug 2008 19:19:54 -0400 Subject: [PATCH] Reducing the buttons in tkplotdataset code with a loop --- examples/tkplotdataset | 86 +++++++++++--------------------------------------- 1 file changed, 19 insertions(+), 67 deletions(-) diff --git a/examples/tkplotdataset b/examples/tkplotdataset index b115ce4..7baa825 100755 --- a/examples/tkplotdataset +++ b/examples/tkplotdataset @@ -7,74 +7,27 @@ use strict; my ( %sets, $graph ); my $window = MainWindow->new( -title => 'Math::GSL Plot', ); - -my $del_J0; -$window->Button( - -text => "gsl_sf_bessel_J0", - -command => sub { - ®ion("gsl_sf_bessel_J0"); - $del_J0->configure( -state => "normal" ); - } -)->pack; -$del_J0 = $window->Button( - -text => "Remove gsl_sf_bessel_J0", - -state => "disabled", - -command => sub { - delete_set("gsl_sf_bessel_J0"); - $del_J0->configure( -state => "disabled" ); - } -)->pack; - -my $del_J1; -$window->Button( - -text => "gsl_sf_bessel_J1", - -command => sub { - region("gsl_sf_bessel_J1"); - $del_J1->configure( -state => "normal" ); - } -)->pack; -$del_J1 = $window->Button( - -text => "Remove gsl_sf_bessel_J1", - -state => "disabled", - -command => sub { - delete_set("gsl_sf_bessel_J1"); - $del_J1->configure( -state => "disabled" ); - } -)->pack; - -my $del_Y0; -$window->Button( - -text => "gsl_sf_bessel_Y0", - -command => sub { - region("gsl_sf_bessel_Y0"); - $del_Y0->configure( -state => "normal" ); - } -)->pack; -$del_Y0 = $window->Button( - -text => "Remove gsl_sf_bessel_Y0", - -state => "disabled", - -command => sub { - delete_set("gsl_sf_bessel_Y0"); - $del_Y0->configure( -state => "disabled" ); +my @popo = ("gsl_sf_bessel_J0", "gsl_sf_bessel_J1", "gsl_sf_bessel_Y0", "gsl_sf_bessel_Y1"); + +for my $n (0..3) { + my $del; + $window->Button( + -text => $popo[$n], + -command => sub { + region($popo[$n]); + $del->configure( -state => "normal" ); } -)->pack; - -my $del_Y1; -$window->Button( - -text => "gsl_sf_bessel_Y1", - -command => sub { - region("gsl_sf_bessel_Y1"); - $del_Y1->configure( -state => "normal" ); + )->pack; + $del = $window->Button( + -text => "Remove " . $popo[$n], + -state => "disabled", + -command => sub { + delete_set($popo[$n]); + $del->configure( -state => "disabled" ); + } + )->pack; } -)->pack; -$del_Y1 = $window->Button( - -text => "Remove gsl_sf_bessel_Y1", - -state => "disabled", - -command => sub { - delete_set("gsl_sf_bessel_Y1"); - $del_Y1->configure( -state => "disabled" ); - } -)->pack; + $window->Button( -text => "test", -command => [ \®ion, "test", $window ] ) ->pack; @@ -98,7 +51,6 @@ sub region { @data1 = map { $functions{$name}->($_) } (@region2); } else { - @data1; @data1 = map { $functions{$name}->($_) } (@region); } -- 2.11.4.GIT