GTK: Difference between revisions
Line 52: | Line 52: | ||
Below is an example of a GTK+ Hello World program: |
Below is an example of a GTK+ Hello World program: |
||
⚫ | |||
<pre> |
|||
⚫ | |||
'''int''' main( '''int''' argc, |
|||
'''char''' *argv[] ) |
|||
⚫ | |||
'''char''' *argv[] ) |
|||
⚫ | |||
⚫ | |||
GtkWidget * |
GtkWidget *label; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
gtk_main (); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</pre> |
|||
==Future developments== |
==Future developments== |
Revision as of 19:05, 8 December 2006
Developer(s) | GNOME Foundation |
---|---|
Stable release | |
Repository | |
Operating system | Cross-platform |
Type | Widget toolkit |
License | LGPL |
Website | www.gtk.org |
The GIMP Toolkit—abbreviated, and almost exclusively known, as GTK+—is one of the two most popular widget toolkits for the X Window System for creating graphical user interfaces. GTK+ and Qt have supplanted Motif, previously the most widely used X widget toolkit.
GTK+ was initially created for the GNU Image Manipulation Program, a raster graphics editor, in 1997 by Spencer Kimball, Peter Mattis, and Josh MacDonald—all of whom were members of eXperimental Computing Facility (XCF) at UC Berkeley. Licensed under the LGPL, GTK+ is free (and open source) software, and is part of the GNU Project.
Programming languages
GTK+ uses the C programming language, although its designers use an object-oriented paradigm. The GNOME platform bindings provide for C++ (gtkmm), Perl, Ruby, Java and Python (PyGTK) bindings; others have written bindings for many other programming languages (including Ada, D, Haskell, Pascal, PHP, Pike and all .NET programming languages).
Unlike many other widget toolkits, but like Qt, GTK+ isn't based on Xt. The advantage of this is that it allows GTK+ to be available on other systems and to be much more flexible. The disadvantage is that it doesn't have access to the X resource database, which is the traditional way for customizing X11 applications.
Look and feel
The end-user can configure the look of the toolkit, down to offering a number of different display engines. Engines exist which emulate the look of other popular toolkits or platforms, like Windows 95, Motif, Qt or NEXTSTEP.
Environments that use GTK+
- The GNOME environment uses GTK+ as a base, which means that programs written for GNOME use GTK+ as their toolkit.
- Xfce also uses it as its base, though its apps typically do not depend on as many programs. (This is the difference between something being branded as a "GNOME program" and as a "GTK+ program".)
- The GPE Palmtop Environment, Maemo (Nokia's Internet-tablet framework), and Access Linux Platform (a new Palm OS-compatible PDA platform) also use GTK+ as a base.
- One Laptop Per Child project uses GTK+ and PyGTK.
Those desktop environments are not required to run GTK+ programs, though. If the libraries the program requires are installed, a GTK+ program can run on top of other X11-based environments such as KDE or an X11-plus-window manager environment; this includes Mac OS X if X11.app is installed. GTK+ can also run under Microsoft Windows. Some of the more unusual ports include DirectFB and ncurses.
Window managers
Non-graphics-related code
GTK+ initially contained some utility routines that did not strictly relate to graphics, for instance providing such data structures as linked lists and binary trees. Such general utilities, along with the object system called GObject, have now migrated into a separate library, Glib, which programmers use regularly to develop code that does not require a graphical interface.
GTK+ 2
GTK+ 2 has succeeded GTK+ 1. Its new features include improved text rendering using Pango, a new theme engine, improved accessibility using the Accessibility Toolkit, complete transition to Unicode using UTF-8 strings and a more flexible API. However, GTK+ 2 lacks compatibility with GTK+ 1, and programmers must port applications to it. Some programs continue to use GTK+ 1, as the original version remains in use, is faster, is less complex than GTK+ 2, and is more suitable for embedded applications than GTK+ 2[citation needed].
Starting with version 2.8, GTK+ 2 relies on the Cairo library for rendering with vector graphics in GTK+ 2.
GTK+ development
Software development with GTK+ is somewhat systematic, in that handcoding simple and complex graphical elements is very repetitive. Moreover, this process is so systematic that a program, called Glade, allows one to develop graphical applications with an easy to use visual center, such as that used with Visual Basic.
Below is an example of a GTK+ Hello World program:
#include <gtk/gtk.h> int main( int argc, char *argv[] ) { GtkWidget *window; GtkWidget *label; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); label = gtk_label_new("Hello World!!!"); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL); gtk_container_add (GTK_CONTAINER (window), label); gtk_widget_show_all(window); gtk_main (); return 0; }
Future developments
- Project Ridley is an attempt to consolidate several libraries that are currently external to GTK+, including: libgnome, libgnomeui, libgnomeprint22, libgnomeprintui22, libglade, libgnomecanvas, libegg, libeel and gtkglext.
See also
- Gtk#, a .NET API to GTK+
- Gtkmm, a C++ API to GTK+
- PyGTK, Python API to GTK+
- PHP-GTK, a PHP extension
- Ruby-gnome2, a Ruby API to GTK+
- GTK2-Perl, a Perl API to GTK+
- Widget toolkit
- Qt
- wxWidgets
- FLTK
- FOX toolkit
- VCF
- Ultimate++
- searchmonkey, a Gtk based search engine
External links
- GTK+ homepage.
- GTK+ for Win32, also offers a Glade port.
- Gtk+ for Mac OS X, a native port to be used without X11.
- GtkAda, an Ada API to GTK+.
- gtkmm, a C++ API to GTK+.
- Gtk2-Perl, a Perl API to GTK+ 2.x.
- PHP-GTK, a PHP API to GTK+.
- Gtk2Hs, a Haskell API to GTK+.
- Java-GNOME, a Java API to GTK+ 2.x.
- GTK+ Forum, an unofficial forum archiving all GTK+ mailing lists.
- Runtime for Windows and package for Dev-Cpp.
- LablGTK is an Objective Caml interface to gtk+.
- Intro to GTK with C#