Fl_Widget::redraw() does not do the drawing; it just informs the widget
that the main event/redraw loop should do that. But because the callback
is executed within that loop also, the drawing will not occur until your
callback finishes and the loop can proceed with other tasks. You could
call Fl::flush() after the first widget change to update the screen
instantly but it is a half-assed solution as your GUI will not bee
responsive until your callback finishes and your application window can
be "damaged" during the callback duration ie by dragging some other
window in front of it.
So if you want to do a long *blocking* system call, you should probably
wrap its execution in a new thread and inform the main one after it
finishes (ie by updating a widget within a Fl::lock() and informing
about update using Fl::awake()). There is a "minimalistic" threading
example in fltk/test subdirectory if you want to use that.
Roman
Ben wrote:
> I might could be approaching this situation incorrectly, so let me know if
> you have any suggestions.
>
> My program has a text_display and a run button with a callback. Here's what
> I'm trying to do:
>
> //This is all written within the run button's callback (could that be the
> problem?)
> 1. When I do a callback I display some text (such as: "Running command...")
> 2. Then AFTER it displays the text, I run a few system commands and return
> the status
> 3. Once it's done I inform the user of the status (Success/Failure) by
> sending text to the text display again.
>
> Here's the problem: the text display doesn't display anything until the
> entire callback is finished, so everything comes out all at once.
>
> I've tried using a sleep function, and the redraw() function with no luck.
> I've also writing a separate function for the system calls which is invoked
> by the button's callback. Here's a simple version of my callback:
>
> void runbutt_cb(Fl_Widget *runbutt, void *data)
> {
> textout->insert("Checking packages for compile errors...\n");
>
> const char* cmd = "some system command";
> makestatus = system(cmd);
>
> if (makestatus == 0) textout->insert("\nNo compiling errors found.\n");
> else textout->insert("\nErrors found.\n");
> }
>
> Is there a way to update a text display before the callback has finished?
> Thanks in advance!
>
> Ben
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk