Re: GtkBuilder questions
- From: Tristan Van Berkom <tvb gnome org>
- To: Xavier Claessens <xclaesse gmail com>
- Cc: gtk-list gnome org
- Subject: Re: GtkBuilder questions
- Date: Sun, 14 Oct 2007 23:07:02 -0400
On Sun, 2007-10-14 at 15:13 +0200, Xavier Claessens wrote:
[...]
> Most widgets inherit from GtkContainer and I define in my glade/ui xml
> file widgets contained. If I do that naively I can construct the widget
> using glade (and convert to ui) but that won't be my own defined class.
This can lead to alot of confusion, but I think its totally possible
for a composite widget to create its own internal children using
GtkBuilder (although this recursiveness rings warning bells).
> Is there a way to tell GtkBuilder that an object is of type EmpathyFoo
> and GtkBuilder will magically use g_object_new (EMPATHY_TYPE_FOO,
> properties) to create that object and will pack childrens in it?
This is a no brainer, suffice it to say that any widget that can
be properly built with g_object_new() and responds well to properties
can be handled by gtkbuilder, if that object is a container then
any children found in the glade/builder file will be added using the
normal GtkContainer api (gtk_container_add/child properties).
> I was
> told that's possible to create my own widgets classes for glade using
> "catalogues", I didn't tested that yet, is that possible with GtkBuilder
> too?
Catalogs in glade are only to tell glade how to add widgets to your
glade project, it is our intent to make glade output gtkbuilder readable
files as much (if not more) as libglade readable files.
> An other problem I have is using GtkBuilder if the root is not a
> GtkWindow object, GtkBuilder takes ownership of the widget (using
> g_object_sink_ref), that means if I create a window I can unref the
> builder safely but if it's just a GtkHBox (for example) I have to first
> g_object_ref(hbox); and g_object_force_floating (hbox); and then it
> should be safe to unref the builder, and my hbox becomes a normal widget
> I can pack where I want. Is that the normal behaviours? I think libglade
> don't act like that.
While in practice this should not effect the application using
your empathy widgets because the libempathy user probably embedded
your empathy widget in their app somewhere, i.e. inside some window
that has ownership, I must agree that this behaviour does wonders
to confuse the api user, but yes it is the expected behaviour.
> And final question; I have one ui file per widget, should I create one
> GtkBuilder object and add_from_file() all ui files in it? Or should I
> create one GtkBuilder per widget? And if I want to create 2 instances of
> one widget I have to create 2 different GtkBuilder objects or is there a
> way to tell GtkBuilder to create a new instance of a given object?
One UI file per widget defeats the purpose of using builder/glade type
technologies, builder/libglade builds your UI and add your widgets to
the application interface at the appropriate places, so lets say for
example you might have one builder/glade file that describes your whole
application that may contain one or many emapthy widgets, or maybe
the application will chose to use one file for each toplevel and
one for all its dialogs (which in turn may or may not include some
empathy widgets).
Either way, using the GtkBuilder object and creating/parsing builder
files is the domain of the application frontend, the library & widget
code need only be properly constructable with g_object_new() &
properties (or for corner special cases they can implement
GtkBuildable).
I sincerely hope this helps.
Cheers,
-Tristan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]