Re: understanding GTK thread capabilities



kobyleski thierry wrote:
> 
> Can't someone confirm it is possible to do the following (just if it is
> possible):
> I press a button which starts a long work, and I need to see the cpu
> load in another widget in the same form. Is it possible to update the
> value of the cpu load in a label wigdet for example, while the callback
> from the button is still at work (and is not yet returned to the main
> loop).

It sounds perfectly possible.

Firstly, don't do the real processing in the button's callback - that
will "hang" the gui. Instead, in the button's callback start a new
thread to do the work and start a timer to update the cpu usage label.

The timer callback happens in the gtk+ event queue so, obviously, you
don't need to worry about thread issues there. Just calculate cpu usage
and update the display as usual.

If you do need to update the display from the thread started by the
button press then you need to read up on using threads in the faq at
www.gtk.org.

Also you will probably need some way of letting the gui know that the
thread has finished. You can either do that directly from the thread or
you could create a pipe which the thread writes to when it's finished.
The gui would listen for data on the pipe using the gdk_input_xxx()
functions.

HTH

Cheers, Matt

-- 
Matt Goodall             |  Isotek Electronics Ltd
email: mgg@isotek.co.uk  |  Claro House, Servia Road
Tel: +44 113 2343202     |  Leeds, LS7 1NL
Fax: +44 113 2342918     |  England




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]