Difference between revisions of "Using the Script Editor"

(Add parameter tutorial)
(Add collapse logic for 'scripting' in menu)
 
(15 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
| software              = ImageJ
 
| software              = ImageJ
 
| author                = Johannes Schindelin, Sumit Dubey (Google Summer of Code 2009)
 
| author                = Johannes Schindelin, Sumit Dubey (Google Summer of Code 2009)
| maintainer            = Johannes Schindelin
+
| maintainer            = {{Person|Rueden}}
| source                = {{GitHub|org=imagej|repo=imagej-ui-swing|source=net/imagej/ui/swing/script/ScriptEditor.java}}
+
| source                = {{GitHub|org=scijava|repo=script-editor|source=org/scijava/ui/swing/script/ScriptEditor.java}}
 
| released              = 11 Sep 2008
 
| released              = 11 Sep 2008
 
| status                = active
 
| status                = active
}}{{Scripting}}
+
}}The script editor is an invaluable help when writing scripts in any of ImageJ's supported [[Scripting comparisons|languages]].{{Learn | scripting}}
 +
== Features ==
 +
;Text Editing
 +
* Full undo support
 +
* Auto-indent
 +
* Configurable white-space options
  
The script editor is an invaluable help when writing scripts in any of ImageJ's supported [[Scripting comparisons|languages]].
+
;Programming
 +
* Syntax highlighting
 +
* Output console
 +
* Git integration (file being edited must be part of a [[Git]] repository)
 +
* Language specific [[Script Templates|templates]]
 +
* Find and replace using regex patterns
 +
* Automatic brace highlighting
 +
* Line numbers
  
 +
;Language specific tools
 +
* Organization of <tt>import</tt> declarations
 +
* Access to online documentation ([http://javadoc.imagej.net Javadocs], [http://imagej.nih.gov/ij/developer/macro/functions.html Built-in Macro Functions])
 +
* Access to source code in <tt>.jar</tt> files
 +
 +
;Interface
 +
* Bookmarks
 +
* Tabs for easy switching between open files
 +
* Navigation shortcuts
 +
 +
== Usage ==
 
=== Starting the editor ===
 
=== Starting the editor ===
  
 
To get started, start up the script editor:
 
To get started, start up the script editor:
  
[[Image:Script-Editor-new.jpg]]
+
[[Image:Script-Editor-new.jpg|500px]]
  
There is also the keyboard shortcut {{key|{}} (open curly bracket) to open the editor.
+
There is also the keyboard shortcut {{key|[}} (open square bracket) to open the editor.
  
 
=== Choosing a language ===
 
=== Choosing a language ===
Line 42: Line 65:
 
[[Image:Script-Editor-dialog.jpg]]
 
[[Image:Script-Editor-dialog.jpg]]
  
=== Script Parameters ===
+
== Further reading ==
 
+
See the [[Scripting Help]] page for an introduction to scripting. For more information about each specific language, see the Languages section of top right sidebar.
There is a universal <code>@ parameter</code> notation available across all scripts for declaring inputs and outputs. The rules for their use is as follows:
 
 
 
<ol>
 
<li>All parameter declarations must appear in comments. Each comment line contains a single parameter declaration and nothing else.</li>
 
<li>Any parameters after the first non-parameter line will not be recognized.</li>
 
<li><code>@type variableName</code> will declare an input of the indicated type, assigned to the specified name.</li>
 
<li><code>@OUTPUT type outputName</code> will declare the variable of the specified name as an output parameter with the given type.</li>
 
</ol>
 
 
 
For example, if we look at the Greeting.py template supplied with Fiji:
 
 
 
<source lang="Python">
 
# @String name
 
# @OUTPUT String greeting
 
 
 
# A Jython script with parameters.
 
# It is the duty of the scripting framework to harvest
 
# the 'name' parameter from the user, and then display
 
# the 'greeting' output parameter, based on its type.
 
 
 
greeting = "Hello, " + name + "!"
 
</source>
 
 
 
We see that an input parameter <code>name</code> of type <code>String</code> is declared. This will automatically be harvested via a pop-up dialog when the script is run.
 
 
 
When the script is completed, we expect to have a <code>String</code> variable named <code>greeting</code> which will be displayed as appropriate, based on the variable type.
 
 
 
Note that if we added an extra comment to the top of our script as such:
 
 
 
<source lang="Python">
 
# A simple python script
 
# @String name
 
# @OUTPUT String greeting
 
 
 
# A Jython script with parameters.
 
# It is the duty of the scripting framework to harvest
 
# the 'name' parameter from the user, and then display
 
# the 'greeting' output parameter, based on its type.
 
 
 
greeting = "Hello, " + name + "!"
 
</source>
 
 
 
We would actually break the script, as the parameters would not be harvested or displayed due to violation of the second parameter rule.
 
 
 
=== Further reading ===
 
 
 
There are introductions into the following supported languages: [[Introduction into Macro Programming|ImageJ Macro Language]], [[Beanshell_Scripting|Beanshell]], [[Javascript_Scripting|Javascript]], [[JRuby_Scripting|JRuby]], [[Jython_Scripting|Jython]], and [[Clojure_Scripting|Clojure]] (see also [[Scripting Help]]).
 
  
 
[[Category:Plugins]]
 
[[Category:Plugins]]
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 
[[Category:Scripting]]
 
[[Category:Scripting]]

Latest revision as of 14:01, 23 January 2017

Script Editor (ImageJ)
Author Johannes Schindelin, Sumit Dubey (Google Summer of Code 2009)
Maintainer Curtis Rueden
Source on GitHub
Initial release 11 Sep 2008
Development status active

The script editor is an invaluable help when writing scripts in any of ImageJ's supported languages.

Learn
Topics
Introduction
Getting Started
User Guides
Tutorials
Tips and Tricks
Presentations
Plugins
Techniques
All Techniques
Colocalization
Deconvolution
Registration
Segmentation
Stitching
Tracking
Visualization
Scripting
Overview
User input
Basics of script writing
Batch processing
Script Editor
Auto Imports
Templates
Running headlessly
Comparisons
Toolbox
Multithreading in Clojure
Multithreading in JavaScript
Chess in Jython
Languages
BeanShell
Groovy
ImageJ Macro
JavaScript
Lisp (Clojure)
MATLAB
Python (Jython)
R (Renjin)
Ruby (JRuby)
Scala


Features

Text Editing
  • Full undo support
  • Auto-indent
  • Configurable white-space options
Programming
  • Syntax highlighting
  • Output console
  • Git integration (file being edited must be part of a Git repository)
  • Language specific templates
  • Find and replace using regex patterns
  • Automatic brace highlighting
  • Line numbers
Language specific tools
Interface
  • Bookmarks
  • Tabs for easy switching between open files
  • Navigation shortcuts

Usage

Starting the editor

To get started, start up the script editor:

Script-Editor-new.jpg

There is also the keyboard shortcut [ (open square bracket) to open the editor.

Choosing a language

Then choose a language from the language menu:

Script-Editor-choose-language.jpg

Now you can write your script. In this tutorial, Jython was chosen as scripting language, but the process is really the same for all scripting languages.

Script-Editor-first-script.jpg

Running the script

Once you are satisfied with the script, run it. This does not require saving, but of course you should save your script later when it works.

Script-Editor-run.jpg

Note that while the script is running, the window title shows the tell-tale (Running).

You can use all of ImageJ's classes right away. Here is an example that shows a dialog where the user can input a number. For details how to write dialogs in the different scripting languages, see Scripting comparisons

Script-Editor-dialog.jpg

Further reading

See the Scripting Help page for an introduction to scripting. For more information about each specific language, see the Languages section of top right sidebar.