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;

In reply to wxperl subclassing Wx::VListBox by antmico

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.