Sorry missed off wxperl.

Hi Ryan,

Thanks for your advice.

The specific event I am interested in is tabbing out of a field to trigger 
validation (ie a table lookup), however, this uses wxEVT_KILL_FOCUS.
wxEVT_KILL_FOCUS only passes the id of the control that was clicked 
and event.  It is also triggered when you do alt-tab (in Windows) to
Skip to another application, which I'm not interested in.  So I've come up
With the following strategy:

1) Use 

use vars qw($gl_self_ptr);      # Declare global $self pointer
.
.
.

$gl_self_ptr = \$self;          #Set global $self pointer.

To se a global variable pointer to $self in the main OnInit routine.

2) Use wxEVT_KILL_FOCUS to pick up the "lose focus" event.

        my ($self, $event) = @_;
        if ($event->GetEventType() eq wxEVT_KILL_FOCUS){            #$Self
is the control on the form.
            if ($self->GetValue() eq ""){return};               #Ignore if
nothing in field
            $self=$$gl_self_ptr;                                #set Local
Self to global self.
        };

And ignore it if there is nothing in the field (eg alt tab or just an empty
field).

Otherwise set $self to the pointer to the main screen so that I can
Do cross validation etc.

What do you think?

But I haven't tried $Event->Skip(), so that might help too.

Regards

Steve



-----Original Message-----
From: Doubi [mailto:doubi...@googlemail.com] 
Sent: 10 August 2009 16:11
To: wxperl-users@perl.org
Cc: Steve Cookson
Subject: Re: Distinguishing between event types

Hi Steve,

Steve Cookson wrote:
> I'm comfortable now with how to identify which event called the 
> event-handler,
> but I'm still struggling to understand how to identify the variables 
> involved when
> $self is not passed as a parameter.
Previously you wrote:
> OK I'm making some progress. The event passes $self and $event
> to the subroutine.
So isn't self _always_ passed as a parameter to the subroutine? When is 
it not passed? Which 'involved variables' are you trying to identify there?

> But then I want to find out which control was clicked so I use 
> $self->GetId() and I get "-205".  What is this?
That looks to me very much like the ID of the widget (or the 'window' as 
the docs insist on referring to them) that was clicked. This seems 
usually to be the second arg passed in creating the few components I've 
used, 'parent' being the first.

Every widget ('window') in a program has a unique integer ID. Most of 
the time it's never important to find it out and refer to widgets by 
that ID, so the program can be left to assign a random ID itself. This 
is done by passing -1 for the ID argument in wxPerl - in wxWidgets you 
can use the identifier wxID_ANY, which I feel improves readability.

Anyhow, randomly / automatically assigned IDs are always negative and 
user-designated ones must always be positive. So could you solve your 
problem by giving 'proper' IDs to the widgets that need to call this 
search function and distinguish between them that way? That'd depend on 
$self always being available, as I was asking about above. For instance, 
if you $Event->Skip() for both the TextCtrl and the Button in order to 
have them use the \&OnClick or whatever event in their parent Frame, I 
don't know if $self retains the value of the original widget that 
received the event.

-- Ryan

Reply via email to