File: EventDelegate.py

package info (click to toggle)
pyjamas 0.7~%2Bpre2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,656 kB
  • ctags: 12,331
  • sloc: python: 74,493; php: 805; sh: 291; makefile: 59; xml: 9
file content (24 lines) | stat: -rw-r--r-- 732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from __pyjamas__ import JS


class EventDelegate:
    """
    Create the equivalent of a bound method.  This also prepends extra
    args, if any, to the called method's argument list when it calls it.

    Pass the method name you want to implement (javascript doesn't
    support callables).

    @type args: list
    @param args: If given, the arguments will be prepended to the
                 arguments passed to the event callback
    """
    def __init__(self, eventMethodName, obj, method, *args):
        self.obj = obj
        self.method = method
        self.args = args
        JS("this[eventMethodName] = this.onEvent;")

    def onEvent(self, *args):
        self.method.apply(self.obj, self.args.l.concat(args.l))