> [email protected] wrote:
> >> [email protected] wrote:
> >>> I've been using FLTK to wrapper very complex engineering calculations..
> >>    See Fl::check():
> >>    http://fltk.org/documentation.php/doc-1.1/Fl.html#Fl.check
> >>
> >>    Call Fl::check(); within your calculation so that FLTK
> >>    can have some CPU to keep the interface alive.
> >>
> > I tried that, it didn't work.
>
>       Right; sorry -- think I followed up with a better example.
>
>       Since your calculation is in a separate program being read
>       through popen(), your FLTK app is likely blocking during
>       the fread()/fgets() operations.
>
>       So unless you can make those operations non-blocking,
>       you'll need to use a thread to manage the popen()/reading/pclose()
>       to ensure your app and FLTK doesn't block.
>
>       This example avoids threads, but only works under unix, and
>       shows how to use popen + fltk:
>       http://seriss.com/people/erco/fltk/#add_fd
>

I got the following to compile and run, but it doesn't seem to call HandleFD() 
at any point.  I call a make -j4 with popen() and had added -d -t for testing:


void HandleFD(int fd, void *data) {
    char results[1024]; int *i;
    i = (int*) data;
    if ( fgets(results, 1023, G_fp) == NULL ) {
        run_make->value(0);
        Fl::remove_fd(fileno(G_fp)); pclose(G_fp); return;
    }
    OP_BUF->append(results); run_op->scroll((*i)++, 0);
}

Fl_Light_Button *run_make=(Fl_Light_Button *)0;

static void cb_run_make(Fl_Light_Button* o, void*) {
  //
  FILE *stream; char command[1024]="", results[1024];
  static int i=0;
  o->deactivate(); frame->cursor(FL_CURSOR_WAIT);
  sprintf(command, UGUNN_CMD, colls_directory->value(), processes->value());
  OP_BUF->text("");
  if ( ( G_fp = popen(command, "r") ) == NULL ) {fl_message("popen failed"); 
return;}
  Fl::add_fd(fileno(G_fp), HandleFD, &i); sleep(1);
  while (run_make->value() == 1) {
         sleep(1); frame->redraw(); Fl::flush();}
  o->activate(); frame->cursor(FL_CURSOR_DEFAULT);
}

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

Reply via email to