background: #eeeeee; border: solid 1px #aaaaaa; padding: 0.5em; } .programlisting { background: #eeeeff; border: solid 1px #aaaaff; padding: 0.5em; } .variablelist { padding: 4px; margin-left: 3em; } .navigation { background: #ffeeee; border: solid 1px #ffaaaa; margin-top: 0.5em; margin-bottom: 0.5em; } .navigation a { color: #770000; } .navigation a:visited { color: #550000; } .navigation .title { font-size: 200%; }

Writing Applets

Table of Contents
Hello World Applet
Bonobo Activation .server Files For Applets
Defining a Popup Context Menu
Detecting Changes in the Panel.
Session/Preference Saving.
Multiple Applets

Writing applets is very simple. You take some boiler plate code like below, change a couple of things and write the code that implements your widgetry. The hardest part is writing your widgetry - and its completely up to yourself how hard that should be.


Hello World Applet

As usual, following the pointless tradition of starting with an example of how get 'Hello World' on the screen in some form, here's just about the simplest applet you could write.

#include <string.h>

#include <panel-applet.h>
#include <gtk/gtklabel.h>

static gboolean
hello_applet_fill (PanelApplet *applet,
		   const gchar *iid,
		   gpointer     data)
{
        GtkWidget *label;

        if (strcmp (iid, "OAFIID:My_HelloApplet") != 0)
		return FALSE;

        label = gtk_label_new ("Hello World");
	gtk_container_add (GTK_CONTAINER (applet), label);

	gtk_widget_show_all (GTK_WIDGET (applet));

        return TRUE;
}


PANEL_APPLET_BONOBO_FACTORY ("OAFIID:My_HelloApplet_Factory",
                             PANEL_TYPE_APPLET,
                             "The Hello World Applet",
                             "0",
                             hello_applet_fill,
                             NULL);
      

The code here is very similar to writing a normal Bonobo control. You define a factory using PANEL_APPLET_BONOBO_FACTORY(), passing it a factory function like hello_applet_fill().

libpanel-applet automatically creates a #PanelApplet object for you, passing this to your factory method. Here, you should fill the applet with your widgets just like a #GtkBin. For example, if you were writing a cdplayer applet you would create a #GtkHBox, pack the hbox with the cdplayer buttons and in turn add the hbox to the applet.