Developing a Gnome Applet

Hi there,

I'm trying to develop a Gnome Applet but I encountered some, problems.

I read the tutorial here: http://developer.gnome.org/panel-applet/3.0/getting-started.example.html

I've created the file helloworld.c:
Code:
#include <gtk/gtk.h>
#include <panel-applet.h>

static gboolean
hello_world_applet_start (PanelApplet *applet)
{
    GtkWidget *label;

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

    return TRUE;
}

static gboolean
hello_world_factory_callback (PanelApplet  *applet,
                              const gchar  *iid,
                              gpointer      data)
{
    gboolean retval = FALSE;

    if (g_strcmp0 (iid, "HelloWorldApplet") == 0)
        retval = hello_world_applet_start (applet);

    return retval;
}

PANEL_APPLET_OUT_PROCESS_FACTORY ("HelloWorldFactory",
                                  PANEL_TYPE_APPLET,
                                  hello_world_factory_callback,
                                  NULL)

But when I try to compile it, I got the error:
[CMD=">"]gcc -Wall `pkg-config --cflags --libs libpanelapplet-3.0` helloworld.c -o helloworld
helloworld.c:32:39: error: macro "PANEL_APPLET_OUT_PROCESS_FACTORY" requires 5 arguments, but only 4 given
helloworld.c:29: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
[/CMD]

pkg-config give me this result:
[CMD=">"]pkg-config --cflags --libs libpanelapplet-3.0
-I/usr/local/include/gnome-panel-3.0/libpanel-applet -I/usr/local/include/gconf/2 -I/usr/local/include/orbit-2.0 -DORBIT2=1 -I/usr/local/include/gtk-2.0 -I/usr/local/include/gio-unix-2.0/ -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/pixman-1 -D_THREAD_SAFE -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/libpng15 -I/usr/local/include/pango-1.0 -D_REENTRANT -I/usr/local/include/glib-2.0 -I/usr/local/include/freetype2 -I/usr/local/include -lpanel-applet-3 -lgconf-2 -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -lXext -lXrender -lXinerama -lXi -lXrandr -lXcursor -lXcomposite -lXdamage -lXfixes -lX11 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lm -lgobject-2.0 -lgthread-2.0 -lgmodule-2.0 -pthread -lglib-2.0 -lfreetype -L/usr/local/lib -lfontconfig [/CMD]

Did I missed something ?

Thanks!
Flogo
 
Flogo said:
I'm trying to develop a Gnome Applet but I encountered some, problems.

I read the tutorial here: http://developer.gnome.org/panel-applet/3.0/getting-started.example.html
[snip]
helloworld.c:32:39: error: macro "PANEL_APPLET_OUT_PROCESS_FACTORY" requires 5 arguments, but only 4 given
The tutorial you linked to is from 2005. I don't know much about GNOME (enough not to like it though, but that's besides the point) but my educated guess is that that particular tutorial is out of date. Seven or eight years is a long time and APIs have probably changed in the meantime.

Fonz
 
fonz said:
The tutorial you linked to is from 2005.

Hi Fonz, thanks for your answer.
You are may be right, but I didn't find a more up-to-date tutorial moreover it corresponds to my installed version of libpanelapplet.

Flogo
 
neilms said:
I don't know anything about python. However, I understand that it can be used to develop gnome applets as an alternative to c. It may be a lot easier than c to understand initially if you try it.

I can't vouch for this link, but it appears to provide a detailed introduction:
http://www.znasibov.info/blog/post/gnome-applet-with-python-part-1.html

Hi neilms!
As you, I don't know anything about python, moreover my applet is for an other program fully developed in C. But thanks anyway! :)

If I change a little bit the source code according to the header file:

[CMD=">"]grep PANEL_APPLET_OUT_PROCESS_FACTORY /usr/local/include/gnome-panel-3.0/libpanel-applet/panel-applet*
/usr/local/include/gnome-panel-3.0/libpanel-applet/panel-applet.h:#define PANEL_APPLET_OUT_PROCESS_FACTORY(id, type, name, callback, data) \[/CMD]

Code:
PANEL_APPLET_OUT_PROCESS_FACTORY ("HelloWorldFactory",
                                  PANEL_TYPE_APPLET,
                                  "HelloWorldFactory"
                                  hello_world_factory_callback,
                                  NULL)

It compiles now, but I'm not sure that's good.

If I copy the executable in "/usr/local/lib/gnome-panel/" and create the file /usr/local/share/gnome-panel/applets/hello.panel-applet

[Hello Factory]
Id=HelloWorldFactory
Name=Hello World Applet
Description=Just a try
[PlacardApplet]
Name=HelloWorld
Description=Just a try
Icon=app.png


I can see the entry when I want to add it to the panel, but if I click on "add", nothing happen ...

Do you have an idea ?

Thanks,
Flogo
 
I can see that
Code:
PANEL_APPLET_OUT_PROCESS_FACTORY
is a #define macro that should be defined in #include<panel-applet.h>

This 'entity' expects four arguments:
1. id
2. type
3. callback
4. data

What do each of the arguments to this function do - in a general sense? The original problem was that there were too few arguments provided and that was why it did not compile.

I think there is an error with your callback function. See http://developer.gnome.org/panel-applet/stable/panel-applet-Panel-Applet-Factory.html. If nothing is happening, then callback is returning false - why? If I were you, I would take a look at that part of the code. In particular, is the expected data even being passed to the function?
Code:
hello_world_factory_callback (PanelApplet  *applet,
                              const gchar  *iid,
                              gpointer      data)
{
    gboolean retval = FALSE;

    if (g_strcmp0 (iid, "HelloWorldApplet") == 0)
        retval = hello_world_applet_start (applet);

    return retval;
}
 
Hold on

It says on the introduction page at http://developer.gnome.org/panel-applet/stable/getting-started.intro.html
Note
Keep in mind that starting with GNOME 3, the panel and applets are only available in the fallback mode. An applet will therefore not be usable in the default GNOME that users may use.

I am not sure that the code is wrong. It is probably just illustrative to explain certain concepts. Try finding an example that is intended for compilation..
Alternatively, you will get fast & real help from experts if you post your question to one of the gnome mailing lists - see: https://mail.gnome.org/mailman/listinfo
 
Back
Top