Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Porting a wxPython List Control example into wxPerl: don't see column headings?

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

Dear esteemed PerlMonks

I am trying to port a wxPython ListControl example, into wxPerl. The problem: I don't get the column heading titles (or bar).

Here are the details:
Original Python code example, taken from: (first answer):

import wx class MainWindow(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.panel = wx.Panel(self) self.panel.SetBackgroundColour(wx.GREEN) self.list = wx.ListCtrl(self, style=wx.LC_REPORT, size=(200, - +1)) column_size = self.list.GetSize()[0] / 2 - 2 self.list.InsertColumn(0, 'Name') self.list.InsertColumn(1, 'Age') self.list.SetColumnWidth(0, column_size) self.list.SetColumnWidth(1, column_size) self.sizer = wx.BoxSizer() self.sizer.Add(self.list, proportion=0, flag=wx.EXPAND) self.sizer.Add(self.panel, proportion=1, flag=wx.EXPAND) self.SetSizerAndFit(self.sizer) self.SetSize((600, 400)) self.Show() app = wx.App(False) win = MainWindow(None) app.MainLoop()

My port into wxPerl:

use strict; use warnings; use Wx; use 5.014; use autodie; use Carp; use Carp qw {cluck}; use Carp::Always; use Win32::Console; package MainWindow; use Wx ':everything'; use parent -norequire, 'Wx::Frame'; sub new { #1 MainWindow:: my $class = shift; my $self = $class->SUPER::new( undef, -1, # parent window; ID -1 means any 'Test', # title [-1,-1 ], # position [ -1, -1 ], # size ); # def __init__(self, *args, **kwargs): # wx.Frame.__init__(self, *args, **kwargs) $self->{panel} = Wx::Panel->new($self); $self->{panel}->SetBackgroundColour(wxGREEN); $self->{list} = Wx::ListCtrl->new($self->{panel}, wxLC_REPORT, + [200, -1]); my $column_size = $self->{list}->GetSize->width / 2 - 2; $self->{list}->InsertColumn(0, 'Name'); $self->{list}->InsertColumn(1, 'Age'); $self->{list}->SetColumnWidth(0, $column_size); $self->{list}->SetColumnWidth(1, $column_size); $self->{sizer} = Wx::BoxSizer->new(wxVERTICAL); $self->{sizer}->Add($self->{list}, 0, wxEXPAND); $self->{sizer}->Add($self->{panel}, 1, wxEXPAND); $self->SetSizerAndFit($self->{sizer}); $self->SetSize([600, 400]); return $self; } #1 end sub new MainWindow:: my $app = Wx::SimpleApp->new; my $win = MainWindow->new; $win->Show(1); $app->MainLoop;

The problem: you do get a window, which does get resized, but I don't see any ListCtrl heading line (or bar), or any column titles.
Am I doing something wrong? Is there a mistake somewhere?
My system: DWIM Perl 5.14.2 on Windows 7.

Your help will be appreciated.

Many TIA - Helen

Replies are listed 'Best First'.
Re: Porting a wxPython List Control example into wxPerl: don't see column headings?
by McA (Priest) on Mar 23, 2013 at 12:36 UTC


    being curious I digged around a bit having more or less no clue about the building blocks of wxPerl, but I got a little nice looking window with the following code:

    use strict; use warnings; use Wx; use Carp qw {cluck}; package MainWindow; use Wx ':everything'; use parent -norequire, 'Wx::Frame'; sub new { my $class = shift; my $self = $class->SUPER::new( undef, -1, 'Test', [-1, -1], [-1, -1], ); # we need a panel my $panel = Wx::Panel->new($self); $panel->SetBackgroundColour(wxGREEN); $self->{panel} = $panel; # create a list control with content my $lc = Wx::ListCtrl->new( $panel, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT, ); $lc->InsertColumn(0, 'Column1', wxLIST_FORMAT_LEFT, 150); $lc->InsertColumn(1, 'Column2', wxLIST_FORMAT_LEFT, 150); for my $i (1..10) { my $id = $lc->InsertStringItem($i, "Item $i"); $lc->SetItem($id, 1, $i, -1); $lc->SetItemData($id, 100 + $i); } $self->{list} = $lc; # put sizers in my $panelsizer = Wx::BoxSizer->new(wxVERTICAL); my $mainsizer = Wx::BoxSizer->new(wxVERTICAL); $panelsizer->Add($lc, 1, wxEXPAND|wxALL, 0); $panel->SetSizer($panelsizer); $mainsizer->Add($panel, 1, wxEXPAND|wxALL, 0); $self->SetSizer( $mainsizer ); return $self; } my $app = Wx::SimpleApp->new; my $win = MainWindow->new; $win->Show(1); $app->MainLoop;
    Probably it helps you to find out what was wrong initially.


      McA: thank you for your time and investment of effort.

      I am studying your code, and if I have further questions I'll come back in a day or two.

      Lots of thanks - Helen

Re: Porting a wxPython List Control example into wxPerl: don't see column headings?
by Anonymous Monk on Mar 23, 2013 at 19:01 UTC
Re: Porting a wxPython List Control example into wxPerl: don't see column headings?
by jmlynesjr (Hermit) on Mar 23, 2013 at 16:59 UTC

    As McA demonstrated, the wxPerl ListCtrl calling parameters aren't correct. Missing the id, position, and size, and the style is out of order.


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

      James and Anonymous: you are right, of course.

      In my OP, the call to Wx::ListCtrl (code line 25) should be changed from:

      $self->{list} = Wx::ListCtrl->new($self->{panel}, wxLC_REPORT, [200, -1]);


      $self->{list} = Wx::ListCtrl->new($self->{panel}, -1, wxDefaultPosition, [200, -1], wxLC_REPORT);

      then it works fine, as intended.

      Thank you for your help - Helen

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2018-10-23 18:57 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (125 votes). Check out past polls.