Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Dear esteemed PerlMonks

I am trying to develop GUI-based application, (moving from Win32::GUI to wxPerl/wxWidgets). I find it pretty difficult, the documentation and tutorials are very sketchy.

Trying to implement a (very simple) short list control, I am trying to port a Python example.

Here is the Python code, taken from: http://www.blog.pythonlibrary.org/2011/01/04/wxpython-wx-listctrl-tips-and-tricks/

import wx ###################################################################### +## class MyForm(wx.Frame): #----------------------------------------------------------------- +----- def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "List Control Tutoria +l") # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self.index = 0 self.list_ctrl = wx.ListCtrl(panel, size=(-1,100), style=wx.LC_REPORT |wx.BORDER_SUNKEN ) self.list_ctrl.InsertColumn(0, 'Subject') self.list_ctrl.InsertColumn(1, 'Due') self.list_ctrl.InsertColumn(2, 'Location', width=125) btn = wx.Button(panel, label="Add Line") btn.Bind(wx.EVT_BUTTON, self.add_line) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5) sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5) panel.SetSizer(sizer) #----------------------------------------------------------------- +----- def add_line(self, event): line = "Line %s" % self.index self.list_ctrl.InsertStringItem(self.index, line) self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010") self.list_ctrl.SetStringItem(self.index, 2, "USA") self.index += 1 #--------------------------------------------------------------------- +- # Run the program if __name__ == "__main__": app = wx.App(False) frame = MyForm() frame.Show() app.MainLoop()

and here is the ported Perl program:

# 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-listctr +l-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 wxCEN +TER}; 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 wxCEN +TER}; # 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', # lab +el [20,30], # posi +tion [-1,100], # siz +e &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;

When running the Perl program, it issues the cryptic error:

variable is not of type Wx::Point at Wx List Control test PerlO.pl lin +e 52 MyForm::new('MyForm') called at Wx List Control test PerlO.pl line 25 MyApp::OnInit('MyApp=HASH(0x2407e64)') called at F:/Win7programs/Dwimp +erl/perl/site/lib/Wx/App.pm line 36 eval {...} called at F:/Win7programs/Dwimperl/perl/site/lib/Wx/App.pm +line 36 Wx::App::new('MyApp') called at F:/Win7programs/Dwimperl/perl/site/lib +/Wx/App.pm line 36 Wx::App::new('MyApp') called at Wx List Control test PerlO.pl line 88

(the program name is: "Wx List Control test PerlO.pl").

Line 52 is the statement:

$list_ctrl = Wx::ListCtrl-> new ($panel, -1, # ID 'Report', # lab +el [20,30], # posi +tion [-1,100], # siz +e &Wx::wxLC_REPORT | + &Wx::wxBORDER_SUNKEN, # window style );

(System: DWIMPerl 5.14.2 on Windows 7).

Your help will be appreciated - this is holding up the development.

Many TIA - Helen


In reply to wxPerl fails with a cryptic message: "variable is not of type Wx::Point" by HelenCr

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found