antmico has asked for the wisdom of the Perl Monks concerning the following question:
I'm a Perl novice and I'm trying to develop my skills by building a small GUI application using wxperl. Although this question does relate to wxperl, I suspect it is equally a fundamental OO question.
I'd like to make use of the wxVListBox control and to do so I understand that I must derive from it a subclass, however this has left me with a couple of questions.
Firstly, the demo code appears to derive from a class called Wx::PlVListBox rather than Wx::VListBox, so I'm not sure which of the two I should be using? I've experimented with both and if I base my subclass on Wx:VListBox the OnDrawItem method doesn't seem to get called.
If I base my subclass on Wx::PlVListBox, the control appears to work as expected but I'm not sure how I go about adding additional attributes given I have no knowledge of how the underlying object is stored? Many thanks for any assistance.
My test code:
#!/usr/bin/perl use strict; use warnings; package MyFrame; use Wx; use base qw(Wx::Frame); sub new { my $class = shift; my $self = $class->SUPER::new( undef, # parent window -1, # ID -1 means any 'wxPerl rules', # title [-1, -1], # default position [100, 200], # size ); my $panel = Wx::Panel->new( $self, # parent window -1, # ID ); my $vlistbox = MyWxVListBox->new( $self, -1, [-1, -1], [100, 200] +); return $self; } package MyApp; use base qw(Wx::App); sub OnInit { my $class = shift; my $frame = MyFrame->new(); $frame->Show( 1 ); } package MyWxVListBox; use base qw(Wx::PlVListBox); use Wx; sub new { my( $class, @args ) = @_; my $self = $class->SUPER::new( @args ); $self->SetItemCount( 10 ); return $self; } sub OnDrawItem { my( $self, $dc, $rect, $item ) = @_; print "Drawing item\n"; $dc->DrawText( $item, $rect->x + 1, $rect->y + 1); } sub OnMeasureItem { my( $self, $item ) = @_; return 20; } package main; my $app = MyApp->new(); $app->MainLoop;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: wxperl subclassing Wx::VListBox
by Anonymous Monk on Feb 12, 2011 at 12:18 UTC | |
by antmico (Novice) on Feb 12, 2011 at 13:11 UTC | |
|
Re: wxperl subclassing Wx::VListBox
by Anonymous Monk on Feb 12, 2011 at 01:57 UTC | |
by antmico (Novice) on Feb 12, 2011 at 10:00 UTC |