Hi,
Don't treat a Wx::StaticBox like a window. Just regard the construct
my $boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel, -1,
'Blah blah'), wxVERTICAL );
as creating a sizer with a label.
If you want to catch events from a 'Container', the simplest case is to
use a Wx::Panel.
#!/usr/bin/perl
package MyApp;
use base 'Wx::App';
use Wx qw(:everything);
use Wx::Event qw(EVT_RIGHT_DOWN);
sub OnInit {
my $frame = Wx::Frame -> new(undef, -1, 'demo', [-1,-1], [250,150]);
my $panel = Wx::Panel->new($frame, -1, [-1,-1], [-1,-1],
wxTAB_TRAVERSAL|wxBORDER_NONE);
my $st = Wx::StaticText -> new($panel, -1, "This is some text");
EVT_RIGHT_DOWN($st, sub{print "I clicked the Text!\n"});
EVT_RIGHT_DOWN($panel, sub{print "I clicked the Box!\n"});
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
my $boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel,
-1, 'Blah blah'), wxVERTICAL );
$boxsizer -> Add($st, 0, wxEXPAND|wxALL, 10);
$panel->SetSizer($boxsizer);
$sizer -> Add($panel, 1, wxALL|wxEXPAND, 0);
$frame -> SetSizer($sizer);
$frame -> Show(1);
1;
};
package main;
use Wx qw(:everything);
my $app = MyApp->new->MainLoop;
On 22/03/2011 22:25, Bruce Ravel wrote:
Hi,
I want to start by thanking Mattia for his very helpful answer to my
previous question.
I continue to be confused by the behavior of wxperl on Windows
compared to linux. In this case, I am surprised by the behavior of an
event bound to a right mouse click.
In this script, I have a StaticText inside of a StaticBox. I want to
bind an action to a right click on both static items.
#!/usr/bin/perl
package MyApp;
use base 'Wx::App';
use Wx qw(:everything);
use Wx::Event qw(EVT_RIGHT_DOWN);
sub OnInit {
my $frame = Wx::Frame -> new(undef, -1, 'demo', [-1,-1], [250,150]);
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
my $box = Wx::StaticBox->new($frame, -1, 'Blah blah');
my $boxsizer = Wx::StaticBoxSizer->new( $box, wxVERTICAL );
$sizer -> Add($boxsizer, 1, wxALL, 5);
my $st = Wx::StaticText -> new($frame, -1, "This is some text");
$boxsizer -> Add($st, 1, wxGROW|wxALL, 10);
EVT_RIGHT_DOWN($st, sub{print "I clicked the Text!\n"});
EVT_RIGHT_DOWN($box, sub{print "I clicked the Box!\n"});
$frame -> SetSizerAndFit($sizer);
$frame -> Show(1);
1;
};
package main;
use Wx qw(:everything);
my $app = MyApp->new->MainLoop;
On linux, the text gets printed to STDOUT when clicking on either one.
On Windows, the event for right-clicking on the StaticText happens,
but the one of right-clicking on the StaticBox does not.
Is there a reason for this? Is there something I can do to make sure
that the event gets issued for the StaticBox?
Thanks a mmillion,
B