Subject: Re: How to integrate a C application and a Tcl/Tk GUI. - DN [1]
"D. Richard Hipp" <drh@acm.org> - 18 Jan 2000 - comp.lang.tcl
Tony Gahlinger wrote: > > I have a C application whose main loop responds > to asynchronous events from the outside world > (using the select function). I now want to create > a Tcl/Tk GUI to monitor/manage this application; > e.g., I see the outside world is in state X so I > click on a button to put it into state Y, etc. > > Now this approach would give me two 'main' loops: > the one in C and the event loop in Tk. Any advice > or example on how to integrate the C app and the > GUI into a single `process'? > > I've already browsed through the mktclapp > documentation and Welch's latest edition, but > haven't reached nirvana. It doesn't strike me as > straightforward. Must I switch to peruse mode > on the docs? --Tony > Anything you can do with select() you can just as easily do with Tcl functions such as Tcl_CreateChannelHandler() or Tcl_CreateTimerHandler(). (In fact, these routines are implemented on Unix using select().) So you modify your code to use the built-in Tcl event processing functions in place of your custom select() loop. It may also be possible to rig your custom select() loop to notice the events Tcl cares about and then call the Tcl event loop on an as-needed basis. This would involve calling the Tcl function Tcl_DoOneEvent() whenever there was data to be read from the X server (to capture GUI events), whenever there is no other work to do (to capture idle events), and a periodic intervals (to capture timer events). -- D. Richard Hipp -- drh@acm.org -- http://www.hwaci.com/drh/
Last modified
2000-02-10
2000-02-10
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
