PDA

View Full Version : Gtkmm/libglademm updating a GUI



C--
May 14th, 2009, 06:53 PM
I have a GTK+ window built in Glade and parsed with libglademm and gtkmm (the C++ GTK+ wrapper). I have a separated POSIX thread that is trying to update a Gtk::Label every second with the current system time, but once the window is visible it will not update. Plus, one of the icons I specified in glade is a flashing .gif, and while the .gif animates in the Glade preview version of the window, it does not flash at all when the executable runs. It appears that in both cases the GUI will not update.

haTem
May 14th, 2009, 07:17 PM
Have a look at Glib::Dispatcher. It has been awhile since I've used gtkmm, but I do recall that Glib::Dispatcher allows for cross-thread signaling, which may solve your problem.

SledgeHammer_999
May 14th, 2009, 08:48 PM
or make your main thread do the updating.(look here (http://gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/chapter-chapter-timeouts.html) for timeout functions)

C--
May 18th, 2009, 10:02 PM
Okay after some more work, the GUI updates when I mouseover it, but not on its own. I suspect this is because I am not calling the equivalent of a repaint() function, like in Swing. I cannot find anything in the gtkmm documentation that talks about this.

C--
May 20th, 2009, 03:45 PM
Okay Glib :: Dispatcher did the trick for updating labels. I just set the labels in another thread and then call dispatcher, which fires an event that triggers the GUI to update. You can also connect signal handlers to the dispatcher, however I do not bother with this is the handlers cannot be passed variable arguments.

As for the animation, I had to manually load the .gif into a Gdk :: PixbufAnimation and set it on the Gtk :: Image from glade with a call to Gtk :: Image :: set.