'Create a CustomJS instance from a Python function. The
function is translated to JavaScript using PyScript.'

@classmethod
def from_py_func(cls, func):

    if (not isinstance(func, FunctionType)):
        raise ValueError('CustomJS.from_py_func    needs    function    object.')
    pyscript = import_required('flexx.pyscript', ('To    use    Python    functions    for    CustomJS,    you    need    Flexx    ' + '("conda    install    -c    bokeh    flexx"    or    "pip    install    flexx")'))
    default_values = func.__defaults__
    default_names = func.__code__.co_varnames[:len(default_values)]
    args = dict(zip(default_names, default_values))
    args.pop('window', None)
    code = (pyscript.py2js(func, 'cb') + ('cb(%s);\n' % ',    '.join(default_names)))
    return cls(code=code, args=args)
