From: Ben Soares Date: Fri, 20 Oct 2023 15:57:29 +0000 (+0100) Subject: JAL-4298 Remove a stray return in the processGroovyScript method. Mildy improve a... X-Git-Tag: Release_2_11_4_0~131^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=bd2ad93a3ea4075bc45528e3505e9510ffde835d;p=jalview.git JAL-4298 Remove a stray return in the processGroovyScript method. Mildy improve a groovy example. Ensure consistent setting of groovy variables with JalviewObjectI fields. Update the currentAlFrame when run from Calculate menu. --- diff --git a/examples/groovy/stripUniprotPrefixes.groovy b/examples/groovy/stripUniprotPrefixes.groovy index 2792604..5a01da4 100644 --- a/examples/groovy/stripUniprotPrefixes.groovy +++ b/examples/groovy/stripUniprotPrefixes.groovy @@ -47,5 +47,6 @@ for (ala in af) } } } + ala.repaint(); } diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 3006f1f..e02d132 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -851,7 +851,6 @@ public class Commands if (af == null) { addWarn("Groovy script does not have an alignment window. Proceeding with caution!"); - return; } if (avm.containsArg(Arg.GROOVY)) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 783f533..83efe7d 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -1753,8 +1753,8 @@ public class Jalview implements JalviewObjectI { JalviewObjectI j = new JalviewObject(this); Map vbinding = new HashMap<>(); - vbinding.put("Jalview", j); - vbinding.put("currentAlFrame", + vbinding.put(JalviewObjectI.jalviewObjectName, j); + vbinding.put(JalviewObjectI.currentAlFrameName, af != null ? af : getCurrentAlignFrame()); Binding gbinding = new Binding(vbinding); GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile }); diff --git a/src/jalview/bin/groovy/JalviewObjectI.java b/src/jalview/bin/groovy/JalviewObjectI.java index 775ab2a..f365d30 100644 --- a/src/jalview/bin/groovy/JalviewObjectI.java +++ b/src/jalview/bin/groovy/JalviewObjectI.java @@ -8,7 +8,9 @@ public interface JalviewObjectI public AlignFrame getCurrentAlignFrame(); - public static AlignFrame currentAlFrame = null; + public final static String currentAlFrameName = "currentAlFrame"; + + public final static String jalviewObjectName = "Jalview"; public void quit(); } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index ae14539..ac8ffb9 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -95,6 +95,7 @@ import jalview.api.analysis.SimilarityParamsI; import jalview.bin.Cache; import jalview.bin.Console; import jalview.bin.Jalview; +import jalview.bin.groovy.JalviewObjectI; import jalview.commands.CommandI; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; @@ -5969,6 +5970,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { try { + console.setVariable(JalviewObjectI.currentAlFrameName, this); console.runScript(); } catch (Exception ex) { diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index b1f9000..1cedf3b 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -2663,8 +2663,9 @@ public class Desktop extends jalview.jbgui.GDesktop { JalviewObjectI j = new JalviewObject(this); groovyConsole = new groovy.console.ui.Console(); - groovyConsole.setVariable("Jalview", j); - groovyConsole.setVariable("currentAlFrame", getCurrentAlignFrame()); + groovyConsole.setVariable(JalviewObjectI.jalviewObjectName, j); + groovyConsole.setVariable(JalviewObjectI.currentAlFrameName, + getCurrentAlignFrame()); groovyConsole.run(); /*