To do that, follow the GraalVM install instructions to install a Java 11 version.
Once you do that and start JMRI, a "Python 3" choice should appear in the language selector in the Script Input Window, and the file choosers for running scripts should give you a similar choice.
Our convention is that Python 3 files use a .py3 extension.
import jmri as jmri
import java
exec( open("jython/jmri_bindings.py3").read() )
The third line is the Py3 syntax to read and execute another script file.
In this case, it reads and executes the file that defines a number of
symbols like `THROWN``, `turnouts`, etc.
manager = jmri.InstanceManager.getNullableDefault('jmri.MyManager')
(note quotes). More generally, if you need access to a Java type
object for other purposes, you can get it with
java.type('jmri.MyManager')
but we've provided a new version of InstanceManager.getDefault and
InstanceManager.getNullableDefault that takes the class name as
a parameter to make those common operations simpler.
print (123)
DigitalIO.ON
, not Light.ON
.
class Automat(AbstractAutomaton) :
def init(self) :
print ("init in Python 3")
def handle(self) :
print ("handle in Python 3")
return False
but when you're doing that you can't add any additional
methods to the new class. This might require rethinking
how to connect Java class code to your own scripting code;
we hope to have some recommendations soon.
wait
calls in AbstractAutomaton
,
e.g. waitMsec(..)
and similar,
that can result in JMRI locking up. We don't currently
have a workaround for this.