# wxPerl list control test 7 3 2013. Based on Tutorial 8 # Taken from: http://wxperl.sourceforge.net/tutorial/tutorial4.html # and http://www.blog.pythonlibrary.org/2011/01/04/wxpython-wx-listctrl-tips-and-tricks/ 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 MyApp; use base 'Wx::App'; use Wx qw{ wxLC_REPORT wxBORDER_SUNKEN wxVERTICAL wxALL wxEXPAND wxCENTER}; sub OnInit { my $frame = MyForm->new; $frame->Show( 1 ); } # end package MyApp; package MyForm; use base 'Wx::Frame'; use Wx qw{ wxLC_REPORT wxBORDER_SUNKEN wxVERTICAL wxALL wxEXPAND wxCENTER}; # import the event registration function use Wx::Event qw(EVT_BUTTON); our ($idx, $list_ctrl); sub new { my $ref = shift; my $self = $ref->SUPER::new( undef, # parent window -1, # ID -1 means any 'List Control Tutorial', # title [-1, -1], # default position [400, 300], # size ); # Add a panel so it looks correct on all platforms my $panel = Wx::Panel->new( $self, # parent window -1, # ID ); $idx = 0; $list_ctrl = Wx::ListCtrl-> new ($panel, -1, # ID 'Report', # label [20,30], # position [-1,100], # size &Wx::wxLC_REPORT | &Wx::wxBORDER_SUNKEN, # window style ); $list_ctrl->InsertColumn( 0, 'Subject' ); $list_ctrl->InsertColumn( 0, 'Due' ); $list_ctrl->InsertColumn( 0, 'Location' ); my $btn = Wx::Button->new( $panel, # parent window -1, # ID 'Add Line', # label [-1, -1], # default position [-1, -1], # default size ); EVT_BUTTON( $self, $btn, \&add_line ); my $sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL); $sizer->Add($list_ctrl, 0, &Wx::wxALL| &Wx::wxEXPAND, 5); $sizer->Add($btn, 0, &Wx::wxALL | &Wx::wxCENTER, 5); $panel->SetSizer($sizer); } # end sub new sub add_line { # my $event; my ( $self, $event ) = @_; my $line = "Line $idx"; $list_ctrl->InsertStringItem($idx, $line); $list_ctrl->SetStringItem($idx, 1, '01/19/2010'); $list_ctrl->InsertStringItem($idx, 2, 'USA'); $idx += 1; } # end sub add_line 1; # end package MyForm; package main; my $app = MyApp->new; $app->MainLoop; 1;