Files
pyscript/pyscript.core/test/plugins/index.html
2023-06-16 15:34:05 +02:00

47 lines
1.6 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Plugins</title>
<style>
mpy-script {
display: none;
}
</style>
<script type="importmap">
{ "imports": { "@pyscript/core": "../../min.js" } }
</script>
<script type="module">
import { define, whenDefined } from "@pyscript/core";
whenDefined("mpy").then(console.log);
define("mpy", {
interpreter: "micropython",
async onRuntimeReady(micropython, element) {
console.log(micropython);
// Somehow this doesn't work in MicroPython
micropython.io.stdout = (message) => {
console.log("🐍", micropython.type, message);
};
micropython.run(element.textContent);
element.replaceChildren("See console ->");
element.style.display = "block";
const button = document.createElement("button");
button.textContent = "click";
button.setAttribute("mpy-click", "test_click(event)");
document.body.append(button);
},
});
</script>
</head>
<body>
<mpy-script mpy-click="test_click(event)">
def test_click(event):
print(event.type)
print('Hello Console!')
</mpy-script>
</body>
</html>