An Introduction to the GIMP Tool Kit

March 1st, 1998 by Otto Hammersmith in

The purpose of this article is to give a short overview of what gtk+ is, what it can do and where to gather more information.
Your rating: None Average: 5 (1 vote)

The GIMP tool kit gtk+ is the GUI libraries written for use in the GIMP as an alternative to Motif. (See the GIMP series of articles by Michael Hammel in the November to January issues of LJ.) Although gtk+ was created for the GIMP, it can be used for any GUI application. In fact, recently the gtk+ distribution has been split out from the GIMP distribution in anticipation of the 1.0 release.

What Can gtk+ Do?

Like all GUI tool kits, gtk+ provides a variety of GUI components, a.k.a. widgets. One thing that sets gtk+ apart from tool kits such as Motif is the breadth of the widgets provided. Naturally, all tool kits provide some form of a button widget. gtk+ also provides components such as tabbed notebooks and fully functional color pickers not included in the core widgets of other tools kits. Screen shots are provided in Figures 1 and 2 as examples of the appearance of gtk+ widgets.

Figure 1. Notebook Widget

Figure 2. Color Selection Widget

Another advantage of gtk+ is that it's not limited to a single language. Even though gtk+ is written in C and was originally intended for use from C, there are bindings to many other languages. Just a few of them are C++, Objective C, Python, Scheme, Perl—the list goes on and on with new additions frequently. Chances are someone has already started on bindings for your favorite language.

Best of all, gtk+ is under the Library GNU Public License (LGPL), so there are absolutely no licensing concerns when writing software.

The Pieces

The GIMP tool kit is made up of three different layers. Each layer has its own distinct functionality and depends on the layers below it. The three layers are:

  1. glib: This is a support library that is of general usefulness in many C programs, even non-GUI applications. Most of its utilities are common data structures, such as linked lists (GList), and convenience functions, to ease porting between Unices, e.g., wrappers around malloc and free (gmalloc and gfree).

  2. gdk: This library is basically a thin layer over Xlib and some of Xt to handle the basics of drawing on the X display and handling X events. Having this library means that applications writers never have to see the underlying X libraries to get work done. This library also contains several useful functions for things like handling timers, polling file descriptors and more.

  3. gtk: This library is the meat of gtk+, where all the GUI elements are defined. This library relies heavily on gdk and glib to do its job.

Learning gtk+

For someone with experience in C programming, gtk+ should be fairly easy to pick up. The internals of gtk+ use some advanced C features like function pointers and some tricks with structs, but application writers should never need to worry about the internals of gtk+. Naturally, any experience with other GUI tool kits (especially Motif) will make learning gtk+ easier.

For a long time the only documentation of gtk+ was the source code, and the sample application, the GIMP. Fortunately, the gtk+ tutorial at http://levien.com/slow/gtk/ has filled that void.

However, gtk+ is a moving target (still being developed) so be wary. If there's any doubt about the validity of some documentation, always double check it against the source code. And, as always, nothing can beat actually writing code to test an option out.

There is also a mailing list dedicated to discussing gtk+. To subscribe, send mail to gtk-list-request@redhat.com with a subject of “subscribe email-address”, replacing email-address with your e-mail address.

gtk+ Status

When learning about gtk+, remember that it is still under development, but it is certainly usable for non-trivial applications, the GIMP, for example. There are still plenty of minor bugs and even a few major ones you'll have to work around. For example, at the time of this writing, the text widget still needed a lot of work. But in the two months or more before anyone will read this article in print a lot can happen. The best place to check on the current status of the gtk+ libraries and to get the source is at http://www.gimp.org/gtk/.

Otto is a developer at Red Hat Software who is currently very busy with the next release of Red Hat Linux. He can be contacted by e-mail at otto@redhat.com.

__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
photo retouching's picture

this article

On June 25th, 2009 photo retouching (not verified) says:

I have just started reading up about gimp and realise that it is a powerful image edit tool!

Anonymous's picture

Re: An Introduction to the GIMP Tool Kit

On October 6th, 2004 Anonymous says:

search about "GIMP"

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.







Read this issue