Skip to content

Instantly share code, notes, and snippets.

@lacan
Created August 3, 2023 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacan/8645cc14eed1f41e8addc40d65090c10 to your computer and use it in GitHub Desktop.
Save lacan/8645cc14eed1f41e8addc40d65090c10 to your computer and use it in GitHub Desktop.
[Create Progress Monitor in QuPath] Build a progress monitor that is either command line or graphical #qupath #groovy
// Example creating a dialog to run tasks in a script.
// We need to discern between headless and non-headless manually so far
// @author Olivier Burri
//
import qupath.lib.plugins.CommandLinePluginRunner
import qupath.lib.gui.PluginRunnerFX
// Define the runner, in this case we will not use it but it is quite powerful
def runner
if( getQuPath() != null ) {
runner = new PluginRunnerFX( getQuPath() )
} else {
runner = new CommandLinePluginRunner( null )
}
// We only need the runner to get the progress monitor
def monitor = runner.makeProgressMonitor()
// This is the total steps that the progress monitor will show
def maxUpdates = 10
//Use a try/catch/finally block. Otherwise errors will cause the dialog to remain and lock the JavaFX thread
try {
// startMonitoring(String name, int max_updates, bool isCancellable )
monitor.startMonitoring("My monitor", maxUpdates, true )
// Make some tasks
for( i=1; i<maxUpdates; i++) {
Thread.sleep(1000)
// updateProgress( int increment, String info, ImageRegion where are you)
monitor.updateProgress(1, "I am in $i", null)
// Do something in case the user clicks Cancel
if( monitor.cancelled() ) break
}
} catch(def error) {
println e.getMessage()
} finally {
// This denotes the end of the dialog
monitor.pluginCompleted("Progress Completes")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment