in reply to Passing arguments to event handlers in WxPerl

Passing arguments to event handlers in WxPerl is something you never have to do :)

Having code outside of subroutines is something you never have to do :) (really shouldn't )

EVT_COMBOBOX ... How is this done?

As documented :) my wxWidgets / wxPerl / wxGlade tutorial, wxperl_usage / wxperl-usage / wxPerl::Usage / Class Method Browser , available methods, method invocation syntax, link to docs

sub Combobox1action { my( $frame, $comboevent ) = @_; my $combobox = $comboevent->GetEventObject; my $selection = $comboevent->GetString; $frame->SetTitle( "Combo box selected ($selection)" ); }


http://docs.wxwidgets.org/2.8.12/wx_wxcommandevent.html#wxcommandeventgetstring
http://docs.wxwidgets.org/2.8.12/wx_wxevent.html#wxeventgeteventobject

Re^2: How do i color font in a listbox? ( wx-listctrl-coloritems-findselect.pl )

wx-combobox-event.pl

#!/usr/bin/perl -- ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while " -otr + -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Wx 0.86 qw( ); Main( @ARGV ); exit( 0 ); sub Main { my $app = Wx::SimpleApp->new; my $f = Wx::Frame->new( undef, -1, "", ); my $cb = Wx::ComboBox->new( $f, -1, "", [-1,-1,], [-1,-1,], [ 22 .. 33 ], ); $cb->SetFocus; $f->SetSizer( Wx::BoxSizer->new( Wx::wxVERTICAL() ) ); $f->GetSizer->Add( $cb, 0, Wx::wxEXPAND() ); $f->GetSizer->SetSizeHints( $f ); $f->Show( 1 ); $app->SetTopWindow( $f ); #~ Wx::Event::EVT_COMBOBOX( $app, $cb, \&Combobox1action ); Wx::Event::EVT_COMBOBOX( $f, $cb, \&Combobox1action ); $app->{cb} = $cb; $app->MainLoop; } ## end sub Main sub Combobox1action { my( $frame, $comboevent ) = @_; my $combobox = $comboevent->GetEventObject; my $selection = $comboevent->GetString; #~ my $selection = $combobox->GetValue; $frame->SetTitle( "Combo box selected ($selection)" ); } ## end sub Combobox1action __END__
  • Comment on Re: Passing arguments to event handlers in WxPerl (is something you never have to do; wx-combobox-event.pl)
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Passing arguments to event handlers in WxPerl (is something you never have to do; wx-combobox-event.pl)
by pwn01 (Initiate) on Sep 19, 2014 at 15:12 UTC
    I guess I'm still trying to develop an OO way of thinking. One more question. Is there an ideal place to do database operations? Should I do them right at the beginning and load up a bunch of variables?
Re^2: Passing arguments to event handlers in WxPerl (is something you never have to do; wx-combobox-event.pl)
by pwn01 (Initiate) on Sep 19, 2014 at 14:38 UTC
    Thanks for the response. It think that you are on to the problem. Do the variables in MyFrame that I loaded with the data from the database have the right scope for the event handler sub to access them?
      Got it!!! Thanks. Here is the code:
      sub Combobox1action { my( $self, $event ) = @_; my $selection; $selection = $event->GetString(); $self->SetTitle( 'Combo box selected ( '.$selection.' )' ); }
      I guess I still need to clean up a little, but at least I've moved forward. Thanks all. Any other final suggestions are welcome.
      I found the answer to the scope question.