Embedded Linux - PowerPoint PPT Presentation

lerato
embedded linux n.
Skip this Video
Loading SlideShow in 5 Seconds..
Embedded Linux PowerPoint Presentation
Download Presentation
Embedded Linux

play fullscreen
1 / 18
Download Presentation
Embedded Linux
152 Views
Download Presentation

Embedded Linux

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Embedded Linux GTK+

  2. Overview • Introduction • Installation • Tutorials • References: • http://www.gtk.org/ • Ch16 POSIX Threads in “Beginning Linux Programming” • http://zetcode.com/tutorials/gtktutorial/

  3. What is GTK+? • Cross-platform widget toolkit for creating GUI • GTK: The GIMP Toolkit • GTK+ was initially created for the GNU Image Manipulation Program (GIMP) in 1997 • GTK+ is written in C • GTK+ bindings include C++, Perl, Ruby, Java, Python, C# and PHP • LGPL2: free to use for non-commercial and for commercial softwares

  4. Architecture • Over time GTK+ has been built up to be based on four libraries, also developed by the GTK+ team: Glib, a low level core library Pango, a library for layout and rendering of intl. text Cairo, a library for 2D graphics ATK, a library for a set of interfaces providing accessibility

  5. Features • Stability • Cross Platform: GNU Linux/Unix, Windows, Mac OS X • Various Language Bindings • Mobile: GMAE (GNOME Mobile & Embedded) • Accommodating: Native Look and Feel, Theme, Thread-safe, Object Oriented Approach, etc • Interfaces: Various Widgets • Foundations: GLib based ...

  6. GTK+ Object Model • Inheritance Hierarchy GObject GtkObject GtkWidget GtkContainer GtkBin GtkWindow

  7. Building the Latest GTK+ from Sources • Installation Guide in GTK+ Reference Manual • http://library.gnome.org/devel/gtk/stable/gtk-building.html • Installation Steps • Download the latest sources • GTK+ 2.14, GLib 2.18, Pango 1.20 • Extract the sources • tar xvfjgtk+-2.0.0.tar.bz2 • Configure the sources: • ./configure --prefix=/usr/local • make • make install

  8. How to Use • Environment Variables • export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig“ • pkg-config takes care of C flags and Linker flags • pkg-config --cflagsgtk+-2.0 • pkg-config --libs • cc -o simple simple.c `pkg-config --libs --cflagsgtk+-2.0` • Terms • GTK: GIMP Toolkit • GIMP: GNU Image Manipulation Program • GNOME: GNU Network Object Model Environment • GDK: GIMP Drawing Kit • gdk-pixbuf: a library for client-side image manipulation

  9. How to Learn GTK+ Programming • GTK+ Tutorial • http://library.gnome.org/devel/gtk-tutorial/stable/ • http://zetcode.com/tutorials/gtktutorial/ • GTK+ Demo • Run ‘gtk-demo’! • Copy gtk-demo folder to your working directory and examine the sources. • GTK+ Reference Manual • /usr/local/share/gtk-doc/html/gtk/index.html • http://library.gnome.org/devel/gtk/stable/

  10. Ex: Simple GTK+ Application • simple.c #include <gtk/gtk.h> int main( intargc, char *argv[]) { GtkWidget *window; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_show(window); gtk_main(); return 0; }

  11. Ex: Hello World with a Button #include <gtk/gtk.h> static void hello( GtkWidget *widget, gpointer data ) { printf("Hello, World!\n"); } int main( intargc, char *argv[] ) { gtk_init (&argc, &argv); GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", gtk_main_quit, NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 10); GtkWidget *button = gtk_button_new_with_label ("Hello World"); g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL); gtk_container_add (GTK_CONTAINER (window), button); gtk_widget_show (button); gtk_widget_show (window); gtk_main(); return 0; } • simple.c gtk_widget_show_all (window); hello1.c

  12. Ex: Adding Another Button #include <gtk/gtk.h> static void hello( GtkWidget *widget, gpointer data ) { printf(“%s: Hello, World!\n“, (char*)data); } int main( intargc, char *argv[] ) { gtk_init (&argc, &argv); GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", gtk_main_quit, NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 10); GtkWidget *button1 = gtk_button_new_with_label ("Hello, World"); g_signal_connect (button1, "clicked", G_CALLBACK (hello), “B1”); gtk_container_add (GTK_CONTAINER (window), button1); GtkWidget*button2 = gtk_button_new_with_label ("Hello, Again"); g_signal_connect (button2, "clicked", G_CALLBACK (hello), “B2”); gtk_container_add (GTK_CONTAINER (window), button2); gtk_widget_show_all(window); gtk_main(); return 0; } • simple.c hello2.c

  13. Oops, GtkWindow may have only child! • GTK+ Object System

  14. GtkBox • GTK+ Object System Start End GtkHBox End GtkVBox Start

  15. Ex: GtkBox - GtkHBox, GtkVBox • two_buttons.c Border Width GtkWidget*window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window),"Life is Beautiful"); gtk_container_set_border_width(GTK_CONTAINER(window), 10); g_signal_connect( window, "destroy", G_CALLBACK(gtk_main_quit), NULL ); GtkWidget*button1 = gtk_button_new_with_label("Hello, World!"); g_signal_connect( button1,"clicked",G_CALLBACK(button_clicked), "1" ); GtkWidget*button2 = gtk_button_new_with_label("Hello, Again!"); g_signal_connect( button2,"clicked",G_CALLBACK(button_clicked), "2" ); GtkWidget*hbox = gtk_hbox_new( TRUE, 10 ); gtk_box_pack_start( GTK_BOX(hbox), button1, TRUE, TRUE, 5 ); gtk_box_pack_start( (GtkBox*)hbox, button2, TRUE, TRUE, 20 ); gtk_container_add(GTK_CONTAINER(window), hbox); Spacing Homogenous Expand Padding Fill

  16. Ex: GtkBox - GtkHBox, GtkVBox • GtkHBox Packing Rule Padding Padding Border Width Spacing

  17. Ex: GtkHBox • Border Width=0, Spacing=10, Padding=5 • Homogeneous: equal size (including padding) • Expand: maximize widget area (including padding) • Fill: fill the widget area (except padding)

  18. GtkEntry