Closed NicoKiaru closed 2 years ago
This PR depends on a snapshot version of scijava-ui-swing and explicitely overrides scijava-common for the moment,
To test it, here are two simple groovy scripts:
#@TaskService taskService
def task = taskService.createTask("Task 0");
task.setProgressMaximum(100)
task.run(() -> {
try {
Thread.sleep(2000)
task.setProgressValue(20)
Thread.sleep(2000)
task.setProgressValue(40)
Thread.sleep(2000)
task.setProgressValue(60)
Thread.sleep(2000)
task.setProgressValue(80)
Thread.sleep(2000)
IJ.log('Done')
} catch (InterruptedException e) {
IJ.log(task.getCancelReason())
IJ.log('Interrupted')
}
})
try {
task.waitFor() // If you want to wait for the end of the task, will return if cancelled
} catch (Exception e) {
}
IJ.log("Task "+task.getName()+" cancelled ? "+task.isCanceled())
import ij.IJ
And
#@TaskService taskService
#@File file
def task = taskService.createTask("Task 0");
task.setProgressMaximum(100)
task.start()
def isCancelled = false
task.setCancelCallBack(() -> {
IJ.log('User interrupted')
isCancelled = true
})
Thread.sleep(2000)
task.setProgressValue(20)
Thread.sleep(2000)
task.setProgressValue(40)
Thread.sleep(2000)
if (isCancelled) {
task.finish()
} else {
task.setProgressValue(60)
Thread.sleep(2000)
task.setProgressValue(80)
Thread.sleep(2000)
IJ.log('Done')
task.finish()
}
IJ.log("Task cancelled ? "+task.isCanceled())
import ij.IJ
The modification of the batch processor comes in a separate and independent PR
This pull request has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/demo-and-proposal-new-progress-bars-for-fiji/64956/6