Hi Camilo,

On Wed, 05 Oct 2011 23:57:31 -0300 you wrote:
> I like to create an animated statusbar icon like this:
> 
> void animate_statusbar_icon(Glib::RefPtr< Gtk::StatusIcon > icon)
> {
>     while (true)
>     {
>         icon->set_from_file("icon.png");
>         icon->set_visible();
>         sleep(1);
>         icon->set_from_file("icon_2.png");
>         icon->set_visible();
>         sleep(1);

You can't do that. Never use "sleep" this way.

The sleep function pauses your _entire_ application (or at least the
whole thread) which means the GTK main loop never gets to run. Instead
you need to write your code to co-operate with GTK. Try something like:

class animated
{
        Glib::RefPtr< Gtk::StatusIcon > iconref;
        int next_img;

        void tick_cb(void);
        void animate_statusbar_icon(Glib::RefPtr< Gtk::StatusIcon > icon)
};


void animated::animate_statusbar_icon(Glib::RefPtr< Gtk::StatusIcon > icon)
{
        iconref = icon;
        next_img = 0;
        Glib::SignalTimeout().connect_seconds ( 
sigc::mem_fun(animated::tick_cb, this), 1 );
}

void animated::tick_cb(void)
{
        std::string fname = "icon_";
        fname += next_img;
        fname += ".png";
        next_img++;
        icon->set_from_file(fname);
}
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to