GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 02, 2014 2:31 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: animated statusicon
PostPosted: Thu Apr 23, 2009 11:50 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
Hi all
i would like to make an animated statusicon(trayicon).
is it possible.
may i get sample code for the trayicon.

any help it should be appreciable


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 23, 2009 12:40 pm 
Offline
GTK+ Guru

Joined: Thu Jun 21, 2007 1:52 pm
Posts: 198
Location: Wilkes Barre Pa
This might answer part of your question.

Code:
#include <gtk/gtk.h>

/* gcc -o status status.c `pkg-config --libs --cflags gtk+-2.0` */

void tray_icon_on_click(GtkStatusIcon *status_icon,
                        gpointer user_data)
{
        printf("Clicked on tray icon\n");
}

void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button,
                       guint activate_time, gpointer user_data)
{
        printf("Popup menu\n");
}

static GtkStatusIcon *create_tray_icon() {
        GtkStatusIcon *tray_icon;

        tray_icon = gtk_status_icon_new();
        g_signal_connect(G_OBJECT(tray_icon), "activate",
                         G_CALLBACK(tray_icon_on_click), NULL);
        g_signal_connect(G_OBJECT(tray_icon),
                         "popup-menu",
                         G_CALLBACK(tray_icon_on_menu), NULL);
        gtk_status_icon_set_from_icon_name(tray_icon,
                                           GTK_STOCK_MEDIA_STOP);
        gtk_status_icon_set_tooltip(tray_icon,
                                    "Example Tray Icon");
        gtk_status_icon_set_visible(tray_icon, TRUE);

        return tray_icon;
}

int main(int argc, char **argv) {
        GtkStatusIcon *tray_icon;

        gtk_init(&argc, &argv);
        tray_icon = create_tray_icon();
        gtk_main();

        return 0;
}



References:
http://library.gnome.org/devel/gtk/stab ... sIcon.html

Here is another example found in GTK+ Example Code
http://www.gtkforums.com/viewtopic.php?t=2350

And here is another question about GtkStatusIcon where the programmer posted his code check it out might help.
http://www.gtkforums.com/viewtopic.php?p=8440

Hope that helps :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 24, 2009 5:18 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
caracal wrote:
This might answer part of your question.

Code:

        gtk_status_icon_set_from_icon_name(tray_icon,
                                           GTK_STOCK_MEDIA_STOP);





hey! thank you for your replay.
and i know to creat simple trayicon..

but i need animated status icon...
the icon which is showing in the tray should be animated..

any help it should be appreciable


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 24, 2009 12:43 pm 
Offline
GTK+ Guru

Joined: Thu Jun 21, 2007 1:52 pm
Posts: 198
Location: Wilkes Barre Pa
Use this function to load an animated image from file.
http://library.gnome.org/devel/gdk-pixb ... -from-file

Then instead of gtk_status_icon_set_from_icon_name(tray_icon, GTK_STOCK_MEDIA_STOP);

use

gtk_status_icon_set_from_pixbuf ()

http://library.gnome.org/devel/gtk/stab ... rom-pixbuf

I am guessing thats how it could be done.
Sorry i cant post a working example i am not that familiar with gdk-pixbuf but i will spend some time on the problem and if i get some working code ill post it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 28, 2009 6:31 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
hi

i tried like this.
but i did not got the animation statusicon

any help it should appreciable

Code:
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

//gcc -o status status.c `pkg-config --libs --cflags gtk+-2.0`


static GtkStatusIcon *create_tray_icon() {
        GtkStatusIcon *tray_icon;
        GdkPixbufAnimation *anim;

        tray_icon = gtk_status_icon_new();

        //gtk_status_icon_set_from_icon_name(tray_icon,GTK_STOCK_MEDIA_STOP);

        anim=gdk_pixbuf_animation_new_from_file("hackanm.gif", NULL);
        gtk_status_icon_set_from_pixbuf (tray_icon,anim);
        gtk_status_icon_set_tooltip(tray_icon,
                                    "Example Tray Icon");
        gtk_status_icon_set_visible(tray_icon, TRUE);

        return tray_icon;
}

int main(int argc, char **argv) {
        GtkStatusIcon *tray_icon;

        gtk_init(&argc, &argv);
        tray_icon = create_tray_icon();
        gtk_main();

        return 0;
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 29, 2009 10:43 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
can anybudy give the solution for the above code


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 02, 2009 2:06 pm 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
hi
anybudy replay for the above code


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 03, 2009 11:50 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
Here's an example of how to use an animation for a GtkStatusIcon.
You should be able to adapt it to your needs.
Code:
#include <gtk/gtk.h>

#define   ANIM_FILE   "test.gif"

typedef struct _Data
{
   GtkStatusIcon *icon;
   GdkPixbufAnimationIter *iter;
} Data;

gboolean button_press_cb(GtkStatusIcon *icon, GdkEventButton *ev, gpointer user_data)
{
   GtkWidget *menu;
   GtkWidget *item;

   /* Create a menu just for an example */
   menu = gtk_menu_new();

   /* Create a stock quit item */
   item = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
   g_signal_connect(item, "activate", G_CALLBACK(gtk_main_quit), NULL);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   gtk_widget_show(item);

   /* Popup the menu */
   gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, ev->button, ev->time);

   return FALSE;
}

gboolean pixbuf_anim_timeout(gpointer user_data)
{
   GdkPixbuf *pbuf;
   Data *data = (Data*)user_data;

   /* If the image doesn't need to be updated, return */
   if(gdk_pixbuf_animation_iter_advance(data->iter, NULL) == FALSE)
      return TRUE;

   /* Get our current frame's pixbuf */
   pbuf = gdk_pixbuf_animation_iter_get_pixbuf(data->iter);
   /* Update the status icon */
   gtk_status_icon_set_from_pixbuf(data->icon, pbuf);

   /* Return TRUE to keep the animation running */
   return TRUE;
}

gint main(gint argc, gchar **argv)
{
   GtkStatusIcon *icon;
   GdkPixbufAnimation *anim;
   GdkPixbufAnimationIter *iter;
   GdkPixbuf *pbuf;
   gint delay;
   GError *err = NULL;

   Data data;

   gtk_init(&argc, &argv);

   /* Create a new GdkPixbufAnimation and do error checking */
   anim = gdk_pixbuf_animation_new_from_file(ANIM_FILE, &err);
   if(err != NULL)
   {
      g_warning("%s", err->message);
      g_error_free(err);
      return 1;
   }
   /* Get a start iter... */
   iter = gdk_pixbuf_animation_get_iter(anim, NULL);
   data.iter = iter;
   /* ...and get the start frame */
   pbuf = gdk_pixbuf_animation_iter_get_pixbuf(iter);

   /* Create a new GtkStatusIcon from our pixbuf */
   icon = gtk_status_icon_new_from_pixbuf(pbuf);
   data.icon = icon;
   /* And connect a signal so we can quit */
   g_signal_connect(icon, "button-press-event", G_CALLBACK(button_press_cb), NULL);

   /* Set up the timeout */
   delay = gdk_pixbuf_animation_iter_get_delay_time(iter);
   /* If delay == -1, then it should be static */
   if(delay != -1)
      g_timeout_add(delay, pixbuf_anim_timeout, (gpointer)&data);

   gtk_main();

   return 0;
}

Docs:
http://library.gnome.org/devel/gtk/stab ... sIcon.html
http://library.gnome.org/devel/gdk-pixb ... ation.html
Also, here's one of your older topics with more information on GdkPixbufAnimation:
viewtopic.php?t=1639


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 04, 2009 5:45 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
dreblen wrote:
Here's an example of how to use an animation for a GtkStatusIcon.
You should be able to adapt it to your needs.
Docs:
http://library.gnome.org/devel/gtk/stab ... sIcon.html
http://library.gnome.org/devel/gdk-pixb ... ation.html
Also, here's one of your older topics with more information on GdkPixbufAnimation:
viewtopic.php?t=1639


Hi
while i am trying to excute the program getting these errors
and also statusicon not showing.

Quote:
(animation.exe:8384): GdkPixbuf-CRITICAL **: gdk_pixbuf_animation_get_iter: assertion `GDK_IS_PIXBUF_ANIMATION (animation)' failed

(animation.exe:8384): GdkPixbuf-CRITICAL **: gdk_pixbuf_animation_iter_get_pixbuf: assertion `GDK_IS_PIXBUF_ANIMATION_ITER (iter)' failed


and also i would like to ask another querry.

i need to do some more implementation for the statusicoon.
how can we change the status of the statusicon..

let me clear my querry.(with an example)
in the tray we can find the volume statusicon
if we disabled the icon it can show desabled volume icon and if we enable this icon can show enabled volume icon...

so here the trayicon is changing with two types of images..

is it possible to do that..

any help it should be appreciable


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 04, 2009 9:40 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
ramesh wrote:
Hi
while i am trying to excute the program getting these errors
and also statusicon not showing.

Quote:
(animation.exe:8384): GdkPixbuf-CRITICAL **: gdk_pixbuf_animation_get_iter: assertion `GDK_IS_PIXBUF_ANIMATION (animation)' failed

(animation.exe:8384): GdkPixbuf-CRITICAL **: gdk_pixbuf_animation_iter_get_pixbuf: assertion `GDK_IS_PIXBUF_ANIMATION_ITER (iter)' failed

If you're running my program, then you need to make sure that you have ANIM_FILE set to a valid path.

ramesh wrote:
i need to do some more implementation for the statusicoon.
how can we change the status of the statusicon..

let me clear my querry.(with an example)
in the tray we can find the volume statusicon
if we disabled the icon it can show desabled volume icon and if we enable this icon can show enabled volume icon...

so here the trayicon is changing with two types of images..

is it possible to do that..

any help it should be appreciable

You can change the image using the gtk_status_icon_set_ line of functions (like I do in my previous program).
Here are some docs:
http://library.gnome.org/devel/gtk/stab ... rom-pixbuf
http://library.gnome.org/devel/gtk/stab ... -from-file


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 05, 2009 7:05 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
dreblen wrote:
If you're running my program, then you need to make sure that you have ANIM_FILE set to a valid path.



yes i given the valid path of pixmap.
still i am getting the same error.

Quote:
You can change the image using the gtk_status_icon_set_ line of functions (like I do in my previous program).
Here are some docs:
http://library.gnome.org/devel/gtk/stab ... rom-pixbuf
http://library.gnome.org/devel/gtk/stab ... -from-file


can you please explain with an example.

any help it should be appreciable


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 05, 2009 4:33 pm 
Offline
GTK+ Guru

Joined: Thu Jun 21, 2007 1:52 pm
Posts: 198
Location: Wilkes Barre Pa
Your changing this line right

Code:
#define    ANIM_FILE    "test.gif"


The code example works fine for me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 05, 2009 4:51 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
ramesh wrote:
yes i given the valid path of pixmap.
still i am getting the same error.

You are running my example program right? If not, can you post what you are running? Thanks...

ramesh wrote:
can you please explain with an example.

Well, like I said, my previous example is already kind of an example of this, but here's another more direct example using gtk_status_icon_set_from_file:
Code:
#include <gtk/gtk.h>

static const gchar *IMAGE_FILES[] = {
   "test.png",
   "test2.png",
};

gboolean button_press_cb(GtkStatusIcon *icon, GdkEventButton *ev, gpointer user_data)
{
   static gint ref = 0;

   /* If RMB (or equivalent), quit */
   if(ev->button == 3)
      gtk_main_quit();

   /* Otherwise, re-set the image */
   /* Using the '!' operator will ensure that we always have 0 or 1 */
   ref = !ref;
   gtk_status_icon_set_from_file(icon, IMAGE_FILES[ref]);

   return FALSE;
}

gint main(gint argc, gchar **argv)
{
   GtkStatusIcon *icon;

   gtk_init(&argc, &argv);

   icon = gtk_status_icon_new_from_file(IMAGE_FILES[0]);
   g_signal_connect(icon, "button-press-event", G_CALLBACK(button_press_cb), NULL);

   gtk_main();

   return 0;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group