Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support event handlers using pyodide #212

Open
simzer opened this issue Feb 24, 2023 · 1 comment
Open

support event handlers using pyodide #212

simzer opened this issue Feb 24, 2023 · 1 comment

Comments

@simzer
Copy link
Member

simzer commented Feb 24, 2023

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)
@simzer
Copy link
Member Author

simzer commented Mar 2, 2023

or micropython
https://micropython.org/

@veghdev veghdev changed the title Support Python event handlers using pyodide python development: support event handlers using pyodide Mar 16, 2023
@veghdev veghdev added the enhancement New feature or request label Mar 16, 2023
@schaumb schaumb removed the enhancement New feature or request label Jul 3, 2023
@veghdev veghdev changed the title python development: support event handlers using pyodide support event handlers using pyodide Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants