Re: Updating GUI during long operation



On Thu, 2013-04-25 at 22:53 -0400, Allin Cottrell wrote:
I have a situation which might, perhaps, be akin to yours. From the 
GUI, my app calls an iterative numerical procedure that can be quite 
time consuming. Without any special treatment, this causes the GUI 
to appear "frozen" and unresponsive, as if something had gone wrong.

My solution was to introduce a "breather", as you call it. I 
installed a callback function, to be called every k iterations of 
the numerical procedure (for a suitable value of k). The callback 
simply looks like this:

static void gui_show_activity (void)
{
     while (gtk_events_pending()) {
         gtk_main_iteration();
     }
}

Hey Allin. Thanks a lot for your help. It's similar to my situation, but
unfortunately in my case the demanding work is in a secondary thread
where events_pending() / main_iteration() don't seem to do anything from
the secondary thread. I'm guessing because it's a separate event queue
in each thread and we're really not suppose to be doing GUI operations
outside the main thread anyways. 

So I tried using idle_add() in the worker thread to have a callback
invoked periodically from within the main thread which in turn does
exactly what your gui_show_activity() function does, but the problem is
that the callback calls itself recursively until the stack blows up
because main_iteration() call invokes the callback again since the last
invocation was never removed off the queue yet. Almost got it. Arg.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


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