Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

wxPerl virtual list control not calling OnGetItemText?

by HelenCr (Monk)
on Mar 13, 2013 at 15:58 UTC ( #1023244=perlquestion: print w/ replies, xml ) Need Help??
HelenCr has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed PerlMonks: I hope you can help me with this problem:

I am trying to implement a (trivial) virtual list control demo. It should show a frame, and fill-in all fields with the word: "test".

When I run the program (listed below), it shows the frame and the title, including the scroll bar and the horizontal lines, but it seems that the virtual ListCtrl doesn't call OnGetItemText, so the fields do not get populated.

I'd be very thankful to you if you could help in finding where the error is.

My systems: Strawberry Perl 5.16.0 on Windows XP (same results with DWIM Perl 5.14.2 on Windows 7).

Many TIA - Helen

The program:

# wxPerl Virtual list control test use strict; use warnings; use warnings qw< FATAL utf8 >; use Wx; use Encode; use 5.014; use utf8; use autodie; use Carp; use Carp qw {cluck}; use Carp::Always; use Win32::Console; use English '-no_match_vars'; package MyForm; use strict; use warnings; use Wx qw[:everything]; use base 'Wx::Frame'; sub new { #1 my $class = shift; my $self = $class->SUPER::new( undef, # parent window -1, # ID -1 means any 'Phone book', # title [ 200, 200 ], # position [ 400, 500 ], # size ); # Add a panel my $panel = Wx::Panel->new( $self, # parent window -1, # ID ); $self->{list_ctrl} = Wx::ListCtrl->new( $panel, -1, # ID [ 20, 30 ], # position [ 350, 300 ], # size 32 | Wx::wxBORDER_SUNKEN | Wx::wxLC_VIRTUAL | Wx::wxLC_HRULES, + # window style ); $self->{list_ctrl}->InsertColumn( 0, 'Last Name' ); $self->{list_ctrl}->InsertColumn( 1, 'First Name' ); $self->{list_ctrl}->InsertColumn( 2, 'Addr City' ); $self->{list_ctrl}->InsertColumn( 3, 'Addr State' ); my $sizer = Wx::BoxSizer->new(wxVERTICAL); $sizer->Add( $self->{list_ctrl}, 0, wxALL | wxEXPAND, 5 ); $panel->SetSizer($sizer); $self->{list_ctrl}->SetItemCount(1000); return $self; } #1 end sub new sub OnGetItemText { #1 MyForm:: say 'Entered OnGetItemText'; my ($line, $column, $data_item); my ($self, $item, $col) = @_; $data_item = 'test'; return $data_item; } #1 end sub OnGetItemText MyForm:: # end package MyForm binmode(STDOUT, ":unix:utf8"); binmode $DB::OUT, ':unix:utf8' if $DB::OUT; # for the debugger my $app = Wx::SimpleApp->new; my $frame = MyForm->new; $frame->Show(1); $app->MainLoop;

Note: trying to cross-post here: http://old.nabble.com/wxPerl-virtual-list-control-not-calling-OnGetItemText--tt35170291.html

Comment on wxPerl virtual list control not calling OnGetItemText?
Download Code
Re: wxPerl virtual list control not calling OnGetItemText?
by jmlynesjr (Pilgrim) on Mar 14, 2013 at 02:10 UTC

    Helen:

    I haven't played with a ListCtrl yet, but from my reading, to use a Virtual List Control you can't use ListCtrl directly. You have to subclass ListCtrl into a derived class like MyListCtrl. The derived class will include your OnGetItemText method which will be called instead of the default OnGetItemText method in ListCtrl which is happening now in your test code. Clear as mud yet?

    Also wxLC_VIRTUAL can only be used with wxLC_REPORT so your MyListCtrl->new call has to include wxLC_VIRTUAL | wxLC_REPORT. I'm not sure what the 32 does that's in your code.

    Example code from wxPerl Demo:

    package Wx::DemoModules::wxListCtrl::Virtual; use strict; use base qw(Wx::ListCtrl Wx::DemoModules::wxListCtrl); use Wx qw(:listctrl wxRED wxBLUE wxITALIC_FONT wxDefaultPosition wxDefaultSize); sub new { my( $class, $parent ) = @_; my $self = $class->SUPER::new ( $parent, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL ); $self->bind_events; $self->create_menu; my( $small, $normal ) = $self->create_image_lists; $self->AssignImageList( $small, wxIMAGE_LIST_SMALL ); $self->AssignImageList( $normal, wxIMAGE_LIST_NORMAL ); $self->InsertColumn( 0, "Column 1" ); $self->InsertColumn( 1, "Column 2" ); $self->InsertColumn( 2, "Column 3" ); $self->InsertColumn( 3, "Column 4" ); $self->InsertColumn( 4, "Column 5" ); $self->SetItemCount( 100000 ); return $self; } sub OnGetItemText { my( $self, $item, $column ) = @_; return "( $item, $column )"; }

    Remember that there is code in the wxPerl Demo example that you won't need. It's just there to support the structure of the demo.

    James

    There's never enough time to do it right, but always enough time to do it over...

Re: wxPerl virtual list control not calling OnGetItemText?
by Anonymous Monk on Mar 14, 2013 at 02:59 UTC
Re: wxPerl virtual list control not calling OnGetItemText?
by jmlynesjr (Pilgrim) on Mar 14, 2013 at 13:18 UTC

    Helen:

    Here's some working code you can build on. A subclassing of ListCtrl.

    #! /home/xxxx/CitrusPerl/perl/bin/perl # wxPerl Virtual list control test # Created by: HelenCR # Last Modified: March 14,2013 by James M. Lynes, Jr. package MyForm; use strict; use warnings; use Wx qw[:everything]; use base 'Wx::Frame'; sub new { my $class = shift; my $self = $class->SUPER::new( undef, -1, 'Phone book', [ 200, 20 +0 ], wxDefaultSize); my $panel = Wx::Panel->new($self, -1, wxDefaultPosition, wxDefault +Size); $self->{list_ctrl} = MyListCtrl->new($panel); my $sizer = Wx::BoxSizer->new(wxVERTICAL); $sizer->Add( $self->{list_ctrl}, 0, wxALL | wxEXPAND, 5 ); $panel->SetSizer($sizer); return $self; } package MyListCtrl; # Subclass ListCtrl to allow use of a Virtual List Control and a custo +m OnGetItemText Subroutine use strict; use warnings; use base qw(Wx::ListCtrl); use Wx qw(:everything); sub new { my( $class, $parent ) = @_; my $self = $class->SUPER::new( $parent, -1, wxDefaultPosition, wxD +efaultSize, wxBORDER_SUNKEN | wxLC_REPORT | wxL +C_VIRTUAL | wxLC_HRULES ); $self->InsertColumn( 0, 'Last Name' ); $self->InsertColumn( 1, 'First Name' ); $self->InsertColumn( 2, 'Addr City' ); $self->InsertColumn( 3, 'Addr State' ); $self->SetItemCount( 1000 ); return $self; } sub OnGetItemText { print "Entered OnGetItemText\n"; my ($line, $column, $data_item); my ($self, $item, $col) = @_; $data_item = 'test'; return $data_item; } my $app = Wx::SimpleApp->new; my $frame = MyForm->new; $frame->Show(1); $app->MainLoop;

    James

    There's never enough time to do it right, but always enough time to do it over...

      Thanks a lot, James. I'm studying it.

      Your code is really helpful and instructive.

      Helen

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (20)
As of 2014-07-24 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (162 votes), past polls