We've got an MFC application (a test automation tool) which has an
embedded Tcl interpreter so the application can run test scripts
written in Tcl. So far we've been using just Tcl without the Tk part
but now we'd like to be able to have our Tcl scripts create dialogs,
popups etc ... which is why the Tk part is also required now.
Notice a test script as run in our tool does not necessarily HAVE to
use any Tk windows, but some scripts may use them to request input from
the user, etc. I have only a very vague understanding of what must be
done to set up the interpreter so it is Tk-capable, so I'd definitely
appreciate some good advice.
So far I'm aware of the following differences:
- must link against Tk84.lib as well (not just Tcl84.lib)
- need to include tk.h
- need to ship Tk84.dll with the application
Will I have to ship any additional files?
Also, I think setting up the interpreter will look something like this
(pseudo code):
1) call Tcl_CreateInterp()
2) Tcl_FindExecutable()
3) Tcl_Init()
4) Tk_Init()
5) done ??
6) Tcl_Eval( whatever_script_the_user_is_running )
By the way, the interpreter is created in a separate thread from the
GUI thread of the application.
Does this look right? Did I forget anything? Are there any additional
things I need to look out for? Thanks in advance for any helpful
replies!
Cheers,
ant
Here's what I do.
- Tcl_FindExecutable()
- Tcl_CreateInterp()
- use Tcl_SetVar() to set the "tcl_library" variable to tell the
interpreter where to look for the library scripts
- Tcl_Init() ... works
- Tk_Init() ... ERROR!! "invalid command name Tcl_findLibrary"
I've read posts by other people who've also encountered this problem in
their case it was usually a matter of forgetting to call Tcl_Init()
before Tk_Init() or the init.tcl script being from another version than
the embedded interpreter, but in my case I've made sure that the
versions are the same. What else could be causing this error?
The following sample is supposed to display a window saying "hello
world":
label .hello -text "Hello World"
pack .hello
Unfortunately it does not. The interpreter executes the commands and
then ends. No window is ever shown. =(
The [tcl_findLibrary] command should be auto-loaded when needed.
If not, check
1) Did you redefine the [unknown] command to do something else,
interfering with its auto-loading function?
2) Is the tclIndex file missing or corrupt?
Your program is probably failing to start an event loop.
Can you go back several steps and just consider dynamically
loading Tk in the usual way with
package require Tk
?
antred wrote:
> 1) call Tcl_CreateInterp()
> 2) Tcl_FindExecutable()
> 3) Tcl_Init()
> 4) Tk_Init()
> 5) done ??
> 6) Tcl_Eval( whatever_script_the_user_is_running )
7) churn the event loop until asked to exit.
I have more to say, but I'm off to "make the donuts" right now.
- --
David Gravereaux <davy...@pobox.com>
[species:human; planet:earth,milkyway(western spiral arm),alpha sector]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
iD8DBQFE+IHClZadkQh/RmERAkZbAKDApQIQh1iFy4C6Z99EiGUT9GiVbACgiujv
YD9gWYRf3++gvKVOJMOTMaA=
=YGXK
-----END PGP SIGNATURE-----
First off, thanks for your replies. With your help, I've solved most
(well, some) of the problems I've mentioned and I now almost have this
thing running. Just one final problem remains.
David Gravereaux wrote:
>
> 7) churn the event loop until asked to exit.
>
Do you have any idea how I would go about this? Previously, my MFC
application went about processing a Tcl script by passing the pathname
of the script to Tcl_EvalFile() ... which won't return until the script
is done. To fire up the event loop of Tk, I'd have to call
Tk_MainLoop() ... which never returns until the user closes the last Tk
window.
I guess the problem is that I'm essentially trying to combine a
sequential, synchronous execution mechanism (Tcl_EvalFile()) with an
event drive execution mechanism (Tk_MainLoop()) ... and I have no idea
how to do it. Perhaps it isn't even possible in the way I've dreamed it
up. =(