From WxPerl Wiki
Jump to: navigation, search

An event is an object holding information about an event. It is passed to an event-handler function or method.

For more information about events, see the handling overview at the (C++-oriented) wxWidgets documentation site.

In wxPerl, custom event classes should be derived from Wx::PlEvent and Wx::PlCommandEvent.

Beginners should focus on the GetEventObject, GetEventType, and Skip methods; most of the others are for more advanced uses, such as generating custom events.


Wx::Event derives from Wx::Object.

See also

Wx::CommandEvent, Wx::MouseEvent



$ev = Wx::Event->new($id, $type);

Application code should never have to use this directly.



$copy = $ev->Clone;

Returns a copy of the event.

The following comes from the C++-oriented wxWidgets documentation at http://docs.wxwidgets.org; I don't know to what extent it applies to Perl classes that are derived from Wx::PlEvent. Anyone who knows more is asked to please update this section.

Any event that is posted to the wxWidgets event system for later action (via wxEvtHandler::AddPendingEvent or wxPostEvent) must implement this method. All wxWidgets events fully implement this method, but any derived events implemented by the user should also implement this method just in case they (or some event derived from them) are ever posted.
All wxWidgets events implement a copy constructor, so the easiest way of implementing the Clone function is to implement a copy constructor for a new event (call it MyEvent) and then define the Clone function like this:
wxEvent *Clone(void) const { return new MyEvent(*this); }


$obj = $ev->GetEventObject();

Returns the object (usually a window) associated with the event, if any.


$type = $ev->GetEventType();

Returns the identifier of the given event type, such as wxEVT_COMMAND_BUTTON_CLICKED.


$int = $ev->GetId();

Returns the identifier associated with this event, such as a button command id.


$bool = $ev->GetSkipped();

Returns true if the event handler should be skipped, false otherwise.


$long = $ev->GetTimestamp();

Gets the timestamp for the event. The timestamp is the time in milliseconds since some fixed moment (not necessarily the standard Unix Epoch, so only differences between the timestamps and not their absolute values usually make sense).


$bool = $ev->IsCommandEvent();

Returns true if the event is or is derived from Wx::CommandEvent else it returns false. Note: Exists only for optimization purposes.



Sets the propagation level to the given value (for example returned from an earlier call to StopPropagation).



Sets the originating object.



Sets the event type.



Sets the identifier associated with this event, such as a button command id.



Sets the timestamp (a long integer) for the event.


$bool = $ev->ShouldPropagate();

Test if this event should be propagated or not, i.e. if the propagation level is currently greater than 0.



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.

If $skip is true or omitted, 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.

If $skip is false, or if Skip() is never called, the event will not be processed any more after the current event 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.


$int = $ev->StopPropagation();

Stop the event from propagating to its parent window.

Returns the old propagation level value which may be later passed to ResumePropagation to allow propagating the event again.