Re: Changing widgets in events
- From: Brian <brian8192 fastmail fm>
- To: Richard Warren <rew primagraphics co uk>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Changing widgets in events
- Date: 05 Feb 2004 01:31:48 -0800
Yep, that did it! Thanks for the advice. Next time I'll check the
archives before posting. I still think most of the documentation for
gtk is rather incomplete. More examples would certainly help. If
anyone from gtk.org is reading this and need volunteers to write
documentation then I can help on some stuff. For example, tree view and
list store docs are empty.
thanks again,
brian.
On Thu, 2004-02-05 at 01:12, Richard Warren wrote:
Does anyone know a way to change widgets while running an event
handler? For example, I created a window with a single button on it. I
used gtk_signal_connect to connect a function to the button to fire when
it is pressed. Inside the function, I just sleep for 20 seconds.
Before I issue the sleep call, I change the cursor to a "watch" cursor.
When the sleep is finished, I change it back to the default arrow. When
I run this program, pressing the button makes it stop for 20 seconds,
but the cursor does not change. If I remove the call to change the
cursor back to the arrow, the cursor changes to the watch, but only
after the 20 seconds is over (which I assume is after the event has
finished). I have tried different combinations of changing cursors,
pulsing progress bars, etc. I have also tried doing something time
consuming other than just sleeping (like computing the fib of 30, for
example). I have looked over the documentation for signal handlers,
using both the deprecated gtk_signal* and the new g_signal*, neither of
them discuss this. Am I doing something wrong? I am using gtk 2.2, and
have tested this with the same results in Solaris 9 and Linux 2.4.
Thanks in advance.
brian.
You're not giving the main GTK+ loop a chance to run. Whilst you're in your
sleep() (or any other time consuming action) you've got the processor busy
and therefore the main loop can't update the GUI (so the cursor, progress
bars and so on can't be changed). All the requests you make to change
things will be queued-up and actioned when you return from your signal
handler after the delay.
There are loads of questions along these lines in this mailing list so
trying searching the archives. If I remember rightly, you need to do
something along the lines of the following in amongst your time-consuming
function if you want the GUI to update:
while( gtk_events_pending() )
{
gtk_main_iteration();
}
(NOTE that I can't remember precisely what the functions are called or
whether they have arguments, so check the archives or docs).
An alternative would be to spawn another thread to do the work and allow the
GUI loop to run in the main thread (although note that you can't touch the
GUI from your worker thread without a lot of care and attention to detail).
Regards,
Richard.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]