Presentation is loading. Please wait.

Presentation is loading. Please wait.

GTK + Programming.

Similar presentations


Presentation on theme: "GTK + Programming."— Presentation transcript:

1 GTK + Programming

2 What is GTK+ program? The GTK+ is a library for creating graphical user interfaces. The library is created in C programming language. The GTK+ library is also called the GIMP Toolkit. Today, most of the GUI software in the open source world is created in Qt or in GTK+.

3 Cont.. The GTK+ is an object oriented application programming interface. The object oriented system is created with the Glib object system, which is a base for the GTK+ library. The GObject also enables to create language bindings for various other programming languages. Language bindings exist for C++, Python, Perl, Java, C# and other programming languages.

4 Libraries The GTK+ itself depends on the following libraries. Glib
Pango ATK GDK GdkPixbuf Cairo

5 Cont.. Glib - a general purpose utility library.
It provides various data types, string utilities, enables error reporting, message logging, working with threads and other useful programming features. Pango - a library which enables internationalization. ATK - accessibility toolkit. This toolkit provides tools which help physically challenged people work with computers.

6 Cont.. GDK - a wrapper around the low-level drawing and windowing functions provided by the underlying graphics system. On Linux, GDK lies between the X Server and the GTK+ library. GdkPixbuf library - toolkit for image loading and pixel buffer manipulation.  Cairo - a library for creating 2D vector graphics.

7 Compiling GTK+ applications
To compile GTK+ applications, we have a handy tool called pkg-config. The pkg-config returns metadata about installed libraries. The pkg-config program retrieves information about packages from special metadata files. Command- gcc -o simple simple.c `pkg-config --libs --cflags gtk+-2.0`

8 First programs in GTK+ We will show a basic window.
#include <gtk/gtk.h> int main( int argc, char *argv[]) { GtkWidget *window; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_show(window); gtk_main(); return 0; }

9 Explaination We create a GtkWindow widget.
The window type is GTK_WINDOW_TOPLEVEL. Toplevel windows have a titlebar and a border. They are managed by the window manager. After we have created a widget, we must show it. Main code enters the GTK+ main loop. From this point, the application waits for events to happen.

10 GTK+ layout management
When we design the GUI of our application, we decide what widgets we will use and how we will organize those widgets in the application. To organize our widgets, we use specialized non visible widgets called layout containers. They are  GtkAlignment, GtkFixed, GtkVBox and GtkTable.

11 GtkFixed, GtkVBox, GtkHBox
The GtkFixed container places child widgets at fixed positions and with fixed sizes. This container performs no automatic layout management. For example games, specialized applications that work with diagrams, resizable components that can be moved (like a chart in a spreadsheet application), small educational examples. GtkVBox is a vertical box container. It places its child widgets into a single column.  GtkHBox  is a very similar container. This container places its child widgets into a single row.

12 GtkTable, GtkAlignment
The GtkTable widget arranges widgets in rows and columns. The GtkAlignment container controls the alignment and the size of its child widget.

13 GTK+ events and signals
GTK+ library is an event driven system. All GUI applications are event driven. If there is no event, the application waits and does nothing. In GTK+ an event is a message from the X server. When the event reaches a widget, it may react to this event by emitting a signal. The GTK+ programmer can connect a specific callback to a signal. The callback is a handler function, that reacts to a signal.

14 Ex: We have two signals. The clicked signal and the destroy signal.
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button_clicked), NULL); We use the g_signal_connect() function to connect the clicked signal to the button_clicked() callback.

15 GTK+ dialogs A dialog is used to input data, modify data, change the application settings etc. Dialogs are important means of communication between a user and a computer program.

16 Cont.. Message dialogs GtkAboutDialog GtkFontSelectionDialog
Message dialogs are convenient dialogs that provide messages to the user of the application.  GtkAboutDialog The GtkAboutDialog displays information about the application. GtkFontSelectionDialog The GtkFontSelectionDialog is a dialog for selecting fonts. GtkColorSelectionDialog GtkColorSelectionDialog is a dialog for selecting a color.

17 GTK+ Widgets Widgets are basic building blocks of a GUI application.
For example a button, a check box or a scroll bar. The GTK+ toolkit's philosophy is to keep the number of widgets at a minimum level. More specialized widgets are created as custom GTK+ widgets.

18 Cont.. GtkButton GtkCheckButton GtkFrame GtkLabel
GtkButton is a simple widget, that is used to trigger an action. GtkCheckButton GtkCheckButton is a widget, that has two states. On and Off. The On state is visualized by a check mark. GtkFrame GtkFrame is a bin with a decorative frame and optional label GtkLabel displays text.


Download ppt "GTK + Programming."

Similar presentations


Ads by Google