This evening I’ve been trying to convert my projects (gnome-packagekit and gnome-power-manager) away from libgade to the shinier GtkBuilder. One less library, right? So far so good, except for the fancy super sexy custom widgets.
Stuff like the graph widget in gnome-power-statistics was created using the glade_set_custom_handler function, which was then creating the widget using gpm_graph_widget_new() in that callback. I’m not sure how to do this with GtkBuilder and the new markup format. Google isn’t being very helpful. Help appreciated. Thanks!
Published by
hughsie
Richard has over 10 years of experience developing open source software. He is the maintainer of GNOME Software, PackageKit, GNOME Packagekit, GNOME Power Manager, GNOME Color Manager, colord, and UPower and also contributes to many other projects and opensource standards. Richard has three main areas of interest on the free desktop, color management, package management, and power management.
Richard graduated a few years ago from the University of Surrey with a Masters in Electronics Engineering. He now works for Red Hat in the desktop group, and also manages a company selling open source calibration equipment. Richard's outside interests include taking photos and eating good food.
View all posts by hughsie
Paint is the best option. It solves all problems!!
Looking at the docs, I see this:
In order to allow construction from a GtkBuilder UI description, an object class must implement the GtkBuildable interface. The interface includes methods for setting names and properties of objects, parsing custom tags, constructing child objects.
Seems like that’s how (although I haven’t tried it)
Read somewhere (don’t know where) that GtkBuilder is (going to be) obsolete … by glade.
“Read somewhere (don’t know where) that GtkBuilder is (going to be) obsolete … by glade.”
Other way around, mate – Libglade was depreciated, and GtkBuilder (which is part of GTK) is replacing it.
If you find out, sharing this by adding it to e.g.
http://library.gnome.org/devel/gtk/stable/gtk-migrating-GtkBuilder.html would be welcome.
In cheese what we did is just leave an empty frame and add the custom control in the code to that frame.
See around line 1660 in
http://svn.gnome.org/viewvc/cheese/trunk/src/cheese-window.c?revision=1210&view=markup
I wrote a little hack a while ago to load custom like constructs directly:
http://www.gnome.org/~johan/gtkbuildercustom.c
Haven’t really been tested with what glade3 is generating, but it should in general work.
I had some success doing this 2 weeks ago.
First I made my widget class implement GtkBuildable. This wasn’t much much work because GtkContainer already implemented it, I just had to alter add_child() slightly.
Then I added construction properties to my widget class so that these could be set from the XML.
Then I put this into my builder XML:
True
I was also looking at implementing the custom_tag_start, etc. methods for setting custom widget data, but didn’t get far.
I also set up my main window as a subclass on GtkWindow. This could be constructed directly from gtkbuilder XML, which was pretty cool, e.g.
…
It all seemed fairly straightforward, even if the docs were a little short of practical information. I hope I understood your question.
Sorry… the XML got mangled, here it is again:
1.
<object class=”GpmGraphWidget” id=”graph”>
<property name=”foo”>True</property>
<signal name=”xyzzy-event” handler=”graph_on_xyzzy”/>
</object>
2.
<object class=”MyAppWindow” name=”window”>
<child>
…
</child>
</object>
Richard,
To get your widget loaded it does not need to
explicitly implement GtkBuildable, it only needs to
have its type specified in the Glade file (if it has
custom constructs or needs to do custom stuff
at load time, then implement buildable).
Please read the docs I wrote at glade.gnome.org/docs
about integrating your widgets into Glade, and feel
free to send me emails on the subject…
This is the first I’ve heard of GtkBuilder. Eek. Better take a look at my glade apps.