On Tuesday, March 22, 2011 07:48:52 pm Mark Dootson wrote: > 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.
Hi Mark, Ok.... I guess. But it *has* a label. And I am able to attach a mouse event to that label on one platform but not on another. That is surprising to me. I feel I am going to keep running into problems of this ilk unless I can actually understand why certain things behave differently on the different platforms. This is mysterious and your suggestion avoids the mystery, rather than explaining it. Which is not necessarily a bad thing. Doing things differently is good if it gets the job done. Attaching the mouse event to the Wx::Panel is a good idea. It is somewhat different for the user, though. It requires training the user to acknowledge that the negative space is clickable. To my mind, my concept makes more sense because it uses the label of the StaticBox -- a bit of positive space -- as the place to click. Thanks for your prompt response! B > 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 -- Bruce Ravel ------------------------------------ bra...@bnl.gov National Institute of Standards and Technology Synchrotron Methods Group at NSLS --- Beamlines U7A, X24A, X23A2 Building 535A Upton NY, 11973 My homepage: http://xafs.org/BruceRavel EXAFS software: http://cars9.uchicago.edu/~ravel/software/exafs/