Files
2026-06-17 14:00:51 +02:00

55 lines
2.2 KiB
Plaintext

This folder contains Jynstruments sorted by the place they extend.
***********************
* What's a Jynstrument?
***********************
A Jynstrument is a bundle of Jython code and other resources packaged in a a .jyn folder.
They're intended to extend the UI of JMRI and to be easily customizable by advanced end users without modifying the Java JMRI code.
For example a XYZ Jynstrument would look like this:
XYZ.jyn folder containing a XYZ.py file in which is defined a XYZ class derived from the jmri.jmrit.jython.Jynstrument class.
The Light.jyn Jynstrument is a good starting point, it simply adds a control to Function 0 for a Throttle.
To use it simply drag'n drop the Light.jyn folder into a JMRI Throttle control window.
****************************
* How to write a Jynstrument?
*****************************
Once again the Light.jyn sample is a good starting point.
Your Jynstrument must inherit from the Jynstrument class like that:
import jmri.jmrit.jython.Jynstrument as Jynstrument
class Test(Jynstrument):
The Jynstrument class itself inherits from javax.swing.JPanel .
Your Jynstrument *must* define the following methods:
def getExpectedContextClassName(self):
Must returns a string indicating the class that shall be expected as context. (java.lang.Object will open all doors)
def init(self):
This method will be called by instrumented class once all Jynstrument has been instantiated and internally initiated.
def quit(self):
This method will be called when the Jynstrument is quitting (particularly to unregister from used listeners)
Your Jynstrument will have the following methods available:
self.getContext() : Access a JMRI object instance, it is set by the Jynstrumented code, and usually is of the class defined by getExpectedContextClassName(self).
self.getFolder() : Returns a string containing the folder from where the Jython was loaded (useful to load resources files)
********************************************
* How to get some Java code Jynstrumentable?
********************************************
Please see class jmri.jmrit.throttle.ThrottleFrame code and search for #JYNSTRUMENT#, that's where the Light.jyn sample is loaded and executed.