-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pyxel_fetch.html
37 lines (34 loc) · 1.25 KB
/
test_pyxel_fetch.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!-- Bootstrap HTML for running the unit tests. -->
<!DOCTYPE html>
<html>
<head>
<title>pyodide</title>
<script src="./pyodide.js"></script>
</head>
<body>
<button id="start" type="button" disabled>Loading</button> <br>
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<script type="text/javascript">
async function main() {
const filename = (new URLSearchParams(location.search)).get("py") || "08_triangle_api"
const pyodide = await loadPyodide();
await pyodide.loadPackage("micropip")
const micropip = pyodide.pyimport("micropip")
await micropip.install("pyxel-1.8.0-cp37-abi3-emscripten_3_1_14_wasm32.whl")
const response = await fetch(`python/${filename}.py`)
const startButton = document.getElementById("start")
if (response.status != 200) {
const defaultScript = await (await fetch("python/00_moving_square.py")).text()
startButton.addEventListener("click", () => pyodide.runPython(defaultScript))
}
else {
const script = await response.text()
startButton.addEventListener("click", () => pyodide.runPython(script))
}
startButton.disabled = false
startButton.innerText = "Start"
}
main()
</script>
</body>
</html>