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.
- glib - this is a low level library, actually a set of utilities
for handling memory allocation, strings, linked lists and other basic stuff
that has absolutely nothing to do with graphics and which could be useful in
a wide range of programming endeavors.
- GDK - this is a low level graphics library that lies beneath other
parts of GTK. If you only need to use prefab GTK widgets you won't need to
know about it, but the truth is that every program I have ever written needed
to access it.
- Gnome - Can you write a GUI without worrying about Gnome?
Maybe and maybe not, there are things like the gnome canvas (which gets you
involved quickly with GDK objects) that you may want to mix with GTK widgets
and so you must learn to work on all 3 levels.....
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)
Books
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.
- GTK+/Gnome Application Development by Havoc Pennington, 1999 --
Maybe my favorite, GTK+ 1.2, in depth and well organized
- GTK+ programming in C by Syd Logan, 2001 --
Useful, and known as the naked lady book. This covers GTK+ 1.2
- Developing Linux Applications with GTK+ and GDK by Eric Harlow, 1999 --
A nice book, and he doesn't neglect GDK, but from the GTK+ 1.2 era.
- The Official Gnome 2 Developer's Guide by Mattius Warkus, 2004 --
Well reviewed and it does cover Gnome 2.0, but neglects GDK
Feedback? Questions?
Drop me a line!
Tom's Computer Info / [email protected]