The Script
Editor
In the template
editor it is possible to select a
script as executable code.
In other words you can write the code used to calculate a function in form of
a script. Matrex includes by default the Jython interpreter and there are plugins for JRuby and Groovy.
To make things, Matrex includes a script editor which is actually a small IDE. It allows you to:
- Write/edit the script using an editor that has some limited but useful syntax highlighting.
- Test the script with some test input matrices, output matrices and parameters.
In this way you can be reasonably sure that the script will work when used to calculate matrices in a project.
To create or edit a script select the application menu System
-> Edit Scripts.
The following window appears:
The editor is on the top right side of the IDE.
It supports a limited syntax highlighting (only keywords, operators and
special characters) but it is confortable for writing scripts, that in
general should not be larger than a hundreds lines.
You can:
- Load a script on this editor with the Load
button in the toolbar Select the script type (Jython is included by
default in Matrex) and load the script file using the Open File dialog,
with the correct extension (py for Jython)
- Create a new script, using the New button in the toolbar. Again, to make things simple this menu loads the skeleton of a script in the selected language.
Writing a script means writing the code for the calculation class which inherits from IFunction (as you do in java).
Once your script is written, you can test it using the views on the right side of the window:
- Input Matrices, to add the input matrices for the script, in the same order as expected by the script.
You can add input matrices pressing the Add
button on the top of the view. This shows a menu to choose the type of
the matrix to add (numeric, text...), and opens the Matrix Size Dialog to get the initial size of the matrix. The last step is to write the content of the matrix with the Matrix Script Editor. The matrix is added at the bottom of the list of matrices.
The view has also a popup menu, which can be showed clicking the right button of the mouse on it.
The menu has the following entries:
- Edit, to edit the selected matrix, using the the Matrix Script Editor.
- Remove, to remove the selected matrix (it needs you to confirm).
- Insert Before, which behaves like Add, but adding the matrix before the selected one.
- Output Matrices, to add the output matrices for the script, in the same order as expected by the script.
You can add input matrices pressing the Add
button on the top of the view. This shows a menu to choose the type of
the matrix to add (numeric, text...) and then adds it. Since it is an
output matrix it is initially empty and it is the script that fills it
when executed.
The view has also a popup menu, which can be showed clicking the right button of the mouse on it.
The menu has the following entries:
- View, to show the selected matrix in the Matrix Viewer.
- Remove, to remove the selected matrix (it needs you to confirm).
- Insert Before, which behaves like Add, but adding the matrix before the selected one.
- Parameters, to add the input parameters for the script, in the same order as expected by the script.
You can add parameters pressing the Add
button on the top of the view. This shows a menu to choose the type of
the parameter to add (numeric, text...) and opens the Parameter For Script Editor to write name and value of the parameter. The parameter is added at the bottom of the list of parameters.
The view has also a popup menu, which can be showed clicking the right button of the mouse on it.
The menu has the following entries:
- Remove, to remove the selected parameter (it needs you to confirm).
- Insert Before, which behaves like Add, but adding the parameter before the selected one.
Once all matrices and parameters are in place, you can execute it using the Run button in the toolbar.
The output of the script (print...) is written in the output view on the window's left bottom side.
If the script has errors, the errors are also writtent in the output view, in red.
If the script has success, it populates the output matrices, which can be viewed.
To save the script, press the Save
button on the top. If the script is new this display a save dialog to
give a path/name to the script file. If the script was only edited it
is saved without requesting a name/path, because it already has it.
The Save As button saves the script always requesting its name/path.
To know how to write
Jython code, go to the site
www.jython.org.
To know how to write a Matrex function, read the document
“Matrex
Function Coding”.