Search in sources :

Example 1 with CommandLinePluginRunner

use of qupath.lib.plugins.CommandLinePluginRunner in project qupath by qupath.

the class QPEx method runPlugin.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static boolean runPlugin(final String className, final ImageData<?> imageData, final String args) throws InterruptedException {
    if (imageData == null)
        return false;
    boolean completed = false;
    String pluginName = className;
    boolean cancelled = false;
    try {
        Class<?> cPlugin = QP.class.getClassLoader().loadClass(className);
        Constructor<?> cons = cPlugin.getConstructor();
        final PathPlugin plugin = (PathPlugin) cons.newInstance();
        pluginName = plugin.getName();
        PluginRunner runner;
        // TODO: Give potential of passing a plugin runner
        var qupath = getQuPath();
        if (isBatchMode() || imageData != qupath.getImageData()) {
            runner = new CommandLinePluginRunner(imageData);
            completed = plugin.runPlugin(runner, args);
            cancelled = runner.isCancelled();
        } else {
            completed = qupath.runPlugin(plugin, args, false);
            cancelled = !completed;
        // runner = new PluginRunnerFX(qupath);
        }
    } catch (Exception e) {
        logger.error("Error running plugin {}: {}", className, e.getLocalizedMessage());
        logger.error("", e);
    }
    // Notify caller that this failed
    if (cancelled)
        throw new InterruptedException(pluginName + " cancelled!");
    // }
    return completed;
}
Also used : CommandLinePluginRunner(qupath.lib.plugins.CommandLinePluginRunner) PluginRunner(qupath.lib.plugins.PluginRunner) CommandLinePluginRunner(qupath.lib.plugins.CommandLinePluginRunner) PathPlugin(qupath.lib.plugins.PathPlugin) IOException(java.io.IOException) QP(qupath.lib.scripting.QP)

Aggregations

IOException (java.io.IOException)1 CommandLinePluginRunner (qupath.lib.plugins.CommandLinePluginRunner)1 PathPlugin (qupath.lib.plugins.PathPlugin)1 PluginRunner (qupath.lib.plugins.PluginRunner)1 QP (qupath.lib.scripting.QP)1