Package gda.jython
Class GDAJythonInterpreter
java.lang.Object
gda.jython.GDAJythonInterpreter
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(!).****
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classExtension of dictionary to use for python globals so that we can intercept sets and check that we're not overriding a protected name or aliased command.static classA builtin to provide a way for users to prevent names being overwritten. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringRuns a Jython command which returns some output.protected voidTranslates and then runs the given file through the Jython interpreter.org.python.core.PyObjectReturns the contents of the top-level namespace.protected ObjectgetFromJythonNamespace(String objectName) Get the object from the Jython namespace known by the given string.org.python.util.InteractiveConsoleprotected static Translatorprotected voidplaceInJythonNamespace(String objectName, Object obj) Place an object into the Jython namespace.protected voidRuns the script updating the CommandServer status as it goes.protected booleanGives the command to the JythonInterpreter's runsource methodprotected voidsetTranslator(Translator myTranslator) Changes dynamically the translator being used.static StringtranslateScriptToGDA(String input) Creates a script in a format compatible with the GDAJythonInterpreter runcode method.
-
Constructor Details
-
GDAJythonInterpreter
-
-
Method Details
-
exec
Translates and then runs the given file through the Jython interpreter.- Parameters:
input- File- Throws:
org.python.core.PyException
-
runscript
Runs the script updating the CommandServer status as it goes.- Parameters:
input- script to run
-
runsource
Gives the command to the JythonInterpreter's runsource method- Parameters:
command- String to run in interpreter- Returns:
- boolean
-
getFromJythonNamespace
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
Place an object into the Jython namespace.- Parameters:
objectName- What the object is to be known as.obj-
-
evaluate
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
Changes dynamically the translator being used.- Parameters:
myTranslator-
-
getTranslator
- Returns:
- the translator
-
translateScriptToGDA
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()
-