Patch for GladeXML.pm to allow for methods as callbacks




Ken,

Please accept the attached patch for GladeXML.pm (from Gtk-Perl-0.7004)
which allows the user to pass a blessed reference as the argument to
'signal_autoconnect_from_package' (instead of the package name) and have
each callback called as an object method (of the passed reference value).

This way, you can have a class constructor which looks something
like this:

   sub new {
      my $proto = shift;
      my $class = ref $proto || $proto;
      my $self  = {};

      bless $self, $class;

      $self->{GOBJ} = new Gtk::GladeXML('pgt.glade');

      $self->{GOBJ}->signal_autoconnect_from_package($self);

      return $self;
   }


...and callsbacks looking similar to this:

   sub on_new_button_clicked {
      my $self = shift;

      $self->{GOBJ}->get_widget('detail_window')->show();
   }


Of course... there may be a way to do this with the existing code...
but I never could figure out how to do it without this simple patch.
If this can be done without a patch... please, somebody tell me how. :-)

I've tested this under 5.005_03 only.  I can't say whether it will
work with other versions (as I don't have any others installed right
now) but it's simple enough that all should be well.  AFAIK, all that's
needed is support for closures... and that's been around for quite
a while.

Thanx,
Tim.

-- 
 ____________________________________________   _                       _ 
                           Timothy E. Peoples  |_| C o l l e c t i v e |_|
                          Engineering Manager   |_    technologies     _| 
                             tep colltech com     []                 []   

Attachment: GladeXML.pm-patch
Description: Text document



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]