Skip to content

Commit

Permalink
Do not popup if returnError
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Apr 8, 2024
1 parent c2f75cd commit be27d72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ij/IJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static void setDebugMode(boolean b) {
/** Runs the macro contained in the string <code>macro</code>
on the current thread. Returns any string value returned by
the macro, null if the macro does not return a value, or
"[aborted]" if the macro was aborted due to an error. The
"[aborted]..." if the macro was aborted due to an error. The
equivalent macro function is eval(). */
public static String runMacro(String macro) {
return runMacro(macro, "");
Expand All @@ -153,7 +153,7 @@ public static String runMacro(String macro) {
on the current thread. The optional string argument can be
retrieved in the called macro using the getArgument() macro
function. Returns any string value returned by the macro, null
if the macro does not return a value, or "[aborted]" if the
if the macro does not return a value, or "[aborted]..." if the
macro was aborted due to an error. */
public static String runMacro(final String macro, final String arg) {
if(EventQueue.isDispatchThread()){
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ij/gui/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3321,7 +3321,7 @@ void drawShape(PlotObject plotObject, int x, int y, int size, int pointIndex) {
sb.append(plotObject.macroCode);
if (!drawingLegend ||!sb.toString().contains("d2s") ) {// a graphical symbol won't contain "d2s" ..
String rtn = IJ.runMacro(sb.toString());//.. so it can go to the legend
if ("[aborted]".equals(rtn))
if (rtn.startsWith("[aborted]"))
plotObject.macroCode = null;
}
WindowManager.setTempCurrentImage(null);
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/ij/plugin/Macro_Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ else if (name.endsWith(".py"))
/** Runs the specified macro on the current thread. Macros can retrieve
the optional string argument by calling the getArgument() macro function.
Returns the string value returned by the macro, null if the macro does not
return a value, or "[aborted]" if the macro was aborted due to an error. */
return a value, or "[aborted]..." if the macro was aborted due to an error. */
public String runMacro(String macro, String arg) {
Interpreter interp = new Interpreter();
try {
Expand All @@ -184,6 +184,13 @@ public String runMacro(String macro, String arg) {
IJ.showProgress(1.0);
ImagePlus imp = WindowManager.getCurrentImage();
if (imp!=null) imp.unlock();
if (returnError){
CharArrayWriter caw = new CharArrayWriter();
PrintWriter pw = new PrintWriter(caw);
e.printStackTrace(pw);
String s = caw.toString();
return "[aborted] Error:" + s;
}
String msg = e.getMessage();
if (e instanceof RuntimeException && msg!=null && e.getMessage().equals(Macro.MACRO_CANCELED))
return "[aborted]";
Expand All @@ -194,7 +201,7 @@ public String runMacro(String macro, String arg) {

/** Runs the specified macro from a JAR file in the plugins folder,
passing it the specified argument. Returns the String value returned
by the macro, null if the macro does not return a value, or "[aborted]"
by the macro, null if the macro does not return a value, or "[aborted]..."
if the macro was aborted due to an error. The macro can reside anywhere
in the plugins folder, in or out of a JAR file, so name conflicts are possible.
To avoid name conflicts, it is a good idea to incorporate the plugin
Expand Down

0 comments on commit be27d72

Please sign in to comment.