Skip to content

Glade and property binding: Create your own bindings now!

Hello inhabitants of the wonderful world of GNOME,

I admit it right away: I lied. Or, rather, didn’t do what I promised and planned. While I wrote in my last post that I would blog about any visible progress of my Google Summer of Code project, GObject property binding in GtkBuilder and Glade, right after it is commited, I didn’t post anything for, gosh, over a whole month. Which is a shame, as there *is* actually quite a lot to see: support for not only viewing, but also creating and deleting property bindings is now fully implemented and working! The UI for this is pretty non-obvious at the moment and could be much improved, but it’s fully functional and will receive a great deal of spit and polish once the mandatory implementation work is done (more on this later).

The right-click menu of every property in the inspector (what, you didn’t know there was a right-click menu? well, I said this isn’t obvious ;)) now contains a new item named Bind to source… which allows you to make the property the target of a new binding.

Choosing this item will present you will a nice little two-pane dialog which allows you to choose the source object and property you would like to bind to. As you can see in the screenshot below, properties whose type don’t match the target property are greyed out and appear after all the compatible ones.

(Yes, these screenshots are made in fallback mode, which is why the dialog is not visually attached to the Glade parent window. For some odd reason, the screenshot tool gives me only shots of my desktop background when I’m in the Shell – probably because the crappy propietary ATI Catalyst drivers which I have to use because my laptop’s GPU fan goes crazy with the open-source ones. *End of off-topic rant*)

Clicking Bind then makes the magic happen. Last but not least, the mentioned right-click menu also offers the option to remove an established property binding you don’t like it anymore, or replacing it if you like another one better.

So, voila, the whole CRUD family is there! You can now actually use the property binding feature in this basic form. (Okay, the resulting app won’t run anywhere as the code in my GTK+ branch is needed so that GtkBuilder is able to read the new <binding> element, but hey.)

So, where to go from here? For this second half of GSoC, my plan is to implement support for transformation functions, that is, being able to specify the name of a function which may arbitrarily transform the value of a binding’s source property before passing it on to the target. This includes further enhancements in my GTK+ branch – possibly with new GtkBuilder API functions for hooking up transformation functions automatically in the manner of gtk_builder_connect_signals() (I sent a message to gtk-devel-list to discuss this) -, some extensions to Glade’s data model and, naturally, exposing the whole thing in the UI. Should be more than doable in six weeks’ time, should it? After this is done, the agenda will be polishing, polishing, polishing: fixing bugs, gracefully handling edge cases and, lastly, making the UI a bit prettier and more discoverable.

Well, this is it for now. Sorry for taking so long for blogging about all of this, but I had a lot on my plate in the last weeks with my semester coming to an end and course work getting more and more time consuming. But now my lectures are over, next Monday is my last exam, and then I’ll have all the time of the world to bring you plenty of Glade property goodness! Stay tuned…

Glade and property binding: Finally something to see!

Hello fellow GNOMErs,

Since shortly before Google Summer of Code started, I haven’t blogged the least bit about my Google Summer of Code project (GObject property binding support for GtkBuilder and Glade; see my last post or here for what this about). The reason for this is easy: there simply wasn’t anything to show! Not that I didn’t get any coding work done in the first two weeks, I naturally did, and I am even slightly ahead of schedule despite having to study in parallel as my semester does not end until July. (Yay me.)

However, that work was of the boring type: implement support for a new <binding> tag in GTK+’s GtkBuilder class to codify property bindings in GtkBuilder files, writing a small GObject class named “GladeBinding” to represent property bindings in Glade, integrate it into Glade’s existing data model, extend Glade’s GtkBuilder parser to create GladeBinding objects from <binding> tags, and make Glade write such objects to <binding> tags again when saving. Sounds exciting, doesn’t it?

So after all of that, I basically was at the point where you can open GtkBuilder files with <binding>‘s and save them again without losing the binding definitions in the process. So far so good. However, the read binding definitions didn’t actually do anything whatsoever within Glade. Kind of boring. So this week, I devoted my time to make property bindings in Glade ALIVE!

First of all, this means that property bindings read from a GtkBuilder file are now actually created for real. That is, you can change the value of a binding’s source property and the target property is updated to the same value instantly.

The property inspector is now also aware of property bindings. If a property is the target of a binding, its name is now bold and italic, and its value editing contols are disabled (the property’s value depends on the source property, right?). As cherry on top, the tooltip of a bound property shows which property it is bound to.

Lovely, isn’t it? Finally something to see!

All of this work can be found in my “gbinding” branch at git.gnome.org. If you feel like compiling it and giving it a spin (which I would absolutely be happy about!): you can test the new code by taking a GtkBuilder file of your choice (or quickly creating a new one), opening it with a text file, and adding a tag like the following to the object you would like to be the binding target:

<binding to="target-property" from="source-property" source="source-object"/>

with target-property, source-property and source-object replaced with sensible values.

Well, that’s it for now. Next on my TODO list, apart from fixing bugs (which I have likely introduced) and memory leaks (which I have *most likely* introduced), is to make it possible to actually create and edit property bindings from within Glade. This will require me to go back to some boring work again for while (integrate with the undo/redo system and things), but if there is be anything new on the UI side, you’ll hear from me as soon as possible. I promise!

Dear Planet GNOME readers…

… please welcome your new kid on the blog: his name is Denis Washington, and he is a 21-year old Computer Science student living in Berlin, Germany. He is a passionate Linux user since the days of Fedora Core 1 and has made several small contributions to GNOME in the past few years, including participation in the Google Highly Open Participation Contest 2007/2008 (now called Google Code-in). He has been accepted to this year’s GNOME Summer of Code and will try as well as he can to keep you updated about his progress in the next months with his blog. Please be nice to him!

That guy would be me, yes.

So now it’s finally time for me to say: Hello, Planet GNOME! First of all, let me tell you how much of a honor it is to be aggregated here. I’ve been reading the Planet for years and have learned a lot about GNOME, it’s community and the development of Free Software (thanks to everyone who has ever posted here!). Being part of it now feels just awesome!

I would also like to thank the GNOME project for accepting me to Google Summer of Code and thus giving me the possibility to not only post here, but also work full-time on making GNOME rock even harder – and even be paid a impressive amount of cash (for a student) in the process. Special thanks go to Juan Pablo Ugarte, who agreed to be my mentor for the summer (I hope he won’t regret it!). Also, great thanks to Google for even making it possible for the GNOME project to give me the possibility to… erm… just thanks! 🙂

Phew. Now with all the acknowledigments of my limitless gratitude out of the way, let me introduce you to what I am going to work on during the summer. My project is titled GObject property binding support in GtkBuilder and Glade, and this is exactly what I’m going to deliver: the possibility to create bindings between widget properties right within Glade – our beloved GTK+ user interface editor – and save them along with the interface to GtkBuilder files.

Now before you follow the above link to my extremely lengthy Summer of Code application, let you give you a quick overview of the project.

What is this about?

Since 2.26, GLib has a GObject property binding API (named GBinding) which implements a simple form of what the cool kids call reactive programming. Basically, it lets you define that whenever a specified property of a particular GObject (the source) changes its value, a certain other GObject instance property (the target) should be updated accordingly – either by setting it to the same value, or by passing that value to a transformer function which computes the target’s new value. This is a nice thing to have, as this can save a lot of potentially error-prone boilerplate code (writing and connecting signal handlers which call setters on property changes) in favor of a single call to g_object_bind_property() for things like “This widget should be sensitive if that checkbox is enabled” or “The page displayed by this notebook  depends on that radio group’s currently selected item” (among other things).

Now this is nice and all, but it would be even better if you could define bindings between your Glade UI’s widgets graphically and save them as part of GtkBuilder files, without having to write a single line of additional code, wouldn’t it? Well, this is exactly what I’d like to implement this summer. To be exact, you’ll be able to:

  • Right-click a property of a widget in Glade’s property inspector and choose “Bind to Source Property…” (or something similar) to make create a property binding
  • Specify source-to-target transformation functions for property bindings by name which will be automatically connected like gtk_builder_connect_signals() already does for signals
  • See the effect of  the defined property bindings in preview mode and directly in the Glade workspace
  •  Free your code from tedious manual-property-binding signal handlers and calls
  • Thank me for my awesome work 😉

I hope I’ll be able to deliver all of this, including a lot of polish and extensive testing,  in the next 12 weeks; considering that my semester ends only a few weeks after GSoC starts, it won’t be easy, but I’ll certainly do my best.

In any case, I will keep you updated about my progress during this summer. (This is, of course, the reason why I created this blog, and why I was able to sneak into Planet GNOME.) So expect to hear from me again soon!

Best regards,
Denis Washington