Package gda.jython

Class GDAJythonInterpreter

java.lang.Object
gda.jython.GDAJythonInterpreter

public class GDAJythonInterpreter extends Object

Wrapper for the JythonInterpreter class.

IMPORTANT: for the classes in this package to work properly jython must be fully installed on the machine and the jython.jar located in the jython installation folder must be referenced in the java classpath. Jython.jar must NOT be located anywhere else. This is because there is more to jython than just the files in jython.jar(!).****

  • Constructor Details

    • GDAJythonInterpreter

      public GDAJythonInterpreter(ScriptPaths scriptPaths)
  • Method Details

    • exec

      protected void exec(String input) throws org.python.core.PyException
      Translates and then runs the given file through the Jython interpreter.
      Parameters:
      input - File
      Throws:
      org.python.core.PyException
    • runscript

      protected void runscript(String input)
      Runs the script updating the CommandServer status as it goes.
      Parameters:
      input - script to run
    • runsource

      protected boolean runsource(String command)
      Gives the command to the JythonInterpreter's runsource method
      Parameters:
      command - String to run in interpreter
      Returns:
      boolean
    • getFromJythonNamespace

      protected Object getFromJythonNamespace(String objectName)
      Get the object from the Jython namespace known by the given string.
      Parameters:
      objectName -
      Returns:
      Object
    • getAllFromJythonNamepsace

      public org.python.core.PyObject getAllFromJythonNamepsace()
      Returns the contents of the top-level namespace.

      This returns object references so cannot be distributed.

      Returns:
      PyObject
    • placeInJythonNamespace

      protected void placeInJythonNamespace(String objectName, Object obj)
      Place an object into the Jython namespace.
      Parameters:
      objectName - What the object is to be known as.
      obj -
    • evaluate

      protected String evaluate(String command)
      Runs a Jython command which returns some output. As the Jython engine is in a distributed environment, only strings are returned. Object references will also be converted to strings.
      Parameters:
      command - String - must be python code - cannot run import javaclass - this results in fixParseError - unknown source
      Returns:
      String
    • setTranslator

      protected void setTranslator(Translator myTranslator)
      Changes dynamically the translator being used.
      Parameters:
      myTranslator -
    • getTranslator

      protected static Translator getTranslator()
      Returns:
      the translator
    • translateScriptToGDA

      public static String translateScriptToGDA(String input)
      Creates a script in a format compatible with the GDAJythonInterpreter runcode method. The main part of the script is from the input object. All lines are translated from GDA syntax into true Jython from GDA syntax where necessary. A header and footer are then added to make the script run in a separate thread, so that the GUI does not freeze up.
      Parameters:
      input - a Jython script
      Returns:
      a string of the same Jython code (translated to true Jython where required) which will run in its own thread
    • getInterp

      public org.python.util.InteractiveConsole getInterp()