Converting to GtkBuilder

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!

12 responses to “Converting to GtkBuilder”

  1. Rhod

    Paint is the best option. It solves all problems!!

  2. Ray

    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)

  3. Jaroslav Smid

    Read somewhere (don’t know where) that GtkBuilder is (going to be) obsolete … by glade.

  4. Stephen Gentle

    “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.

  5. aklapper

    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.

  6. Jaap

    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

  7. Johan Dahlin

    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.

  8. rvl

    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.

  9. rvl

    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>

  10. Tristan

    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…

  11. GNOME PackageKit updates « Technical Blog of Richard Hughes

    […] Technical Blog of Richard Hughes Blog about geeky stuff « Converting to GtkBuilder […]

  12. Jon

    This is the first I’ve heard of GtkBuilder. Eek. Better take a look at my glade apps.

Bad Behavior has blocked 2769 access attempts in the last 7 days.