For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > January 2005 > passing $var from one dialog to another...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author passing $var from one dialog to another...
joe.cipale@radisys.com

2005-01-18, 9:00 pm

I have a dialog box in which a user is required to specify a
device type from a list (switch, CPU, Disk, None). Once they select
a device type, they click 'Next' and are then taken to the next dialog
in the scheme. The problem I am encountering, is that the value they
select MUST be passed to the next dialog box.
Sub routine code displayed below:
sub blade_wizard {

#--------------------------------------------------------------#
# Dialog/Frame creation for window layout.

my $pu = MainWindow->new;
my $db = $pu->DialogBox(-title => "Blade Diagnostic WIzard");
$db->focus();
my $frame1 = $pu->Frame(-borderwidth => 2);
my $frame2 = $pu->Frame(-borderwidth => 2,
-relief => 'groove',
-width => 200);
my $frame3 = $pu->Frame(-borderwidth => 2);

#--------------------------------------------------------------#
$frame1->Button(-text => 'Next',
### <- This is where I print out the vlaue of the choosen
### <- device type. (Simply a debug stmt for now). The
### <- value $dev_type fails to print out here.
-command => sub { print "Device type is now: $dev_type\n";
choose_slt($dev_type) },
### <- Destroy the previous window AFTER I pass the data
### <- to the next dialog box
-command => sub { $pu->destroy if Tk::Exists($pu) })->pack(
-side => 'left',
-anchor => 'w');

$frame1->Button(-text => 'Cancel',
-command => sub { print "Cancel wizard...\n"},
-command => sub { $pu->destroy if Tk::Exists($pu) })->pack(
-side => 'left',
-anchor => 'w');

#--------------------------------------------------------------#
# Create Device Type field (choices based on type identified by slot
values passed to function).

print "$type\n";

$frame2->Label(-text => "Device type: ")->pack(-side => 'left',
-anchor => 's',
-expand => 1);
$frame2->Optionmenu(-variable => \$dev_type,
-options => [split ' ', $type],
### <- Value $dev_type prints out correctly here...
-command => [sub { print "Device type is $dev_type\n"
}])->pack(-side => 'bottom',
-expand => 1,
-ipadx => 3);

#--------------------------------------------------------------#
$frame3->Label(-text => "Blade Diagnostic Wizard")->pack;

$frame3->pack;
$frame2->pack;
$frame1->pack;
}

I keep thinking this isn't supposed to be this... difficult. :^)
Thanks in advance,

Joe

joe.cipale@radisys.com

2005-01-18, 9:00 pm

never mind... it looks like there are some funny things going on with
-command argument order. For example, replace this stmt:
-command => sub { print "Device type is now: $dev_type\n";
choose_slt($dev_type) },
with this stmt:
-command => sub {choose_slt($dev_type);
print "Device type is now: $dev_type\n"; },

And everything works as expected... Now, in trying to understand this,
can someone explain why this operates this way?

Thx,

Joe

zentara

2005-01-20, 3:59 pm

On 18 Jan 2005 11:24:43 -0800, "joe.cipale@radisys.com"
<joe.cipale@radisys.com> wrote:

>never mind... it looks like there are some funny things going on with
>-command argument order. For example, replace this stmt:
>-command => sub { print "Device type is now: $dev_type\n";
>choose_slt($dev_type) },
>with this stmt:
>-command => sub {choose_slt($dev_type);
>print "Device type is now: $dev_type\n"; },
>
>And everything works as expected... Now, in trying to understand this,
>can someone explain why this operates this way?
>
>Thx,
>
>Joe


Either this is a trick question, or it's obvious.
It looks like the "choose_slt($dev_type)" subroutine sets what the
global variable $dev_type is.

So the second example sets it before printing it, whereas the first
tries to print it before setting it.

If you have enabled
use warnings;
use strict;

then you probably would get an error message about an
"undefined variable in print statement" when you try the first one.






--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com