Automatic Tcl/Tk GUI generation (was Re: Tk tty window)
Nadav Har'El wrote in article <CM1IKz.Dq2@discus.technion.ac.il> :
Wed Nov 14 14:03:15 EST 2007
>Neeta Ganguly H3-428 <ganguly at oakhill.sps.mot.com> wrote:
>>I am new to tcl/tk (isn't everyone) and am trying to set up a GUI for
>>a program. When I hit the run button, I would like to open up a shell
>>window, which displays the command, and traps all output from the
>>command as it executes. Does anyone have any pointers on how to
>>do this?
>>
>>Thanks,
>>
>>Neeta.
OK, imagine this: a Perl program that `interrogates' your program, determines
the names, abbreviations, types and possible values of the program's command
line parameters, and then proceeds to AUTOMATICALLY build a Tcl/Tk GUI wrapper
around your program. When you execute the generated wrapper you see a nice
window with a Text widget containing complete usage help for the command, and
a series of Label/Entry/Button/RadioButton widgets containing the command line
parameters.
You then `fill in the blanks' and push buttons to establish values for your
program's parameters (all the while watching the actual command that shall be
executed update on-the-fly in a separate Entry widget). When you are satisfied
simply click the `Do It' button, an output window appears, the command is
executed and stderr/stdout is captured in that window for viewing and/or
piping.
If your TK has the `AddInput' extention built in then the Tcl/Tk wrapper uses
it and changes the `Do It' button to `Cancel' so you can even abort your
program's execution early.
You can do this today with one proviso: your program must be written in C or
Perl and use the function evaluate_parameters to parse the command line. If
your C/Perl program doesn't use evaluate_parameters (I assume it doesn't since
you've probably never heard of it (-:) it is still VERY simple to retrofit,
and has the added advantage of cleaning up your current argument processing
code.
Most C/Perl program process parameters via a while loop with a bunch
of if statements and variable assignments, or maybe a case if they use getopt.
On the other hand, to use evaluate_parameters you (essentially) simply call it,
and the command line is parsed and parameter values stored in a structure for
you to access. The right way to use evaluate_parameters is to gut the old
argument processing code and just use the parameter values from the structure.
The lazy way is to copy the values from the structure into your program's
existing variables. In any case, this is typically a 10-15 minute process.
What you gain is a simple and consistent user interface (and that makes the
automatic GUI generation possible), with three levels of help, and
type-checking of parameter values.
For more info, you can get the evaluate_parameters package via anonymous FTP
from ftp.Lehigh.EDU, file pub/evap/evap-2.x/evap-2.0.tar.Z.
Take care,
Steve
----- End Included Message -----
More information about the grass-user
mailing list