Tcl/Tk scripts run inside C program 
Author Message
 Tcl/Tk scripts run inside C program

Hi all,

I am having some problems with running Tcl/Tk scripts inside my C program
(Tcl/Tk 8.3.3 from ActiveState on Win2k).  Originally, I used this bit of
code to run my Tcl scripts.

interp = Tcl_CreateInterp();
status = Tcl_EvalFile(interp,file_name);
Tcl_DeleteInterp(interp);

This worked all fine and dandy, but then I wanted to make Tk work.  I look
in a book and they show how to use code like this:

Tk_Main(dummyArgc, dummyArgv, Tk_AppInit);

with

int Tk_AppInit(Tcl_Interp * interp)
{

   char file_name[260];
   int status;

   // Initialize Tcl
   status = Tcl_Init(interp);
   if (status != TCL_OK)
   {
      return TCL_ERROR;
   }

   // Initialize Tk
   status = Tk_Init(interp);
   if (status != TCL_OK)
   {
      return TCL_ERROR;
   }

   // tell Tcl/Tk about our commands here

      // Do the commands in the tcl script
      status = Tcl_EvalFile(interp,file_name);

      return TCL_OK;

Quote:
}

This works, but when you exit Tk, either through the exit command, clicking
the Windows 'x' in the corner or using destroy ., you quit the entire
application!  I just want the tcl script to quit, not the entire
application.

How can I make just the script quit?  I'm looking to either hack the
existing Tk_Main/TkAppInit stuff that I currently have OR adding to the
older version of the code that I originally used.  Either way works just
fine for me.

Also, right now I have two menu options for users:  Run Tcl Script and Run
Tk Script, depending on whether the script uses Tk.  Mostly this is just to
avoid the little window in non-Tk scripts.  Is there any way to get the
little window to not show up?  I saw the post a few days ago, but the
scripts will be used by Scientists, not programmers, so I want to have as
clean of a solution as possible - no having to put 'exit' at the end of
their scripts and no dealing with the bonus window that gets created.
Handling it in TkAppInit would be best.

Thanks,

Dana Robinson



Sun, 27 Jun 2004 09:15:15 GMT  
 Tcl/Tk scripts run inside C program
By the way, I can make init.tcl an empty script and I get the same problem
where the entire application quits, so it's probably not something in
init.tcl.  It still could be something that init.tcl doesn't do, though.

Thanks,

Dana



Sun, 27 Jun 2004 10:14:28 GMT  
 Tcl/Tk scripts run inside C program

Quote:

> How can I make just the script quit?  I'm looking to either hack the
> existing Tk_Main/TkAppInit stuff that I currently have OR adding to the
> older version of the code that I originally used.  Either way works just
> fine for me.

Use a modified Tk_Main(), since that's what is shutting down the program.  Just
copy it and adjust to taste.

Quote:
> Also, right now I have two menu options for users:  Run Tcl Script and Run
> Tk Script, depending on whether the script uses Tk.  Mostly this is just to
> avoid the little window in non-Tk scripts.  Is there any way to get the
> little window to not show up?  I saw the post a few days ago, but the
> scripts will be used by Scientists, not programmers, so I want to have as
> clean of a solution as possible - no having to put 'exit' at the end of
> their scripts and no dealing with the bonus window that gets created.
> Handling it in TkAppInit would be best.

IIRC, it is possible in recent versions of Tcl to do [package require Tk] (or
something like that) and have Tk load if and when needed.  But I'm no expert on
this so there's probably crucial details (like how recent the versions need to
be) that I'm missing out here.

Donal.
--

-- Short attention span since- ooh! Shiny thing on the floor!



Sun, 27 Jun 2004 17:57:08 GMT  
 Tcl/Tk scripts run inside C program

Quote:


> > How can I make just the script quit?  I'm looking to either hack the
> > existing Tk_Main/TkAppInit stuff that I currently have OR adding to the
> > older version of the code that I originally used.  Either way works just
> > fine for me.

> Use a modified Tk_Main(), since that's what is shutting down the program.  Just
> copy it and adjust to taste.

AFAIK, the close button is invoking the equivalent to the script level
'exit' command  and the exit command is terminating the process
regardless if you use Tk_Main() or not.

You can override the action of the close button by
wm protocol (window name) WM_DELETE_WINDOW {puts "user closed window"}

You need a clear concept of how the scripts should be evaluated. Probely
you should really avoid Tk_Main() and use Tcl_DoOneEvent() inside a loop
instead.

-sacha



Sun, 27 Jun 2004 20:09:35 GMT  
 Tcl/Tk scripts run inside C program

Quote:

> AFAIK, the close button is invoking the equivalent to the script level
> 'exit' command  and the exit command is terminating the process
> regardless if you use Tk_Main() or not.

No, the close button only ever kills that one window (and its children, which is
all the other windows in that interpreter.)  That wish exits when all the
windows go away is functionality that is defined in Tk_Main(), and not part of
the default WM_DELETE_WINDOW handler.

Donal.
--

-- Short attention span since- ooh! Shiny thing on the floor!



Sun, 27 Jun 2004 22:38:00 GMT  
 Tcl/Tk scripts run inside C program

Quote:

> > AFAIK, the close button is invoking the equivalent to the script level
> > 'exit' command  and the exit command is terminating the process
> > regardless if you use Tk_Main() or not.

> No, the close button only ever kills that one window (and its children, which is
> all the other windows in that interpreter.)  That wish exits when all the
> windows go away is functionality that is defined in Tk_Main(), and not part of
> the default WM_DELETE_WINDOW handler.

In my application the process is stopped when the exit command occures.
And i am definitily not using Tk_Main(). (I'm using Tcl/Tk 8.33
(thread-enabled) on WinNt). I'm also surprised about this behaviour but
it is actually the case.
-sacha


Mon, 28 Jun 2004 00:29:32 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Running Tcl Scripts inside Tcl

2. Running a Tcl/Tk applet within a Tcl/Tk program

3. Jacl -- Running Tcl Scripts inside Java

4. Jacl -- Running Tcl Scripts inside Java

5. Jacl -- Running Tcl Scripts inside Java

6. Executing Tcl script inside a Tcl script

7. Running a TK script using wish80.exe within a tcl script

8. Jacl -- Running Tcl Scripts inside Java

9. Jacl -- Running Tcl Scripts inside Java

10. problems running tk-script with tcl/tk 8.3.3

11. Run Tk scripts from Windows C++ program

12. run Tcl/TK script from within Vim?

 

 
Powered by phpBB® Forum Software