GUI With GTK Under Linux - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

GUI With GTK Under Linux

Description:

GUI With GTK+ Under Linux Fanfan Xiong Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed with GTK+ Other ... – PowerPoint PPT presentation

Number of Views:106
Avg rating:3.0/5.0
Slides: 17
Provided by: cisTempl
Learn more at: https://cis.temple.edu
Category:
Tags: gtk | gui | linux | under

less

Transcript and Presenter's Notes

Title: GUI With GTK Under Linux


1
GUI With GTK Under Linux
  • Fanfan Xiong

2
Introduction
  • GTK (GIMP toolkit) A library for creating
    graphical user interfaces(GUI)
  • Two examples developed with GTK
  • Other GUI software in Linux

3
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.

4
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

5
Download and Install GTK(cont)
  • Then create a gtkenv.sh
  • export LD_LIBRARY_PATH/home/fanfan/local/lib
  • export PATH/home/fanfan/local/binPATH
  • alias ggcc'gcc -Wall -g gtk-config --cflags
    gtk-config --libs'
  • Download gqcam-0.8.tar from http//webcam.sorucefo
    rge.net/ make
  • start gqcam

6
One Simple Example
  • include ltgtk/gtk.hgt (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)

7
Example 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

8
Signals and Callbacks
  • GTK is an event driven toolkit
  • Passing of control is done using the idea of
    "signals
  • set up a signal handler to catch these signals
    and call the appropriate function
  • gint gtk_signal_connect( GtkObject object,
  • gchar name,
  • GtkSignalFunc func,
  • gpointer func_data )

9
Example 2 Hello World!
  • include ltgtk/gtk.hgt
  • 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()

10
  • 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)

11
Compiling Hello World
  • To compile use
  • gcc -Wall -g helloworld.c -o helloworld
  • gtk-config --cflags gtk-config --libs

12
Output of Example 2

13
Other 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

14
Glade in Mandrake Linux 8.1

15
KDevelop in Mandrake Linux 8.1

16
Where 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, raph_at_acm.org
  • Peter Mattis, petm_at_xcf.berkeley.edu
Write a Comment
User Comments (0)
About PowerShow.com