Moore, Paul wrote:
>Attached is my second Win32::GUI script (and my first go at events)...
>
>There are two things I don't feel I've got right. First, in the Resize
>event code, I am referring to the global variable $main directly. Is
>there a way to get at "the window/control to which this event applies"
>*without* needing to know global variable names, etc. Longer terms, I'm
>thinking of things like
> *{"${name}_Resize"} = sub {...}
>to assign generic code to events.
I'm thinking about it...
maybe a $self variable should always be passed as the first argument
to the event, or maybe an option should be added to the Window creation,
something like: -events => VB_LIKE or -events => TK_LIKE ...
don't know ;-)
BTW, something similar is possible, and I've actually used it, using
Perl's own eval(), eg:
sub DefineEvent {
my($name) = @_;
my $evt = qq(
sub ${name}_Resize {
print \$${name}->Width();
}
}
eval $evt;
return $@ ? 0 : 1;
}
DefineEvent("main");
(presuming the -name option and the variable name are the same...)
>Second, the given code flickers dreadfully. Presumably because I am
>resizing the window in the resize event. Can this flicker be avoided?
there's a workaround, at least.
$main = new Win32::GUI::Window(
-name =>"Main",
-width => 250,
-height => 250,
-maxsize => [ 500, 500 ],
);
so you don't need to resize the window in the Resize event.
>Thanks for the help. I *will* write up my experiences.
and we *will* all thank you a lot ;-)
>PS A nasty gotcha I hit was new Win32::GUI::Window(-name => "Main"
>-width => 250, -height => 250) [note the lack of comma between "Main"
>and -width]. This goes horribly wrong, because Perl sees string minus
>bareword, and accepts it, followed by the wrong number of remaining
>parameters.
yup. we should definitely warn() if the remaining number of parameters
is odd (like perl does with "Odd number of elements in hash assignment").
bye, Paul, and thank you for all your nice reports ;-)
__END__
# Aldo Calpini
print sort {$_{$a} cmp $_{$b}} values %{{split undef,
"xritajbugne fahokem csuctawer jhdtlrnpqloevkshpr"}};