On Fri, Jan 02, 2004 at 02:57:38PM +0000, James Brown wrote:
> Thank you for the advice Rocco, I've done what you suggested and
> 'hidden' the blessed postback in an unblessed one.
>
> The one thing I'm still not sure about is do you how I can access the
> keysym information once the "ev_key" event has fired? I have tried using
> $_[ARG0] and $_[ARG1], but without success.
>
> An idea I had was to put Ev('K') in the callback (as in 1. below) but I
> couldn't get it to work with postback() because the entire callback
> needed to be surrounded with [] (according to
> http://search.cpan.org/~ni-s/Tk-804.025_beta13/pod/callbacks.pod).
[...]
> sub ui_keypress {
>
> my ($c) = $_[ARG1];
> my $event_obj = $c->XEvent; #Get Event Object - line 82
> my $keysym= $event_obj->K;
> print "The $keysym key was pressed\n";
>
> }
>
> The above script (2.) gives me this error on pressing a key:
>
> Tk::Error: Can't call method "XEvent" on unblessed reference at lingo.pl
> line 82.
> Tk::After::once at D:/perl/site/lib/Tk/After.pm line 83
> [once,[{},after#62,0,once,[\&POE::Kernel::_loop_event_callback]]]
> ("after" script)
The unblessed reference is an ARRAY reference. You can verify it by
adding
warn $c;
just after you create $c. Then it's an easy matter of checking what's
inside it with
warn "@$c";
which would show you what you need to know.
Now, a mini tutorial on postbacks:
There are two times where postbacks are "called". The first is when the
postback is created
my $postback = $ssesion->postback("event", "a", "b", "c");
and the second is when it's used
$postback->(1, 2, 3);
Therefore there are two sets of parameters a postback can return: The
ones given to it at creation time, and the ones it's called with at
runtime.
The creation-time information is useful for reminding you what the
postback is attached to. They're a form of magic cookie. The
creation-time information is passed back as a list reference in ARG0.
In the context of the previous example
my @cookies = @{$_[ARG0]};
print "@cookies\n";
would print "a b c".
The runtime information lets you know what the other system (Tk in this
case) wanted to call you back with. The runtime callback parameters are
also passed in a list reference, in ARG1.
my @returns = @{$_[ARG1]};
print "@returns\n";
would print "1 2 3".
Therefore, the parameter you're looking for is
my $c = $_[ARG1]->[0];
which turns out to be a Tk::MainWindow object.
--
Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/