Menu Tool in python

plugin
macro
Tags: #<Tag:0x00007fb882908818> #<Tag:0x00007fb882908070>

#1

I am wanting to add a toolbar menu tool analogous to the “Developer menu” that runs a set of python macros.
I know I can do this adding a .txt. or .ijm file to the toolsets folder that will do this with coding something like the functional text code below.

However, I would rather have the whole tool file be a single .py file
rather than having to call separate files using call.plugin.Macro_Runner.runPython.

Is this possible?

/-------------------------------------------------------------------
var mCmds = newMenu("New Menu Tool",newArray("run macro 1 [F1]",
"run macro 2 [F2]"));

macro "New Menu Tool - 	C037T1b12M"
{
	cmd = getArgument();
	if (cmd!="-" && cmd == "run macro 1 [F1]"){ 
		jythonText = File.openAsString("/Applications/Fiji.app/plugins/Scripts/Python_Animation.py"); 
	call("ij.plugin.Macro_Runner.runPython", jythonText, ""); 
	}
	if (cmd!="-" && cmd == "run macro 2 [F2]") 
		{ 
		jythonText = File.openAsString("/Applications/Fiji.app/plugins/Scripts/Python_Animation.py"); 
	call("ij.plugin.Macro_Runner.runPython", jythonText, ""); 
	}

}

/***********************************************/
macro "run macro 1 [F1]"
{
	jythonText = File.openAsString("/Applications/Fiji.app/plugins/Scripts/Python_Animation.py"); 
	call("ij.plugin.Macro_Runner.runPython", jythonText, "");    
}
/***********************************************/
macro  "run macro 2 [F2]" 
		{
	jythonText = File.openAsString("/Applications/Fiji.app/plugins/Scripts/Python_Animation.py"); 
	call("ij.plugin.Macro_Runner.runPython", jythonText, "");    
}

#2

What you’re trying to do is overly complicated, if I understand correctly what you’re trying to achieve.

Just put your Python script in in a subdirectory of the Fiji.app/plugins/Scripts/ directory already (or, even easier, a subdirectory of Fiji.app/scripts/), and it will show up in the menu at the position defined by the subdirectory tree, e.g.:

  • Fiji.app/scripts/Image/Python_Animation.py will show up as Image > Python Animation in the menu.

You can then use the run() command to call your script:

run("Python Animation");

So your toolbar menu could look similar to this:

var mCmds = newMenu("New Menu Tool",newArray("run macro 1 [F1]", "run macro 2 [F2]"));

macro "New Menu Tool - 	C037T1b12M"
{
	cmd = getArgument();
	if (cmd == "run macro 1 [F1]") {
		run("Python Animation");
	}
	if (cmd == "run macro 2 [F2]") {
		run("Python Animation");
	}
}

#3

Thanks Jan,
That is good to know.

However, to get [F1] and [F2} keys to function one still has to add to the code

macro “run macro 1 [F1]”{
run(“Python Animation”);}

macro “run macro 2 [F2]” {
run(“Python Animation”); }

This still does not deal with my fundamental issue which I would like to deal with:
I would like to be able to simply put one file into toolsets (or Scripts) rather than having to drag 7 files into FIJI.

So what I am looking for is how one in a python script I could
declare a macro Menu Tool so I can simply have one file
and think of the various menu options as different actions in one larger plug in.

I hope I am making sense.


#4

As an example,
kymoClear 2.0 is representative of what I want to accomplish
but is written using the ijm scripting language, not python.