Hi Ed,
I would not pay too much heed to my example at www.gigi.co.uk as it was really
just my way of getting around some problems I had at that time with closures.
You only need Wx::PostEvent for sending events between threads - and Thread.pod
that you have is best reference for that.
You only need Wx::PlEvent / PlCommandEvent if you want to create your own
custom events (use base qw( Wx::PlCommandEvent)
The way to raise a window's close event is to do:
$window->Close;
(and I'm not being 'smart' with that)
If you want to do this via the event loop, the simplest way I think is:
In window:
EVT_COMMAND( $self, -1, $ID_MY_EVENT, \&mysub );
sub mysub {
my ($self $event) = @_;
$self->Close;
}
Elsewhere
my $event = Wx::CommandEvent->new( $ID_MY_EVENT, -1 );
$mywindow->AddPendingEvent($event);
--------------------------------------
If you want to create custom events, I have some more up to date code in
Wx::Perl::ProcessStream on CPAN.
Hope this helps
Regards
Mark
Ed W wrote:
> Hi
>
> I am trying to send myself a CommandEvent type object based on the the
> samples here:
> http://www.gigi.co.uk/wxperl/pdk/perltrayexample.txt
> http://search.cpan.org/dist/Wx/lib/Wx/Thread.pod
>
> (However, ideally for neatness I would like to be able to send myself a
> non command event, specifically in this case I want to send a Close
> message to one of my windows. How would I achieve this?)
>
> What I have so far is a sub which does:
>
> my $canary = Wx::Window::FindWindowById($main::WX_ID_CANARY, undef);
> my $e = Wx::PlEvent->new( -1, $main::ID_MENU_FILE_EXIT );
> Wx::PostEvent( $canary, $e );
> Then in the canary window I have:
>
> EVT_COMMAND( $this, -1, $main::ID_MENU_FILE_EXIT, \&OnClose );
>
> But sub OnClose is never called? What am I doing wrong? "$canary" is
> definitely set ok because I can call $canary->OnClose() - (however, this
> causes a crash due to another problem)
>
> I also tried using Wx::PlCommandEvent and also WxCloseEvent, but neither
> seems to reach my destination window?
>
> FWIW: the reason I am doing this is that I am finding lots of problems
> getting wxPerl apps to exit cleanly from the TaskBar object. Calling
> TaskBar->Destroy() from within an event on the taskbar seems to be an
> automatic crash in the perl executable (under win32 at least). So if I
> want to exit my app from a popup menu in the systemtray then I think
> that I need to send myself a close event and do all the destruction in
> the main app rather than the taskbar object.
>
> Grateful for some pointers
>
> Ed W