Here are the source links from my original answer:
: Python - Java?
: Python ?
, : Python?
[ ]
Jython , . , :
def _(self, event):
print 'Cancel button was clicked!'
if self.task is not None:
self.task.cancel()
cancelButton.setOnAction(lambda event: _(self, event))
.
(1) . , .
(2) self aware, , self .
(3) () . Python , . , , _, . ( .) ad-infinitum.
, , , :
@LocalEventHandler(self, cancelButton.setOnAction)
def _(self, event):
print 'Cancel button was clicked!'
if self.task is not None:
self.task.cancel()
:
class LocalEventHandler(object):
'''This decorator turns a local function into a *self aware* event handler.'''
def __init__(self, context, assignHandlerFunc):
self.context = context
self.assignHandlerFunc = assignHandlerFunc
def __call__(self, handler):
self.assignHandlerFunc(lambda event: handler(self.context, event))
return handler