The GNOME Panel Libraries | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
The simplest applet one can write would be along the lines of:
Example 1. hello-world_applet
#include <config.h> #include <applet-widget.h> int main(int argc, char **argv) { GtkWidget *applet; GtkWidget *label; /* Initialize the i18n stuff */ bindtextdomain (PACKAGE, GNOMELOCALEDIR); textdomain (PACKAGE); /* intialize, this will basically set up the applet, corba and call gnome_init */ applet_widget_init("hello-applet", NULL, argc, argv, NULL,0,NULL); /* create a new applet_widget */ applet = applet_widget_new("hello-applet"); /* in the rare case that the communication with the panel failed, error out */ if (!applet) g_error("Can't create applet!\n"); /* create the widget we are going to put on the applet */ label = gtk_label_new(_("Hello There!")); gtk_widget_show(label); /* add the widget to the applet-widget, and thereby actually putting it "onto" the panel */ applet_widget_add (APPLET_WIDGET (applet), label); gtk_widget_show (applet); /* special corba main loop */ applet_widget_gtk_main (); return 0; } |
This creates an applet which just sits on the panel, not really doing anything, in real life the label would be substituted by something which actually does something useful. As you can see the applet doesn't really take care of restarting itself.