I have a nice (C, Fortran, ...) program and I want to develop a GUI for it. What options do I have?Of course this depends on the type of program. Let us sum up a few types:
- Small batch jobs: The program reads an input file, does a few calculations and after several seconds, it gives an answer (on screen or in a file)
- Large batch jobs: The program reads an input file, does its calculations but requires several minutes or hours to produce an answer (on screen or in a file)
- Interactive programs: The program is highly interactive, but reads its data from the command prompt
- Mildly interactive programs: The program is mildy interactive, it reads a few files or data it asks for, does a lot of calculations requiring noticeable time and produces the results.
Small batch jobs:The part that requires a GUI is the creation of the input file or better the manipulation of the input data and the presentation of the results.
- The easiest way to do it is to create a GUI with Tk that prepares the input data and either calls the program via exec or open.
- A (slightly) more involved way is to turn the program into a subroutine that can be called in Tcl. This subroutine must accept the input data and return the output to the caller.
Large batch jobs:As the calculations probably take too long, the best option is:
- Create a GUI for the input file
- Execute the program via exec in the background
- Pick up the results when it is finished
Interactive programs:When the program displays a prompt and wants to have information all the time, you have basically two choices:
- Provide the input via such programs as expect or expectk. The program will run as a separate process and does not need to know that it is running under control of another program.
Simpler solutions of that type: [Managing Fortran programs], [FORTRAN via open pipe]
- Isolate the calculations and turn them into separate Tcl commands. The drawback of this solution is that you must change the program itself. The good news however is that it will be very easy to extend the program's capabilities, as Tcl would then provide the glue needed to put the pieces together instead of some complicated, fixed logic.
Mildly interactive programs:This type programs would ask you a few questions first and then start to work. Perhaps it will ask for a few more data later on. They fall between the categories of batchwise and interactive processing. The solutions can be either way. For instance:
- If the program asks input on the command-prompt and then goes off, simply prepare an input file via a separate GUI, pass the data via a redirection (see exec and open for details) and pick up the results when done.
- If the program will come back later, it depends: are the questions foreseeable - just prepare another set of data. If not, try the expect approach.
LV If Tk came with (or at least if not with Tk, some how simple to obtain) something to do what zenity  does, except cross-platform, it seems to me that would be a nice demonstration of Tk's power.