Skip to content

Instantly share code, notes, and snippets.

@petebankhead
Last active December 6, 2016 14:25
Show Gist options
  • Save petebankhead/c19186a30707b5c51aa5a8a9c0d2c6b1 to your computer and use it in GitHub Desktop.
Save petebankhead/c19186a30707b5c51aa5a8a9c0d2c6b1 to your computer and use it in GitHub Desktop.
Script that can be used to programmatically run a command from a QuPath menu
/*
* Sample script to run a GUI command from QuPath v0.1.1
*
* @author Pete Bankhead
*/
// Specify command to run
// Note: Only the simple name is required if the menu item has a unique name
// Otherwise, the full path to the menu item should be give, separated by >
def commandName = "Measure>Show annotation measurements"
//def commandName = "Fill annotations" // An alternative (selectable) command to test
// Request access to the main QuPath GUI
def qupath = getQuPath()
// Request the menu item
def mi = qupath.getMenuItem(commandName)
if (mi == null) {
print("Could not find menu item for " + commandName)
return
}
// Fire the menu item in the main JavaFX application thread
// Here, use some Groovy goodness to deal with selectable menu items differently
if (mi.metaClass.respondsTo(mi, "setSelected"))
javafx.application.Platform.runLater({-> mi.setSelected(!mi.isSelected())})
else
javafx.application.Platform.runLater({-> mi.fire()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment