gui with gtk+ under linux fanfan xiong. introduction gtk+ (gimp toolkit) : a library for creating...

16
GUI With GTK+ Under GUI With GTK+ Under Linux Linux Fanfan Xiong

Upload: camron-payne

Post on 05-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

GUI With GTK+ Under LinuxGUI With GTK+ Under LinuxFanfan Xiong

Page 2: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Introduction Introduction

GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI)

Two examples developed with GTK+

Other GUI software in Linux

Page 3: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Basic Knowledge of GTK+Basic Knowledge of GTK+

GTK is essentially an object oriented application programmers interface (API). Although written completely in C, it is implemented using the idea of classes and callback functions (pointers to functions).

GLib: A third component. It contains a few replacements for some standard calls, as well as some additional functions for handling linked lists, etc.

Page 4: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

credited to siva

Download and Install GTK+Download and Install GTK+ Get glib-1.2.10.tar and gtk+-1.2.10.tar from www.gtk

.org. copy glib and gtk source gz and untar using xvf, then cd glib* ./configure --prefix=/home/fanfan/local make make install export LD_LIBRARY_PATH=/home/fanfan/local/lib cd gtk* ./configure --prefix=/home/fanfan/local --with-glib-refix=/home/fanfan/local make make install

Page 5: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

credited to siva

Download and Install GTK+Download and Install GTK+(cont)(cont)Then create a gtkenv.sh

export LD_LIBRARY_PATH=/home/fanfan/local/lib export PATH=/home/fanfan/local/bin:$PATH alias ggcc='gcc -Wall -g `gtk-config --cflags` `gtk-config --libs`'

Download gqcam-0.8.tar from http://webcam.soruceforge.net/ make

start gqcam

Page 6: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

One Simple Example One Simple Example #include <gtk/gtk.h> (1)

int main( int argc, char *argv[] ){ GtkWidget *window; gtk_init (&argc, &argv); (2) window = gtk_window_new (GTK_WINDOW_TOPLEVEL); (3) gtk_widget_show (window); gtk_main (); (4) return(0);}

Page 7: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Example AnalysisExample Analysis

(1) The gtk.h file declares the variables, functions, structures, etc. that will be used in GTK applications. All programs should include gtk/gtk.h

(2) This function initializes the library for use, sets up default signal handlers, and checks the arguments passed to your application on the command line

(3) create and display a window (4) enters the GTK main processing loop

Page 8: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Signals and CallbacksSignals and Callbacks

GTK is an event driven toolkitPassing of control is done using the idea of

"signals“set up a signal handler to catch these

signals and call the appropriate functiongint gtk_signal_connect( GtkObject *object,

gchar *name, GtkSignalFunc func, gpointer func_data );

Page 9: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Example 2: Hello World!Example 2: Hello World! #include <gtk/gtk.h>

void hello( GtkWidget *widget, gpointer data ){ g_print ("Hello World\n"); }

gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ){ g_print ("delete event occurred\n"); return(TRUE); }

void destroy( GtkWidget *widget, gpointer data ){ gtk_main_quit(); }

Page 10: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

1. int main( int argc, char *argv[] ){ 2. GtkWidget *window; 3. GtkWidget *button; 4. gtk_init(&argc, &argv); 5. window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 6. gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL); 7. gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (destroy), NULL); 8. gtk_container_set_border_width (GTK_CONTAINER (window), 10); 9. button = gtk_button_new_with_label ("Hello World"); 10. gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (hello), NULL); 11. gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (window)); 12. gtk_container_add (GTK_CONTAINER (window), button); 13. gtk_widget_show (button); 14. gtk_widget_show (window); 15. gtk_main (); 16. return(0);}

Page 11: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Compiling Hello WorldCompiling Hello World

To compile use:gcc -Wall -g helloworld.c -o helloworld `gtk-config --cflags` `gtk-config --libs`

Page 12: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Output of Example 2Output of Example 2

Page 13: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Other GUI Software for LinuxOther GUI Software for Linux

Glade : An application for creating graphical user interfaces that use the Gtk+ and GNOME libraries

KDevelop: An Integrated Development Environment provides many features that developers need as well as it wraps the functionality of third party projects such as make and the GNU C++ Compilers and makes them aninvisible, integrated part of the development process

Page 14: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Glade in Mandrake Linux 8.1Glade in Mandrake Linux 8.1

Page 15: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

KDevelop in Mandrake Linux 8.1KDevelop in Mandrake Linux 8.1

Page 16: GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed

Where to Get More InformationWhere to Get More Information

Tony Gale and Ian Main, “GTK+ 1.2 Tutorial”, http://www.gtk.org

Eric Harlow, “Developing Linux Applications”, New Riders

Raph Levien, [email protected]

Peter Mattis, [email protected]