Re: signal functions in a package module file
- From: "Matthew Braid" <ptkperl mdb id au>
- To: "gtk-perl-list gnome org List" <gtk-perl-list gnome org>
- Subject: Re: signal functions in a package module file
- Date: Mon, 21 Jul 2008 13:11:36 +1000
Hi,
2008/7/21 muppet <scott asofyet org>:
Two possible solutions:
1. Somehow share the Gtk2::GladeXML instance between the two packages,
either by having the main program use avaim's instance, or having aviam
somehow get the instance from the main program.
For larger projects, I often tell glade to bind to an instance of a
package rather than a package, so you can do stuff like:
my $glade = Gtk2::GladeXML->new($FILE);
my $callbacks = My::Callbacks->new($glade);
$glade->signal_autoconnect_from_package($callbacks);
# Do stuff
$callbacks->destroy;
with a stub callbacks package of:
package My::Callbacks;
use strict;
sub new {
my $class = shift;
return bless({}, (ref($class) or $class or __PACKAGE__))->_init(@_);
}
sub _init {
my $self = shift;
my ($glade) = @_;
$self->{Glade} = $glade;
return $self;
}
sub destroy { # You can also use the standard DESTROY if you want :)
my $self = shift;
delete($self->{Glade});
}
__END__
So the callbacks always have access to the glade object via the
$self->{Glade} key (and anything else you may need to pass them).
MB
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]