Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.


  How can I mix interactions between Xt and Tk/Tcl?
 
 Tk has a new event loop which provides easier interaction than previous
answers dictated.  The following answer is provided by Paolo Brutti
(Paolo.Brutti@tlsoft.it):

void XtEventSetup(ClientData xtconn, int flags)
{
  static Tcl_Time maxDelay={0, 300000}; /* To process non-X events */

  Tcl_WatchFile((Tcl_File)xtconn, TCL_READABLE);
  Tcl_SetMaxBlockTime(&maxDelay);
}

int XtDoEvent(Tcl_Event *evPtr, int flags)
{
  while (XtPending())
    XtProcessEvent(XtIMAll);
  return 1;
}

void XtEventCheck(ClientData xtconn, int flags)
{
  Tcl_Event *event;

  if(XtPending()) {
    event	= (Tcl_Event *)ckalloc(sizeof(Tcl_Event));
    event->proc	= XtDoEvent;
    Tcl_QueueEvent(event, TCL_QUEUE_TAIL);
  }
}

void tkGo (void)
{
  extern Widget topLevel;
  Tcl_File xtconn;
  int xtfd = ConnectionNumber(XtDisplay(topLevel));

  xtconn = Tcl_GetFile((ClientData)xtfd, TCL_UNIX_FD);

  Tcl_CreateEventSource(XtEventSetup, XtEventCheck, (ClientData)xtconn);
  while (1) {
    Tcl_DoOneEvent(TCL_ALL_EVENTS);
  }
}