Quick viewing(Text Mode)

• GTK (GIMP Toolkit) Is a Library for Creating Graphical User Interfaces

• GTK (GIMP Toolkit) Is a Library for Creating Graphical User Interfaces

GTK+

• GTK (GIMP Toolkit) is a for creating graphical user interfaces. • It is licensed using the LGPL license, – so you can develop open , , or even commercial non-free software using GTK without having to spend anything for licenses or royalties. interface to GTK

• The GTK interface is in C • Using C++ with GTK – First, you can use only the C subset of C++ when interfacing with GTK and then use the C interface. – Second, you can use GTK and C++ together by declaring all callbacks as static functions in C++ classes, and again calling GTK using its C interface. GtkWidgets

• Familiar GUI components like –Window –Menus –Frame – Buttons –Labels – Slider – – Dialogs – File selectors –Etc. Signal, event, and Callback

• Widgets fires signals and events. • Client register callbacks for events and signals fired by widgets • Callbacks handle these signals by invoking domain processing Hello, world • gtk_init (&argc, &argv); – Initialize the GTK lib – Should be the first line before any other GTK related API call. • window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_show (window); – create and display a window – Default window w/o children sized to 200x200. • gtk_main (); – enters the GTK main processing loop – When control reaches this point, GTK will sleep waiting for X events (such as or key presses), timeouts, or file IO notifications to occur. – In our simple example, however, events are ignored. HelloGTK

• g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL); – delete_event Ù X – If delete_event returns FALSE, destroy signal issued. • g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL); – Register callback “destroy” HelloGTKObject

• Wrap all callbacks as static member functions of “controller” classes – Why static? Since callbacks must be registered prior to being called by the main loop – Static mf allows the registration to be done without object • Wrap widgets into “view” classes – Register callbacks in view constructors – To hide GtkWidget details