Hi,
I am going to release a module implementing an alternative event handling mechanism for wxPerl; it's inspired to Qt signal/slots.

The module implements a publish/subscribe model for events, and is built on top of wxPerl event handling. Advantages compared to wxPerl event model:

- there is no need to import the EVT_* functions
- "interesting" values for the event are passed directly as parameters,
  so there is no need to deal with wxWidgets event objects
- a notification can be connected to multiple receivers
- notifications can be connected to already existing methods
  (for example connecting a 'TextChanged' signal to one of the existing
  'SetValue' methods)

Preliminary documentation below (obviously, the event list is not complete, the entries are there as an example). Feedback welcome!

Thanks,
Mattia



NAME
       Wx::Perl::SignalSlots - alternative event dispatching for wxPerl

SYNOPSIS
           use Wx::Perl::SignalSlots qw(:default);

           my $frame = MyFrame->new( ... );
           my $listbox = Wx::ListBox->new( $frame, -1, ... );

           subscribe( $listbox, 'ItemSelected', $frame, 'OnItemSelected' );
subscribe( $listbox, 'ItemSelected', $object, 'SetSelectedIndex' );

           # in MyFrame.pm

           sub OnItemSelected {
               my( $self, $index ) = @_;

               # ...
           }

DESCRIPTION
       This module implements an alternative event handling model
       for wxPerl, in some ways similar to Qt signal/slot mechanism.
       The advantages compared to wxWidgets/wxPerl standard
       event handling are:

       simpler
           No need to deal with wxWidgets event objects.

       multicast
           The "EVT_FOO" binders can only bind an event once per object.

       cleaner
           No need to import the various "EVT_FOO" binders.

FUNCTIONS
   "subscribe"
           subscribe( $sender, 'SignalName', $object, 'MethodName' );
           subscribe( $sender, 'SignalName', \&_function );

       Connects a signal to a receiver.  Every time the signal is
       emitted, the receiver method/function will be
       called with zero or more arguments
       specific to the signal (for example the "Clicked" signal takes no
       arguments while the "ItemSelected" signal takes the item index as
       argument).

       When multiple receivers are connected to the same sender/signal,
       the call order is undefined.

       Both sender and receiver converted into weak references; if a
       window is destroyed or an object is garbage collected
       all the associated connections are automatically removed.

   "unsubscribe"
           unsubscribe( $sender, 'SignalName', $object, 'MethodName' );
           unsubscribe( $sender, 'SignalName', \&_function );

       Removes a connection created by "subscribe".  If there is
       no matching connection the call does nothing.

CLASSES
   "Wx::Button"
       "Clicked()"

       Emitted when a push button is clicked.

   "Wx::ListBox"
       "ItemSelected( $index )"

       Emitted when a list box item is selected; takes the item index as
       parameter.

   "Wx::Timer"
       "Timeout()"

       Emitted every time the timer timeout expires.

   "Wx::Window"
       "Destroyed( $object )"

       Emitted when a "Wx::Window" derived class is destroyed.  Note
       that the object passed to the signal might not be blessed in
       the correct class, and no method must be called on it.

       "Idle()"

       Emitted every time the event loop stops because there are no more
       events to process.

Reply via email to