Skip to content, Skip to search

Changes

Jython Scripting

23 bytes added, 12:24, 19 October 2011
Add a key listener to the canvas of every open image
<source lang="python">
from java.awt.event import KeyEvent, KeyAdapter
def doSomething(imp, keyEvent):
""" A function to react to key being pressed on an image canvas. """
IJ.log("clicked keyCode " + str(keyEvent.getKeyCode() ) + " on image " + str(imp))
# Prevent further propagation of the key event:
keyEvent.consume()
class ListenToKey(KeyAdapter):
def keyPressed(this, event):
IJ.log("G was pressed!")
event.consume() # AVOID propagation to other key listeners
listener = ListenToKey()
for imp in map(WindowManager.getImage, WindowManager.getIDList()):
win = imp.getWindow()
map(canvas.removeKeyListener, kls)
# Add our key listener
canvas.addaddKeyListener(listener)
# Re-add existing key listeners
map(canvas.addKeyListener, kls)
Emailconfirmed, uploaders
653
edits