[Glade-users] Making my own Classes
Xavier Claessens
xclaesse at gmail.com
Sun Oct 14 18:44:55 EDT 2007
Hum, I'm not sure it can solve my problem... Here is what I want to do:
1) I create a foo.glade file, the root widget is a GtkVBox, I pack in it
logs of GTK widgets.
2) Manually I rename the root widget class from GtkVBox to EmpathyFoo,
EmpathyFoo is a class inheriting from GtkVBox implemented in libempathy-gtk.
3) Using gtk-builder-convert I convert foo.glade to foo.ui
4) I make a method empathy_foo_new(){return gtk_builder_get_object(foo.ui,
root);} With that function I think GtkBuilder will do a
g_object_new(empathy_foo_get_type(), NULL); and then it will pack all
widgets in it as described in the .ui file. If that works, glade will
introspect my widget, see all packed widgets and display me their properties
but won't allow me to removed them since they are internal childs?
My questions are:
1) If I write a catalog for EmpathyFoo widget, glade-3 will need to call
empathy_foo_new() to create my widget, not g_object_new() because the widget
needs to be constructed by GtkBuilder to have all needed widgets packed in
it. How can I do that?
2) If I want to modify EmpathyFoo object, I open foo.glade using glade-3,
but I changed the root type to from GtkVBox to EmpathyFoo, what will glade
do? Will it use empathy_foo_get_type() and then pack in it all widgets and
allows me to modify everything? If that works I can convert the new glade
file to foo.ui and I'm happy.
The problem I see is glade-3 needs to use
g_object_new(empathy_foo_get_type(), NULL); when I'm editing foo.glade and
empathy_foo_new() when I'm using a EmpathyFoo widget in another glade file.
Is glade able to manage that?
Thanks,
Xavier Claessens.
2007/10/14, Xavier Claessens <xclaesse at gmail.com>:
>
> Thanks for answering that fast;
>
> On your blog I see the "parent" attribute, seems exactly what I need.
> It's not documented [1]? If I understand the patch for the "parent"
> attribute, I write a catalog with my EmpathyFoo widget and say the
> parent class is GtkHBox. When someone wants to embed my widget in the
> glade UI, glade will create a GtkHBox object, pack everything in it so
> it looks like a EmpathyFoo but it's not really one?
>
> Xavier Claessens.
>
> [1] http://glade.gnome.org/docs/index.html
>
>
> Le dimanche 14 octobre 2007 à 16:20 -0400, Tristan Van Berkom a écrit :
> > On Sun, 2007-10-14 at 17:55 +0200, Xavier Claessens wrote:
> > [...]
> > > But how will glade-3 react if I want to edit my glade file? It will
> see
> > > a unknown widget type... Is there a way to tell glade that EmpathyFoo
> is
> > > just like GtkHBox but when a client wants to instantiate it should use
> > > g_object_new(Empathy_foo_get_type(), NULL);
> > >
> > > And if I write a catalog xml file to describe properties of my
> > > EmpathyFoo widget, then other programs will be able to embed a
> > > EmpathyFoo widget in their UI, but will they be able to modify widgets
> > > packed in it?
> >
> > Yes.
> >
> > > So I have a foo.glade describing my EmpathyFoo widget, if I edit that
> > > file I want to be able to modify widgets packed in my EmpathyFoo
> widget.
> > > If a create a new bar.glade and pack (using catalog) an EmpathyFoo
> > > widget into a GtkWindow I don't want to be able to edit widgets
> > > contained in EmpathyFoo widget.
> > >
> > > Is that possible? Thanks for explanations!
> >
> > Ok you'll have to look at glade3/plugins/gtk+/glade-gtk.c,gtk+.xml.in .
> >
> > That will give you a good idea of how the class adapter works
> > (i.e. we use an object class implemented by your plugin to interact
> > with your runtime widgets).
> >
> > A plugin is not always nescisary, but you might need to override
> > some of the behaviour from the GtkHBox adaptor if your widget
> > behaves differently than a normal hbox (especially if you have
> > implicit internal child widgets, you might need to special case
> > them a bit). this blog post[1] you might have found explains the
> > simplest way to make a pluginless catalog, it should get you
> > started at least.
> >
> > Note that from the libglade pov, you'll have to write a plugin
> > that calls glade_register_widget() for your types and does any
> > special casing on the libglade side of things (it will be loaded
> > as the "name" specified in your glade catalog), there are easier
> > ways to get your widgets working without writing libglade plugins
> > but if you want it available for everyone then you need libglade
> > plugins (those plugins will not be needed in a GtkBuilder situation).
> >
> > Cheers,
> > -Tristan
> >
> > [1] http://blogs.gnome.org/tvb/2007/07/25/some-popular-features/
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/glade-users/attachments/20071015/784b88b9/attachment-0001.html
More information about the Glade-users
mailing list