Posted by
Jan Eglinger on
Aug 22, 2013; 9:05am
URL: http://imagej.273.s1.nabble.com/another-python-scripting-question-tp5004517p5004529.html
Dear Aryeh,
On 21.08.2013 8:58 PM, Aryeh Weiss wrote:
> Thank you for your quick response. I sent this just before I left work,
> and when I got home, your response was already here.
:)
> On 8/21/13 7:00 PM, Jan Eglinger wrote:
>> from ij.gui import DialogListener, GenericDialog
>>
>> class MyListener (DialogListener):
>> def dialogItemChanged(self, gd, event):
>> IJ.log("Something was changed.")
>>
>> gd = GenericDialog("DialogListener example")
>> gd.addStringField("Type anything", "change this", 20)
>> gd.addDialogListener(MyListener())
>> gd.showDialog()
>>
> This is great -- works as advertised. I have couple of questions which I
> could not figure out.
>
> 1. I would really like for the action to occur only after I finish
> moving the slider. This is because I will be subtracting two images, and
> this takes some time. Is there an event (either dialog or mouse) that I
> can test for this?
Maybe you'd have to implement a mouse listener for that, reacting on
mouse button release. If you find out, let me know :)
>
> 2. Where can I find a complete list of dialog events? I searched around,
> but when I did not find it, I tried just printing the event argument, to
> see what events are being passed. I found:
> TEXT_VALUE_CHANGED when moved the sliders
> ITEM_STATE_CHANGED when I checked or unchecked a checkbox
I guess the possible events are all subclasses of java.awt.AWTEvent:
http://docs.oracle.com/javase/6/docs/api/index.html?java/awt/AWTEvent.html(and they're all in the java.awt.event package)
>
> I tried radio buttons (with the idea that I will push a button to run
> the calculation), but they did not produce any event and did not invoke
> the listener.
>
> I can use the checkbox to do what I want, but I assume there is a
> better way.
>
> (Maybe a mouse listener in the dialog window?)
Yes. I think this is the way to go, but don't know of any example
implementation.
>
>>>
>>> I want to set up a slider, where whenever I move the slider, something
>>> will change in an image (like preview).
>>
>> Starting with the above code, it should be possible to transform Wayne's
>> nice Java example in the following post into Python/Jython:
>>
>>
http://article.gmane.org/gmane.comp.java.imagej/28353>>
>>> This is documented in the addPreviewCheckbox method, so what I am asking
>>> is if this can also be done within python.
>>> Alternatively, is there a different way to do this?
>>>
>> You might also consider using the ExtendedPluginFilter interface, which
>> provides extended preview functionality.
>>
> Is there an example of this in python?
I don't know of any Python example, but there are plenty of Java
examples in the ImageJ source:
http://fiji.sc/git/?p=ImageJA.git&a=search&h=HEAD&st=grep&s=ExtendedPlugInFilterOh, while searching I found this nice python example:
http://fiji.sc/Find_Dimension_of_Raw_Image.pywhich at least also implements a listener.
If you finish developing your own python script implementing
ExtendedPlugInFilter, it would be great if you could add it to Fiji's
Jython scripting page as an example!
http://fiji.sc/Jython_ScriptingCheers,
Jan
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html