March 5, 2018

GTK programming

I do virtually all of my GTK programming in Ruby. The alternative is writing in C, and that is what the actual Gnome/GTK documentation describes. However, for the sorts of things I want to do, a high level language like Ruby makes more sense - to me anyway.

This produces somewhat of a problem though, since the primary documentation describes the C interface. In the case of GTK2, this is not so bad as good "ruby gnome" documentation exists. If you want to program using Ruby and GTK3, the situation is not so good.

For all I know, some of these fundamental concepts may have changed with the advent of GTK3. GTK3 is allegedly designed to work better with Wayland. GTK3 uses (of all things) CSS in some places, which sounds frightening to me.

Gnome, GTK, and GTK versions

I simply ignore Gnome as an entity in itself and write GTK2 programs. In my point of view, Gnome is a nuisance higher layer that might be important if you are enthused about integrating your applications into one of the Gnome desktops. I abandoned Gnome (as many did) with the advent of the horrid Gnome 3 debacle, so any kind of gnome compliance is meaningless to me.

At this point in time, gtk2 is getting pretty old and even gtk3 has been around for several years. People are talking about gtk4. There is nothing stopping you though at this point in time from continuing to use gtk2, and in the case of the ruby bindings this offers the advantage of actual documentation. If you want to use ruby with gtk3, you are on your own. You can look at the GTK3 documentation for the C interface along with the ruby gtk3 source code. Alternately, what works pretty well is to simply code for gtk2, then try to run that code requiring the gtk3 bindings. You get nice deprecation warnings that guide you into gtk3.

Case study with Ruby GTK2

These days ruby-GTK is ancient history, and people are using GTK2. In fact there is now a GTK3 gem for ruby, and discussions about GTK4, though I don't see any sign of a GTK4 gem.

Ruby Gnome/GTK resources

Gnome/GTK resources (C language API)


I have the following four books on GTK programming, and have gotten some use out of them. They are from the GTK 1.2 era, so they won't be of much use as API references, but they cover basic concepts well. Also they are available cheaply as used books. Interestingly, no new books have come out over the past 12 years or more, so these are still your only choices. So you use online resources and save money.

I particularly like Havoc Pennington's book -- it just seems to be the best organized and is more than a "here is how to put together a bunch of buttons, labels, and entry widgets" kind of book.

Feedback? Questions? Drop me a line!

Tom's Computer Info /