
GTK Widgets
Originally uploaded by crafterm.
Following my previous post regarding building a uClibC based Linux system, we'll now look at building a graphical environment suitable for constructing applications that interact with the user.
Quite often no interactivity other than services or web applications are required for embedded devices (eg. DSL boxes and the like), but this is not always the case (eg. when deploying to real computers or constructing live CD's, etc).
For this, I've been experimenting with getting GTK+ running under DirectFB. This has been the approach of the Debian Installer crew over the past few years who have been working on a graphical installer for the Debian project.
DirectFB can run on any VESA compliant video card. There's also some accelerated drivers for particular video cards as well that utilise video hardware for rendering, etc. Since DirectFB runs directly by interfacing with the kernel and doesn't have a networking protocol like X11 amongst other things it can be quite fast.
The Debian installer crew have been using GTK+ 2.0.9 as their toolkit, with some GDK DirectFB patches to allow rendering of widgets onto the framebuffer device. The advantage of this is that there's no need to pack an X11 server (or a need to configure) along with the resultant root filesystem.
There's been some recent activity surrounding getting GTK+ 2.8.3 (ie. the latest GTK+ version) up and running on DirectFB, and this has been the version I've been experimenting with. The image above shows the gtk-demo program running under VMware from a ramdisk that has GTK+ 2.8.3 rendering on a frame buffer.
There's some instructions about how to build GTK+ 2.8.3 in a DirectFB environment available from the DirectFB Wiki. It also includes information about the dependencies that are required such as glib, pkg-config, pango, cairo (with dfb patches), gtk+ (with dfb patches), etc.
The great thing about GTK+ is that it's also themeable with different rendering engines so you can make it look like many different windowing system or give it it's own look and feel.
Also, there's a lot of nice tool support surrounding it.
For example, Glade, the Gnome User Interface Builder, allows you to build GUI's graphically which can then be integrated into your application via generated C/C++ code, or via libglade, which can interpret a Glade definition file (XML) at runtime and create the resultant GUI.
To make things easier, there's even bindings for most popular scripting languages so that you don't have to enter the world of C/C++ to do the dirty work of UI coding. The Debian team have been using the python bindings, but I've been experimenting with the Ruby GTK+ and Glade bindings, which let you script the GUI using Ruby'ism such as blocks, etc.
eg. a simple Ruby script to display a Glade generated GUI:
#/usr/bin/env ruby
require 'libglade2'
def gtk_main_quit puts "Quitting Application" Gtk.main_quit end
Gtk.init
GladeXML.new("mygladeUI.glade") { |handler| method(handler) }
Gtk.main
This simply shows the GUI created within Glade, saved as XML, and handles the gtk_main_quit signal which in my example was a handler name connected to the action of a button.
All in all, all of these tools work fine with uClibC and buildroot, and Glade/GTK/etc provide a very easy way to prototype and use GUI's from C/C++ or your favourite scripting language.
Awesome tools! :)
Posted by crafterm at December 20, 2005 01:46 PM | TrackBack