Hi James, One more thing I've discovered. If you set the ID in the first place then you know what it means. So instead of passing -1 (wxANY), pass a positive integer of your own invention. Apparently all wxPerl ids are negative.
Regards Steve -----Original Message----- From: GMAIL - James McDonald [mailto:ja...@jamesmcdonald.id.au] Sent: 14 August 2009 02:39 To: wxperl-users@perl.org Subject: wxGlade Generated Code I use wxPerl to create custom interfaces. Alot of these interfaces have a Number Keypad and I've only just figured out how to get hold of the actual object I click using a post from Steve Cookson (Thanks Steve). It's embarrassing to admit but I was creating one event handler per key ( keyPress1, keyPress2 etc...) So using: my $keyLabel = $event->GetEventObject()->GetLabel(); I can get the text on the button I have clicked. But let's say I want to know the actual control name such as return "button_1" from the EVT_BUTTON event how do I return that? I can use GetId to return the default number but how do I return it's programmatic name? $self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0); I am not really understanding the event subsystem very well. Of course I have looked at the documentation but due to my lack of understanding I still am not grasping the concept. I have little idea of what $event->Skip means and where in the block it should appear, if at all. Can anyone enlighten me? What does the doco it mean when it says you can have "further event handlers", can you create a chain of event handlers? # copy and paste from docs wxEvent::Skip *void* *Skip*(*bool*/ skip = true/) This method can be used inside an event handler to control whether further event handlers bound to this event will be called after the current one returns. Without Skip() (or equivalently if Skip(false) is used), the event will not be processed any more. If Skip(true) is called, the event processing system continues searching for a further handler function for this event, even though it has been processed already in the current handler. In general, it is recommended to skip all non-command events to allow the default handling to take place. The command events are, however, normally not skipped as usually a single command such as a button click or menu item selection must only be processed by one handler. # my sample application #!/usr/bin/perl -w -- # generated by wxGlade 0.6.3 on Fri Aug 14 14:57:39 2009 # To get wxPerl visit http://wxPerl.sourceforge.net/ use Wx 0.15 qw[:allclasses]; use strict; package MyFrame; use Wx qw[:everything]; use base qw(Wx::Frame); use strict; sub new { my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_; $parent = undef unless defined $parent; $id = -1 unless defined $id; $title = "" unless defined $title; $pos = wxDefaultPosition unless defined $pos; $size = wxDefaultSize unless defined $size; $name = "" unless defined $name; # begin wxGlade: MyFrame::new $style = wxDEFAULT_FRAME_STYLE unless defined $style; $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name ); $self->{button_1} = Wx::Button->new($self, -1, "1"); $self->{button_2} = Wx::Button->new($self, -1, "2"); $self->{button_3} = Wx::Button->new($self, -1, "3"); $self->{button_4} = Wx::Button->new($self, -1, "4"); $self->{button_5} = Wx::Button->new($self, -1, "5"); $self->{button_6} = Wx::Button->new($self, -1, "6"); $self->{button_7} = Wx::Button->new($self, -1, "7"); $self->{button_8} = Wx::Button->new($self, -1, "8"); $self->{button_9} = Wx::Button->new($self, -1, "9"); $self->__set_properties(); $self->__do_layout(); Wx::Event::EVT_BUTTON($self, $self->{button_1}->GetId, \&keyPress); Wx::Event::EVT_BUTTON($self, $self->{button_2}->GetId, \&keyPress); Wx::Event::EVT_BUTTON($self, $self->{button_3}->GetId, \&keyPress); Wx::Event::EVT_BUTTON($self, $self->{button_4}->GetId, \&keyPress); Wx::Event::EVT_BUTTON($self, $self->{button_5}->GetId, \&keyPress); Wx::Event::EVT_BUTTON($self, $self->{button_6}->GetId, \&keyPress); Wx::Event::EVT_BUTTON($self, $self->{button_7}->GetId, \&keyPress); Wx::Event::EVT_BUTTON($self, $self->{button_8}->GetId, \&keyPress); Wx::Event::EVT_BUTTON($self, $self->{button_9}->GetId, \&keyPress); # end wxGlade return $self; } sub __set_properties { my $self = shift; # begin wxGlade: MyFrame::__set_properties $self->SetTitle("A sample keypad program"); # end wxGlade } sub __do_layout { my $self = shift; # begin wxGlade: MyFrame::__do_layout $self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL); $self->{grid_sizer_1} = Wx::GridSizer->new(3, 3, 0, 0); $self->{grid_sizer_1}->Add($self->{button_1}, 0, 0, 0); $self->{grid_sizer_1}->Add($self->{button_2}, 0, 0, 0); $self->{grid_sizer_1}->Add($self->{button_3}, 0, 0, 0); $self->{grid_sizer_1}->Add($self->{button_4}, 0, 0, 0); $self->{grid_sizer_1}->Add($self->{button_5}, 0, 0, 0); $self->{grid_sizer_1}->Add($self->{button_6}, 0, 0, 0); $self->{grid_sizer_1}->Add($self->{button_7}, 0, 0, 0); $self->{grid_sizer_1}->Add($self->{button_8}, 0, 0, 0); $self->{grid_sizer_1}->Add($self->{button_9}, 0, 0, 0); $self->{sizer_1}->Add($self->{grid_sizer_1}, 1, wxEXPAND, 0); $self->SetSizer($self->{sizer_1}); $self->{sizer_1}->Fit($self); $self->Layout(); # end wxGlade } sub keyPress { my ($self, $event) = @_; # wxGlade: MyFrame::keyPress <event_handler> warn "Event handler (keyPress) not implemented"; $event->Skip; my $key = $event->GetEventObject()->GetLabel(); my $keyid = $event->GetEventObject()->GetId(); # end wxGlade Wx::MessageBox("You pressed: $key\nKey ID: $keyid", "wxPerl Sample"); } # end of class MyFrame 1; 1; package main; unless(caller){ local *Wx::App::OnInit = sub{1}; my $app = Wx::App->new(); Wx::InitAllImageHandlers(); my $frame_1 = MyFrame->new(); $app->SetTopWindow($frame_1); $frame_1->Show(1); $app->MainLoop(); }