Re: Glib::Object::Subclass, embedding and multiple interpreters
- From: Eduardo M KALINOWSKI <ekalin bol com br>
- To: gtk-perl-list gnome org
- Subject: Re: Glib::Object::Subclass, embedding and multiple interpreters
- Date: Thu, 31 Mar 2005 08:58:36 -0300
muppet wrote:
My (first) question is if there is a way to check if the type is
already registered, and if it is, to ignore the registration process.
This probably would mean that I would not be able to use
Glib::Object::Subclass and I would need to do things manually, but
that's OK.
If you've peeked at the code of Glib::Object::Subclass, you know that
it's just a thin syntactic wrapper around Glib::Type->register_object().
What you describe is pretty easy:
package MyObject;
eval {
Glib::Type->list_ancestors (__PACKAGE__);
# if we're alive here, the package is already registered.
} or Glib::Type->register_object ('ParentClass',
__PACKAGE__,
signals => { ... },
...);
# all normal method implementations follow...
Unfortunately, I'm still stuck at doing that manually. What does not
work is the signals, even with only one Perl interpreter and nothing
special.
I'm doing something like this:
package KCWin;
eval {
Glib::Type->list_ancestors(__PACKAGE__);
# if we're alive here, the package is already registered.
} or Glib::Type->register_object('Gtk2::Window',
__PACKAGE__,
signals => { activate => {} });
sub new {
my $class = shift;
my $self = bless Gtk2::Window->new, $class;
my $entry = Gtk2::Entry->new;
$entry->signal_connect(activate => sub {
$self->signal_emit('activate') });
$self->add($entry);
$entry->show;
$self->{ENTRY} = $entry;
return $self;
}
As you can see, I'm creating a new type that is a subclass of a window,
and that has an entry box inside this window. I would like this KCWin
window to have the activate signal, that is emited when the activate
signal of the entry box is emitted. (But I eventually want more things
in this window, this is just test code).
Creating a KCWin works, but connecting to the activate signal doesn't.
Here's some test code:
my $kcw = KCWin->new;
$kcw->signal_connect(activate => sub {
print "Signal fired\n";
});
It gives me this error:
GLib-GObject-WARNING **: gsignal.c:1664: signal `activate' is invalid
for instance `0x852cfd8' at <the line of $kcw->signal_connect>
This worked with "use Glib::Object::Subclass etc", even tough what is
now a new method was INIT_INSTANCE and the Gtk2::Window creating and
blessing was not necessary.
As for the rest, I couldn't test yet because of this problem.
--
Euch ist bekannt, was wir beduerfen;
Wir wollen stark Getraenke schluerfen.
-- Goethe, "Faust"
Eduardo M KALINOWSKI
ekalin bol com br
http://move.to/hpkb
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]