Hello,
I'm just starting to use Win32::GUI and I can't seem to explain the behavior of
my application.
I have a main perl program that occasionally needs user input. On those
occasions I call a function (sub) that builds the window and starts the dialog,
and returns a result gathered from the user input.
The first time this function is called, it works as expected. The user clicks a
button, the button callback sets a value, and terminates the Dialog(). The
value that was set is the return value of the function.
However, on the second and following times that the function is called, the
window is shown, via printouts I can see the return value being set, but when
the dialog exits and the function is about to return its return value, the
return value is the default one, in stead of the set one. I assume that it has
to do something with me, coding the event handlers inside the function that
does all the gui stuff. If that is so, can someone explain this behavior? I
don;t mind changing my code, but then I want to understand why it behaves like
this.
The code is pasted below. The behavior I want is that the user clicks on the
pass button which returns 1 to the calling function. If you press 'passed' in
every test, then you'll see the return value is 0 starting from the second call
to the 'verify' function.
use Win32::GUI();
my $canvas_height = 328;
my $title_height = 32;
my $margin = 15;
for ($i=0; $i<5;$i++){
my $output = "test $i";
print "$output ";
my $result_1 = verify($output);
print $result_1;
print " $output\r\n";
}
sub verify {
my $output = shift;
my $result = 0;
my $main =
Win32::GUI::DialogBox->new(
-name => 'Main',
-width => 280,
-height => $canvas_height+$title_height,
-text => 'Test Step Output Verification',
-helpbox => 0,
);
my $outputfield = $main->AddTextfield(
-name => 'Outputfield',
-multiline => 1,
-hscroll => 1,
-vscroll => 1,
-width => 215,
-height => 200,
-pos => [ $margin, 60],
-disabled => 0,
-readonly => 1,
);
my $pass = $main->AddButton(
-text => 'Passed',
-width => 100,
-height => 25,
-pos => [$outputfield->Left(),
$outputfield->Height() + $outputfield->Top() + $margin],
-name => 'Pass',
-tabstop => 1
);
my $fail = $main->AddButton(
-text => 'Failed',
-width => 100,
-height => 25,
-pos => [$outputfield->Left() + $outputfield->Width() - 100,
$pass->Top()],
-name => 'Fail',
-tabstop => 1
);
sub Pass_Click {
$result = 1;
$outputfield->Text("result : $result");
-1;
}
sub Fail_Click {
$result = 0;
$outputfield->Text("result : $result");
-1;
}
sub Main_Terminate {
-1;
}
$outputfield->Text($output);
$main->Show();
Win32::GUI::Dialog();
return $result;
}
Thanks for any hints,
luksedj
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html