Review: Foundations of GTK+ Development

Davyd Madely reviews the book Foundations of GTK+ Development by Andrew Krause, and published by Apress.

There aren’t many books available that cover GTK+ and even fewer of them are up to date. For a long time, the only book covering GTK+ 2.0 was Matthias Warkus’ The Official GNOME 2 Developer’s Guide from No Starch Press. Now Andrew Krause, a computer engineering student from Pennsylvania State University, has written Foundations of GTK+ Development, published by Apress. Mr. Krause was very kind in providing me with a complementary copy to review.

While by no means the heaviest book on my shelf, Foundations of GTK+ Development weighs in at 630 pages with 13 chapters and 6 appendices. Krause has the right idea with his chapters. The book first covers terminology and what you need to develop GTK+ programs. The second chapter then gives the archetypical “hello world” example, important for the budding GTK+ developer to feel a sense of accomplishment. It introduces the fundamental concepts of GTK+: events, the mainloop, signals and widget heirachies. Chapters 3-5 cover a wide range of GTK+ widgets, starting with packing containers (and how box packing works in GTK+), many of the common widgets you see day to day and finally dialogs. Chapter 6 touches on the functionality provided in GLib. Chapters 7 and 8 cover GtkTextView and GtkTreeView respectively. 9 is menus and toolbars and 10 covers Glade. Chapter 11 briefly touches on writing custom GTK+ widgets and chapter 12 cleans up any miscellaneous items. Chapter 13 then looks at some example apps to discuss how they work.

The book starts with a reasonable overview of X11, GTK+ and its main components (GLib, GObject, GDK, Pango and ATK, but not Cairo) and makes mention of the language bindings. Though be warned, while the bindings are mentioned, this is very much a book for C programmers, and those who are working with a language binding may find it of only minimal usefulness. Krause attempts to explain how to get GTK+ development packages from
your vendor or how to build and install them yourself, but I don’t believe it covers this in enough detail. There is neither a discussion of what packages to install or what the set of packages you will need to build are called. Prospective developers will find it confusing to set up their environment and will likely require extra help.

Krause takes the time to provide some words of caution to the unwary, beginning, for example with regards to widget layout. He also references the Human Interface Guidelines a handful of times when discussing the design of user interfaces, as well as providing his own advice.

Chapter 11 covers writing a custom widget, but I personally found this chapter to be a little bit disappointing as it seems to diverge from GTK+ best practice. For example, it doesn’t use G_DEFINE_TYPE(), or consistently demonstrate functionality like GLib’s runtime type checking for public functions. In my opinion, The Official GNOME2 Developer’s Guide contains a better treatment of GObject, although it doesn’t cover creating custom widgets. The drawing functions described in this chapter are the old GDK drawing functions rather than the Cairo drawing API. Cairo is instead briefly covered in the next chapter under Additional GTK+ Widgets after GtkPrint.

Krause comprehensively covers most, if not all, of the UI widgets available in GTK+, along with an excellent chapter detailing most of the features and data structures provided by GLib. Unfortunately the book does not spend much time discussing GTK+ best practices nor does it provide canonical design patterns for some of the widgets (e.g., GtkRadioButton, a widget that many inexperienced GTK+ programmers get confused by). The book covers Glade (version 3.0) and libglade, but does not cover libgnome/ui, GConf, GnomeVFS, libmlx2 or other GNOME-related technologies (which are covered in The Official GNOME2 Developer’s Guide).

I like the //Test Your Understanding// section given at the end of each chapter. These sections present small exercises to the reader that allows him or her to put what they’ve read into practice (e.g. connecting a signal or creating a menu). Brief answers to these exercises are provided in the back of the book with source code available on the Web. Each chapter also ends with a summary of what was in the chapter.

The last chapter of the book discusses the construction of several small sample applications: a simple file browser, a calculator, a hangman game, a wrapper around `ping` and a calendar. Hints are provided for each application so that the reader can attempt to implement the utility him or herself, although source code is provided on the Web. The chapter then suggests where to go for further help. Five of the six appendices are GTK+ reference documentation: properties, signals, styles, Pango markup, stock items and GError types. Unfortunately the book never points budding developers to awesome tools like Devhelp.

The publisher, Apress, has also made a PDF eBook version available for purchase. The eBook is locked using the email address you provide when you purchase it (which is supported by Evince) and you are able to print it, if you so desire. The PDF does have bookmarks for the chapters, but does not have hyperlinked cross-references or other nice features. Unless you particularly like eBooks, or can’t get a hardcopy where you are, I’d spend the extra $8 for the real thing.

On the whole, the book had both excellent and disappointing aspects. Generally, I like the order in which the topics were presented, though occasionally the book gets bogged down in details that otherwise wouldn’t have a home; and some important concepts, like Interfaces, end up introduced midway through a chapter where they are easily missed by the reader. I like the summaries and exercises and the book is reasonably up to date, covering GTK+ 2.10 and Glade 3.0. Unfortunately the book does not really cover major parts of GTK+’s underlying infrastructure like Pango and Cairo as explicitly as I think it should. Boiling it all down, this is not the book for someone who knows GTK+ to improve their skills, but as its title suggets, will provide the foundations for someone looking to learn GTK+, although not perhaps the canonical GTK+ developer’s style. I am giving it 3.5 feet out of 5.

More information:

About the author

Davyd Madeley is an electronic engineer and computer scientist from Perth, Western Australia. He has previously been the GNOME Applets maintainer and has been an occasional author for GNOME Journal. His interests are UI design, machine learning, electronics and playing the tenor saxophone.

Discuss this story with other readers on the GNOME forums.


Posted on December 4, 2007, in December 2007. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: