help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

perlTK


From: John W. Eaton
Subject: perlTK
Date: Thu, 27 Jan 2000 02:51:33 -0600 (CST)

On 21-Jan-2000, Daniel Heiserer <address@hidden> wrote:

| My question for a fast-hack-gui:
| 
| can I launch a perl script via "system" or
| something else, redirect the
| input of octave to a pipe which is fed
| by perlTK of the perlscript?
| Can I exit the perlscript, or 
| "pause" it somehow, in the way that octave
| goes back to the STDIN, and 
| when my terminal hacking is
| finished I redirect to my
| perlTK gui?

If what you are asking is how to make Octave continue to accept input
at the command-line prompt and also process GUI events, I think the
answer is to register an event hook function with readline.

Although the example I've appended below is not for Octave, it does
demonstrate what is required.  If you notice that the GUI is sluggish,
it might be that your copy of readline sets up a 0.1s delay in the
function rl_gather_tyi (see input.c) which is called by rl_read_key
after each call to the rl_event_hook function.  Remove the code that
sets up the delay, and your GUI should respond better.

FWIW, I am not really interested in GUI solutions that use the
approach of writing functions like

  tcl_tk_send ("some tcl/tk commands");
  results = tcl_tk_receive ();

because then the details of a particular toolkit become too entangled
with Octave, making it very difficult to switch to something new or
better.  (If you disagree with this, then think for a moment about the
current situation with Octave and gnuplot.)

jwe

  

/* Compile with:

   gcc -o foo tkHelloWorld.c -I/usr/X11R6/include -L/usr/X11R6/lib
       -ltk4.2 -ltcl7.6 -lX11 -lreadline -lncurses -ldl -lieee -lm -lc
*/

#include <stdio.h>

#include <tcl.h>
#include <tk.h>

#include <readline/readline.h>
#include <readline/history.h>

void
do_nothing (ClientData data, int i)
{
}

int
event_hook ()
{
  return Tcl_DoOneEvent (TCL_ALL_EVENTS);
}

extern void rl_deprep_terminal (void);

void
clean_up_and_exit (ClientData data)
{
  rl_deprep_terminal ();
  puts ("\n");
  exit (0);
}

int
main (int argc, char **argv)
{
  int retval = 0;

  Tcl_Interp *interp = 0;

  rl_event_hook = event_hook;

  Tcl_CreateExitHandler (clean_up_and_exit, 0);

  interp = Tcl_CreateInterp ();

  Tcl_Init (interp);

  if (Tk_Init (interp) == TCL_ERROR)
    {
      printf ("%s\n", interp->result);

      retval = 1;
    }
  else
    {
      int done = 0;

      Tk_CreateFileHandler (0, TK_READABLE, do_nothing, 0);

      while (! done)
        {
          char *line = readline ("tk> ");

          if (line)
            {
              if (*line)
                {
                  add_history (line);

                  Tcl_Eval (interp, line);
                }
            }
          else
            done = 1;
        }
    }

  Tcl_DeleteInterp (interp);

  return retval;
}


  



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]