Created
August 10, 2020 14:00
-
-
Save ap--/a65c448112adb0a4dd706b74e02021e4 to your computer and use it in GitHub Desktop.
QuPath startup.groovy script that enables per project startup.groovy scripts that can be provided with each project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Run a per project startup script on project load, if the project ships a | |
* 'startup.groovy' script in its project scripts directory. | |
* | |
* @author Andreas Poehlmann | |
*/ | |
import java.awt.image.BufferedImage | |
import javafx.beans.value.ChangeListener | |
import javafx.beans.value.ObservableValue | |
import qupath.lib.gui.scripting.DefaultScriptEditor | |
import qupath.lib.gui.QuPathGUI | |
import qupath.lib.projects.Project | |
import qupath.lib.projects.ResourceManager | |
gui = QuPathGUI.getInstance() | |
gui.projectProperty().addListener(new ChangeListener<Project<BufferedImage>>() { | |
@Override | |
void changed(ObservableValue<? extends Project<BufferedImage>> observable, Project<BufferedImage> oldProject, Project<BufferedImage> newProject) { | |
if (newProject == null) { | |
return | |
} | |
def manager = newProject.getScripts() | |
def script | |
try { | |
script = manager.get('startup') | |
} catch (IOException ignored) { | |
return | |
} | |
DefaultScriptEditor.executeScript(DefaultScriptEditor.Language.GROOVY, script, newProject, null, true, null) | |
} | |
}) | |
println("Registered per project 'startup.groovy' handler") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment