Octavian Rasnita wrote:
Hi,
I try to close the aplication using the system tray but anything I do,
it doesn't seem to work.
I put the sample app I've made in this message below.
The problem is that when I click on the tray icon, instead of closing
the app, it pops up a perl interpreter error window.
If I use just
$self->Destroy;
in the event handler for that event, the application seems to be
closed, but the system tray icon remains, and the program doesn't
really close. In this case it doesn't give any error window.
If I use
$self->Close;
and in the EVT_CLOSE event handler I also destroy the tray icon, it
appear that error window.
I've searched on the internet for this error and I found a few
discussions, but I haven't seen any solution.
Am I doing something wrong? Or there is no solution of closing a
WxPerl app using Wx::TaskBarIcon?
Ah yes, the good old system tray issues. I've been fighting with that a
few years ago too.
I've been experimenting with that a lot and my best guess is that it
doesn't like the taskbaricon (object) being destroyed in it's own event
handler.
What I've done in my case is just use a Popup menu and exit from there.
Maybe that is a usable solution for you to.
I altered your code to a working sample using a right click popup menu
and attached it below.
On a curious side note: does your lack of indenting your code have
anything to do with you using a screenreader?
Or is this just a quick dirty hack.
I hope my example helps.
Cheers,
Huub
use strict;
use Wx;
package MyApp;
use base 'Wx::App';
sub OnInit {
my $self = shift;
my $frame = MyFrame->new();
$self->SetTopWindow($frame);
$frame->Show(1);
return 1;
}
1;
package MyFrame;
use Wx qw(:everything);
use Wx::Event qw(:everything);
use base 'Wx::Frame';
use constant ID_QUIT => Wx::NewId();
sub new {
my $class = shift;
my $self = $class->SUPER::new(undef, -1, "Test", wxDefaultPosition,
wxDefaultSize);
$self->{tbi} = Wx::TaskBarIcon->new();
$self->{tbi}->SetIcon(Wx::GetWxPerlIcon, "Test program");
# Create the TaskBarMenu
$self->{taskbarmenu} = Wx::Menu->new( "TaskBar Menu" );
$self->{taskbarmenu}->Append( ID_QUIT, "Exit" );
EVT_CLOSE($self, \&OnClose);
EVT_TASKBAR_RIGHT_DOWN( $self->{tbi}, sub {
my( $this, $event ) = @_;
$this->PopupMenu( $self->{taskbarmenu} );
});
EVT_MENU( $self->{tbi}, ID_QUIT, sub {
$self->OnClose();
} );
return $self;
}
sub OnClose {
my ($self, $event) = @_;
$self->{tbi}->Destroy;
$self->Destroy;
}
1;
package main;
MyApp->new->MainLoop;