Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Can a sublcass of Wx::StaticBoxSizer handle events in wxPerl?

by Anonymous Monk
on Jun 23, 2010 at 16:10 UTC ( #846110=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to create a subclass of Wx::StaticBoxSizer as a reusable object that will handle its own events, as shown:

package my_sizer; use base 'Wx::StaticBoxSizer'; use Wx qw(:sizer); use Wx::Event qw(EVT_BUTTON); sub new { my $ref = shift; my $parent = shift; my $self = $ref->SUPER::new( Wx::StaticBox->new($parent, -1, 'Box label'), wxHORIZONTAL ); my $button = Wx::Button->new($parent, -1, 'Button'); $self->Add($button); EVT_BUTTON($self, $button, \&click); $self->SetSizeHints($parent); return $self; } sub click { Wx::MessageBox('Click!'); }

But I am getting the following error:

Can't locate object method "Connect" via package "Wx::StaticBoxSizer" at C:/strawberry/perl/site/lib/Wx/Event.pm line 38.

Does this mean that Wx::StaticBoxSizer and subclasses can't handle events? If so, is there another way to restructure my object so that it can handle its own events?

Thank you, monks.

Comment on Can a sublcass of Wx::StaticBoxSizer handle events in wxPerl?
Select or Download Code
Re: Can a sublcass of Wx::StaticBoxSizer handle events in wxPerl?
by ikegami (Pope) on Jun 23, 2010 at 17:12 UTC
    Sizers control layout of a window's children. Windows have a screen presence and manage events. You needs to base your class on wxControl or wxPanel. I couldn't find the difference between the two in practical terms when I was faced with the same question.

      Thanks for the guidance. Unfortunately, I tried your suggestion and now my control isn't even displaying correctly. Any ideas?

      package my_control; use base 'Wx::Control'; use Wx qw(:sizer); use Wx::Event qw(EVT_BUTTON); sub new { my $ref = shift; my $parent = shift; my $self = $ref->SUPER::new($parent, -1); $self->{sizer} = Wx::StaticBoxSizer->new( Wx::StaticBox->new($parent, -1, 'Box label'), wxHORIZONTAL ); $self->{button} = Wx::Button->new($parent, -1, 'Button'); $self->{sizer}->Add($self->{button}); EVT_BUTTON($self, $self->{button}, \&click); $self->SetSizer($self->{sizer}); $self->{sizer}->SetSizeHints($self); $self->{sizer}->FitInside($self); return $self; } sub click { Wx::MessageBox('Click!'); }

      (If you can't tell, I'm new to both wxPerl and Perl objects.)

      Thanks again.

        I don't see any problems from a visual inspection of the code, although I'm not fluent in Wx. I don't have Wx installed here to see the result for myself. How do you display it? What's not correct with how it's being displayed?
Re: Can a sublcass of Wx::StaticBoxSizer handle events in wxPerl?
by TGI (Vicar) on Jun 23, 2010 at 21:28 UTC

    This post was cross-posted at StackOverflow. At the time of this writing, no worthwhile response had been made there.


    TGI says moo

Reaped: Re: Can a sublcass of Wx::StaticBoxSizer handle events in wxPerl?
by NodeReaper (Curate) on Jun 24, 2010 at 03:52 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://846110]
Approved by ikegami
Front-paged by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2015-07-04 15:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls