LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-16-2008, 03:01 AM   #1
andreag
LQ Newbie
 
Registered: Jan 2006
Posts: 6

Rep: Reputation: 0
Basic Gnome 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:

Code:
#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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gnome-timer-applet Chriswaterguy Linux - Software 3 04-16-2008 12:29 AM
Gnome Applet problems SuperNate Linux - Software 1 10-21-2005 12:43 PM
weather applet for gnome walden Linux - Software 1 07-26-2005 08:22 PM
gweather applet - GNOME 2.0, RH 8.0 boonders Linux - Software 1 04-01-2003 02:40 AM
Gnome Clock Applet natto34 Linux - Software 0 07-18-2002 09:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration