PageRenderTime 394ms CodeModel.GetById 378ms RepoModel.GetById 1ms app.codeStats 0ms

/addons/EventDelegate.py

http://pyjamas.googlecode.com/
Python | 23 lines | 19 code | 2 blank | 2 comment | 0 complexity | 7629746937e55cc21deb931e96c4a400 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. from __pyjamas__ import JS
  2. class EventDelegate:
  3. """
  4. Create the equivalent of a bound method. This also prepends extra
  5. args, if any, to the called method's argument list when it calls it.
  6. Pass the method name you want to implement (javascript doesn't
  7. support callables).
  8. @type args: list
  9. @param args: If given, the arguments will be prepended to the
  10. arguments passed to the event callback
  11. """
  12. def __init__(self, eventMethodName, obj, method, *args):
  13. self.obj = obj
  14. self.method = method
  15. self.args = args
  16. JS("this[eventMethodName] = this.onEvent;")
  17. def onEvent(self, *args):
  18. self.method.apply(self.obj, self.args.l.concat(args.l))