PageRenderTime 62ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 18ms app.codeStats 1ms

/addons/EventDelegate.py

http://pyjamas.googlecode.com/
Python | 23 lines | 19 code | 2 blank | 2 comment | 0 complexity | 7629746937e55cc21deb931e96c4a400 MD5 | raw file
 1from __pyjamas__ import JS
 2
 3class EventDelegate:
 4   """

 5      Create the equivalent of a bound method.  This also prepends extra 

 6      args, if any, to the called method's argument list when it calls it.

 7      

 8      Pass the method name you want to implement (javascript doesn't

 9      support callables).

10      

11      @type args: list

12      @param args: If given, the arguments will be prepended to the 

13                   arguments passed to the event callback

14   """
15   def __init__(self, eventMethodName, obj, method, *args):      
16      self.obj = obj
17      self.method = method
18      self.args = args
19      JS("this[eventMethodName] = this.onEvent;")
20
21   def onEvent(self, *args):
22      self.method.apply(self.obj, self.args.l.concat(args.l))
23