Skip to content

support event handlers using pyodide #212

@simzer

Description

@simzer

Example:
This is the example of event usage in the tutorial

click_handler_method = "alert(JSON.stringify(event.data));"
click_handler = click_chart.on("click", click_handler_method)

Which will generate something like this in JS:

click_handler_method = event => { alert(JSON.stringify(event.data)); }
click_handler = chart.on("click", click_handler_method)

The same could be supported with Python syntax:

click_handler_method = "js.alert(json.dumps(event.data))"
click_handler = click_chart.on("click", click_handler_method)

Which would generate something like this in JS:

<script src="https://cdn.jsdelivr.net/pyodide/v0.22.1/full/pyodide.js"></script>
let pyodide = await loadPyodide();
let click_handler_method = (event) => { 
  let handler = pyodide.runPython(`
    def handler(x):
        js.alert(json.dumps(event.data))
    handler
  `);
  handler(event);
};
click_handler = click_chart.on("click", click_handler_method)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions