Basic applet developement



Hi all.
I am attempting my first Gnome applet creation and I found a great
tutorial at http://projects.gnome.org/ORBit2/appletstutorial.html .
Unfortunately, I am stuck where the example goes to load an image. I can
compile the applet and make it run but when I add it to the Gnome bar it
doesn't show anything. I have some printf's in the code and those work on
the console.
Here's the code I am working on:

#include <string.h>
#include <stdio.h>

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

static gboolean
  on_button_press (GtkWidget      *event_box,
                         GdkEventButton *event,
                         gpointer        data)
  {
        static int window_shown;
        static GtkWidget *window, *box, *image, *label;
        /* Don't react to anything other than the left mouse button;
           return FALSE so the event is passed to the default handler */
        if (event->button != 1)
                return FALSE;

        if (!window_shown) {
                window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
                box = GTK_BOX (gtk_vbox_new (TRUE, 12));
                gtk_container_add (GTK_CONTAINER (window), box);

                image = GTK_IMAGE (gtk_image_new_from_file
("/usr/share/pixmaps/camorama.png"));
                gtk_box_pack_start (GTK_BOX (box), image, TRUE, TRUE, 12);

                label = gtk_label_new ("Hello World");
                gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 12);

                gtk_widget_show_all (window);
        }
        else
                gtk_widget_hide (GTK_WIDGET (window));

        window_shown = !window_shown;
        return TRUE;
  }

static gboolean
myexample_applet_fill (PanelApplet *applet,
   const gchar *iid,
   gpointer data)

{
        GtkWidget *image, *event_box;
        printf("I just instantiated the image\n");
        if (strcmp (iid, "OAFIID:ExampleApplet") != 0)
                return FALSE;

        image = gtk_image_new_from_file ("/usr/share/pixmaps/camorama.png");
printf("I just loaded the image\n");
        event_box = gtk_event_box_new ();
        gtk_container_add (GTK_CONTAINER (event_box), image);
        printf("I just created the EB container\n");
        gtk_widget_show_all (GTK_WIDGET (applet));
        printf("I should be showing stuff\n");

        g_signal_connect (G_OBJECT (event_box),
                  "button_press_event",
                  G_CALLBACK (on_button_press),
                  image);

        return TRUE;
}


PANEL_APPLET_BONOBO_FACTORY ("OAFIID:ExampleApplet_Factory",
                             PANEL_TYPE_APPLET,
                             "The Hello World Applet",
                             "0",
                             myexample_applet_fill,
                             NULL);

What am I doing wrong?
Thanks,

Andrew






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]