scyjava icon indicating copy to clipboard operation
scyjava copied to clipboard

Introspection in Fiji Script Editor

Open ian-coccimiglio opened this issue 8 months ago • 0 comments

I got around to testing introspection in scyjava, and it overall works quite nicely!

However, when using the (Python3-enabled) Fiji's Script Editor, the reflection functions print to the calling terminal, rather than the Fiji script editor (see screenshot below). I suspect this behavior arises because all of the scyjava modules (like src() below) are imported prior to Fiji being initialized (i.e., in the /config/fiji.py script). At this time, stdout refers to the calling terminal, not the ScriptContextWriter. Because Python doesn't dynamically update imports, attempting to import the libraries again doesn't override _stdout.write to point to the script editor.

Image

A bad workaround is to append this to the beginning of the script:

#@ ImageJ ij
import importlib
import scyjava.inspect
from scyjava.inspect import methods, src
importlib.reload(scyjava.inspect)
src(ij)

Which then produces the ideal result: Image

However, I'm not sure what the best method to accomplish this is. Maybe it'd be to somehow edit the config script to specify which writer to use. Ideally there's something simpler.

ian-coccimiglio avatar May 10 '25 20:05 ian-coccimiglio