Re: Updating a TextView with the results of a long, processor-intensive process



On Wed, 2004-04-14 at 17:36, Bob Wilkinson wrote:
On Wed, Apr 14, 2004 at 10:42:58PM +0200, Jan Hudec wrote:
On Wed, Apr 14, 2004 at 19:41:30 +0100, Bob Wilkinson wrote:
On Tue, Apr 13, 2004 at 11:17:21PM -0400, muppet wrote:

On Tuesday, April 13, 2004, at 05:23 PM, Bob Wilkinson wrote:

I have read the FAQ Q: How do i keep my gui updating while doing a 
long file read?
and added code to the process_infile routine.
<snip>
However, it only updated my TextView at the end of the processing.

Some sanity-check questions:
- Are you returning control to the event loop?

Implicitly. once the processing routine is finished control returns.
How would I do this explicitly, once the processing routine is
started?

Since all problems you described later seem to be this one:

You should know, that Gtk+ applications are NOT threaded (normaly).
Things don't happen in parallel in them. Instead they run from a big
event loop, that waits for something to happen and calls appropriate
function that responds. All the redrawing is tightly bound to events
sent by the X server. Thus it can only happen from the mainloop^*. So
you need to pass control to the main loop for ANYTHING to be redrawn.

There are two ways to pass control to mainloop.
1) Returning. You must set an idle handler to do the rest of the work
   (it will be called once pending events are processed).
2) Calling gtk_main_iteration()/Gtk2->main_iteration(). That will
   process pending events once and return. So you have to call it
   regularly from a long-running routine.


I have   

Glib::Idle->add( sub {while (Gtk2->events_pending()) {Gtk2->main_iteration()}});

i don't know exactly what you're trying to do, but you don't want to do
that.

Glib::Idle's will only happen while you're in a main loop. it doesn't do
anything productive to have a main iteration happening in an idle that
would be called from a main loop. beyond that it's likely that the idle
loop would only happen once, since you're probably not returning 1
(true) to keep it installed.

basically if you're watching a file descriptor and updating a text
widget with it then you probably want to use a the io watch stuff. where
it will sit in a mainloop and call your code when there's something for
it to do. 

if you're just doing complicated calculations or other non-io stuff that
takes a long time then you should periodically do the while events
pending handle some events stuff. i haven't been following this thread
close enough to tell you what's right for your situation, perhaps others
on the list have and can give you better answers.

-rm




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