Closed JochenGehrig closed 9 months ago
Any chance to have a key board short cut to continue (space bar for instance)?
Actually tricky, the tool is written in the macro language and uses the built-in waitForDialog
that does note handle key press by default. It would mean rewritting in another language.
And even if rewritten, the keyboard press would have to be catched from the active image window not from the waitForDialog window, so not that simple neither.
So I would not put effort into that for the moment if I were you @sankeert1999 😋
ah well I was not looking at the right script, I looked into the User annotation directory at the root of the repo. Which tool are we talking about then ? I dont see one on GitHub that seems to loop over files
VO_(userannotation)(Batch).py
This what you can make out of \Plastic_plate_3_4dpf_PTU_zebrafish with this tool, after removing a few dodgy embryos. To repeat myself: That should be a main message of the paper imho :-)
Before:
After:
Here is a solution, it's not so intuitive but I think you can manage from there, just take the time to understand the code.
The trick is to subscribe to key events happening on the currently annotated image (in your case the mask), using a function called addKeyListener
. This function is not available directly in the ImagePlus, but on the ImageCanvas it contains yes.
The addKeyListener accept a KeyListener as argument, which can be actually any object implementing that interface (think of it as a mother class) by implements the 3 functions listed on that page.
I put below 2 example of KeyListeners, a generic one that extends the KeyAdapter
class (as indicated in the doc, so I dont need to implement all functions of KeyListener),
The second KeyListener is an object derived from the WaitForUserDialog, and that's the magic, the WaitForUserDialog is already extending the KeyListener
, so you can out of the box have your dialog listening to the key press on the image 😊
You can put the code for the CustomWaitDialog
into your Utils file.
Now you just have to test what key is pressed in the keyPressed event, using e
which is a key event with multiple functions to get the pressed key see https://docs.oracle.com/javase/8/docs/api/java/awt/event/KeyEvent.html
"""
This will create a custom WaitForUser dialog, and add it as a listener on the current image.
Any key press on the image will call the keyPressed function of the dialog.
"""
#@ ImagePlus imp
from java.awt.event import KeyAdapter
from ij import IJ
from ij.gui import WaitForUserDialog
class MyKeyListener(KeyAdapter):
"""A generic key listener, just for the sake of the example"""
def __init__(self):
super(MyKeyListener, self).__init__()
def keyPressed(self, e):
IJ.log("Test")
print("Key pressed")
class CustomWaitDialog(WaitForUserDialog):
"""
Extends the WaitForUserDialog, b giving the possiblity to respond to keyboard input
The ok label is also replaced with "Continue"
"""
def __init__(self, title, message=""):
super(CustomWaitDialog, self).__init__(title, message)
okButton = self.getButton()
okButton.label = "Continue"
def keyPressed(self, e):
super(CustomWaitDialog, self).keyPressed(e) # call the mother class event handling, usually good practice
print("Pressed")
# Use e to know what key was pressed
self.close() # in your case you want to close the dialog I think, that's what you currently do with the classic WaitForUserDialog
dg = CustomWaitDialog("MyDialog") # the constructor also accept a message, just omitted here
imp.getCanvas().addKeyListener(dg) # add the dialog as a listener to key events on the image, this way any key event will call keyPressed(self, e) of the dialog
dg.show()
# Anything below here only executed once the dialog is closed
print ("done")
EDIT : Just make sure in the message of the dialog, to mention that people can use the shortcut key instead of clicking, otherwise no one will notice 😁
Added shortcuts for annoataion now the users can use either enter or spacebar instead of clicking ok.
The batch user annotation is nice. What is a bit annoying is that you have to click 96 times on the continue button. Any chance to have a key board short cut to continue (space bar for instance)?
In any case took me just about 5 mins to produce something like the image below. This is what we need to show in the paper, in my opinion and what, at least for me, was the main motivation behind developing it. but with a nice dataset, not this one! ;-)