On 29 Mar 2008, at 23:20, Thomas Guiot wrote:
> hi
>
> i'm developing a small software for neuronal image analysis. I have  
> a problem using fltk callbacks:
>
> i have a main class containing my GUI, and the callbacks for the  
> GUI as member functions (through the "static/inline" pair of  
> functions, as  described in doc)
>
> here's the deal: when the user hits the "filter" button on my gui,  
> i'd like a new window to open, presenting some filtering options;  
> then the user hits "run" on that window, and image filtering is in  
> process.
>
> so far my code is:
>
> [in my main class.cpp]
> ..
> void Filter_callback(){
> filterWindow->show(); //filterWindow derives from Fl_Window
> image->Filter(filterWindow->GetFilterParameters());
> }
> ..

I assume the image->Filter(...) call is some time consuming  
processing step? If so, I'd strongly advocate against doing that. In  
the callbacks, it is probably best to do as little as possible. The  
problem is that whilst fltk is processing the callback for a widget,  
it can't be handling any other widget events, so the UI becomes  
unresponsive, with other UI events either getting queued or lost...

You need to have your callback simply note that the processing has  
been requested and return, (thus allowing the UI to remain active,  
and able to show your parameters window) then have some other  
processing actually execute the filter window.

This is where it gets tricky - I'd have a worker thread that was just  
waiting for the callback to signal it to do the processing, but a lot  
of people (probably rightly) are wary of threads (although on modern  
multi-core PC's they do help spread the CPU load around better!).
An alternate not-threaded approach (and this smells a bit hacky to  
me, although I have used it) is to have the "start" callback register  
a timeout with add_timeout (which will run once the UI widget  
callback has returned) then have that timeout start your processing  
step... I *think* that works the way you'd want...



_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to