Subclassing SimpleList with signals
- From: muppet <scott asofyet org>
- To: gavin brown uk com
- Cc: gtk-perl mailing list <gtk-perl-list gnome org>
- Subject: Subclassing SimpleList with signals
- Date: Wed, 8 Jun 2005 22:12:53 -0400
04:17AM <jodrell> morning all
04:21AM <jodrell> i've got a conundrum - i'm subclassing
Gtk2::SimpleList, but want to add my own signals. but because
SimpleList isn't registered with the GLib type system, i can't. is
there a way to add signals after the startup?
SimpleList isn't registered because it's subclassed by simple perl
reblessing. That means there's no GType for it. In C you probably
could add signals after a type has been created, but we don't bind
those functions in perl so you can't; even if you could, because
there's no special GType for SimpleList, you'd be adding your signals
to TreeView, which isn't what you want.
Now, there are two ways around this, so the question is, what are you
trying to do?
a) If you need to add a signal that corresponds to something
happening on the model, you can create your own model subclass, and
then do
my @ary;
tie @ary, 'Gtk2::SimpleList::TiedList', $model;
# fill the model
@ary = ...;
I've often thought that this should be broken out into a more
generally useful module, because the tied behavior really is the best
part of the whole thing.
b) If you want to add signals to the view, then use the same
functionality that is there to allow you to turn a glade-created
TreeView into a SimpleList:
my $view = MyCoolCustomTreeViewClass->new;
my $slist = Gtk2::SimpleList->new_from_treeview ($view, ...);
And everything should Just Work. new_from_treeview() will replace
whatever model was already in the view with a new one.
On the other hand, if you want to add signals to both the model and
the view, then things get a little trickier. new_from_treeview() is
hardcoded to create a Gtk2::ListStore, so you can't override the
model class. The model instance is held not only in view, but also
in the tied instance, and, worse, in closures used for the cell
editing signals. In retrospect, that should be done a little more
cleanly, fetching the model on demand from the slist instance. So,
without a patch to SimpleList, you can't really use a custom
implementation for both the view and the model.
--
Jolt is my co-pilot.
-- Slogan on a giant paper airplane hung in Lobby 7 at MIT.
http://hacks.mit.edu/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]