Re: Question re gtk_timeout_add and/or SIGALRMs



gtk-devel-list is about the development *of* gtk+, not *with* it. you want gtk-app-devel-list.

On May 25, 2004, at 3:17 AM, Colin Thomas wrote:

I am developing an application which is basically a lots of buttons, no drawing areas. When one button is depressed, the application runs a compute intensive job for 20 minutes. While this is happening though the main screen does not refresh, and slowly becomes obiterated.

I have tried two possible solutions.

One using a SIGALRM running each second to force a gtk_widget_draw(MainWindow, NULL), then reset the alarm for another second.

this is A Very Bad Idea. gtk+ functions are not safe to be called from async signal handlers. you also get a very unresponsive app, so it doesn't do what you want, anyway.

I have also tried using
[...]
  gtk_timeout_add(500, Repaint , 0);
prior to gtk_main().

your processing code never returns control to gtk_main(), so the timeout can never fire.


Apart from setting up a thread just to run a gtk_widget_draw
in the background, what would be the "preferred" solution to this
problem of keeping menu/widgets refreshed while the application is busy?

well, the main loop *must* be active to keep the gui updated. you can either break your task up into little chunks that you handle in idle (which is how the gimp renders image data), or use true concurrency (a worker thread or child process).

i would recommend a child process communicating via pipes with the parent; if you want to communicate progress, the hit of thread synchronization for updating a progressbar will slow things down more than writing data to a pipe from the child to be read and reacted to by the parent. (i'm waving my hands wildly as i say this.) it also will allow (force) you to keep the processing logic completely devoid of gui logic. (i'm speaking from experience on this point.)

--
The door is locked. I tried to open it, but the lock is harder to pick than a broken nose.
  -- Sensei, on 'I, Ninja'




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