How to use the ipycanvas.animation.Py2JSVisitor function in ipycanvas

To help you get started, we’ve selected a few ipycanvas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github martinRenou / ipycanvas / ipycanvas / animation.py View on Github external
if isinstance(value, str):
        parsed = ast.parse(value, '', 'exec')

        return ';\n'.join([Py2JSVisitor().visit(node) for node in parsed.body])

    if isinstance(value, (types.FunctionType, types.MethodType)):
        if getattr(value, '__name__', '') in ('', ''):
            raise RuntimeError('Anonymous functions not supported')

        value = inspect.getsource(value)

        module = ast.parse(value, '', 'exec')

        func = module.body[0]

        return ';\n'.join([Py2JSVisitor().visit(node) for node in func.body])

    raise RuntimeError('py2js only supports a code string or function as input')