From 79069d05aca9b0fdd7bba57b4ca40844f8a36bac Mon Sep 17 00:00:00 2001 From: Tiago Date: Thu, 24 Nov 2016 09:53:34 -0500 Subject: [PATCH] Use a single command to open tutorials --- ...orials.py => Open_Offline_Tutorials....py} | 13 ++++----- Snippets/Tutorials/Open_Python_Tutorials.py | 27 ------------------- Snippets/Tutorials/README.md | 2 +- 3 files changed, 8 insertions(+), 34 deletions(-) rename Snippets/Tutorials/{Open_BeanShell_Tutorials.py => Open_Offline_Tutorials....py} (77%) delete mode 100644 Snippets/Tutorials/Open_Python_Tutorials.py diff --git a/Snippets/Tutorials/Open_BeanShell_Tutorials.py b/Snippets/Tutorials/Open_Offline_Tutorials....py similarity index 77% rename from Snippets/Tutorials/Open_BeanShell_Tutorials.py rename to Snippets/Tutorials/Open_Offline_Tutorials....py index 53260763..ea4f2dcc 100644 --- a/Snippets/Tutorials/Open_BeanShell_Tutorials.py +++ b/Snippets/Tutorials/Open_Offline_Tutorials....py @@ -1,19 +1,20 @@ -import os, java.io.File -from ij import IJ +# @Context context +# @String(label="Tutorial", choices={"Python", "BeanShell"}) choice + + +import os, java.io.File, bar.Utils from bar import Utils -from org.scijava import Context from org.scijava.ui.swing.script import TextEditor # Specify the directory containing the files to be opened dir = Utils.getSnippetsDir() + "Tutorials" + os.sep # Specify the extension of the files to be opened -ext = ".bsh" +ext = ".py" if choice == "Python" else ".bsh" # If directory exists, create a new Script Editor window # and open each filtered file on a dedicated tab if Utils.fileExists(dir): - context = IJ.runPlugIn("org.scijava.Context", "") editor = TextEditor(context) for (root, dirnames, filenames) in os.walk(dir): for filename in filenames: @@ -24,4 +25,4 @@ # Select first tab, rename editor's window and display it editor.switchTo(0) editor.setVisible(True) - editor.setTitle("BAR Tutorial Files" + ext) + editor.setTitle("BAR Tutorial Files" + choice) diff --git a/Snippets/Tutorials/Open_Python_Tutorials.py b/Snippets/Tutorials/Open_Python_Tutorials.py deleted file mode 100644 index 46fd5a87..00000000 --- a/Snippets/Tutorials/Open_Python_Tutorials.py +++ /dev/null @@ -1,27 +0,0 @@ -import os, java.io.File -from ij import IJ -from bar import Utils -from org.scijava import Context -from org.scijava.ui.swing.script import TextEditor - -# Specify the directory containing the files to be opened -dir = Utils.getSnippetsDir() + "Tutorials" + os.sep - -# Specify the extension of the files to be opened -ext = ".py" - -# If directory exists, create a new Script Editor window -# and open each filtered file on a dedicated tab -if Utils.fileExists(dir): - context = IJ.runPlugIn("org.scijava.Context", "") - editor = TextEditor(context) - for (root, dirnames, filenames) in os.walk(dir): - for filename in filenames: - if "_" not in filename and filename.endswith(ext): - path = os.path.join(root, filename) - editor.open(java.io.File(path)) - - # Select first tab, rename editor's window and display it - editor.switchTo(0) - editor.setVisible(True) - editor.setTitle("BAR Tutorial Files" + ext) diff --git a/Snippets/Tutorials/README.md b/Snippets/Tutorials/README.md index 0b6eb417..c532cb27 100644 --- a/Snippets/Tutorials/README.md +++ b/Snippets/Tutorials/README.md @@ -6,7 +6,7 @@ at the [2015 ImageJ User & Developer Conference](http://imagej.net/Conference_20 They can be accessed from ImageJ using `BAR> Snippets> Tutorials` ##See also -Resources listed in [Snippets](https://github.com/tferr/Scripts/tree/master/Snippets#useful-resources) +Resources listed in [Snippets] | [Home] | [Analysis] | [Data Analysis] | [Annotation] | [Segmentation] | [Tools] | [Plugins][Java Classes] | [lib] | [Snippets] | [IJ] |