mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 18:55:29 -05:00
53 lines
1.8 KiB
HTML
53 lines
1.8 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
|
<title>python workers</title>
|
|
<script type="importmap">
|
|
{
|
|
"imports": {
|
|
"basic-devtools": "../../node_modules/basic-devtools/esm/index.js",
|
|
"coincident/window": "../../node_modules/coincident/esm/window.js",
|
|
"@ungap/with-resolvers": "../../node_modules/@ungap/with-resolvers/index.js",
|
|
"@ungap/structured-clone/json": "../../node_modules/@ungap/structured-clone/esm/json.js",
|
|
"@pyscript/core": "../../esm/index.js"
|
|
}
|
|
}
|
|
</script>
|
|
<script type="module">
|
|
import "@pyscript/core";
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<script type="micropython">
|
|
from js import Promise, document
|
|
from xworker import XWorker
|
|
|
|
deferred = Promise.withResolvers()
|
|
|
|
def handle_result(event):
|
|
inputs = document.querySelectorAll('input')
|
|
inputs[0].disabled = True
|
|
inputs[1].disabled = True
|
|
deferred.resolve(inputs[0].value)
|
|
|
|
def handle_input(data):
|
|
inputs = document.querySelectorAll('input')
|
|
inputs[0].placeholder = data
|
|
inputs[0].disabled = False
|
|
inputs[1].disabled = False
|
|
return deferred.promise
|
|
|
|
w = XWorker('./input.py', type='micropython')
|
|
w.sync.input = handle_input
|
|
</script>
|
|
<input type="text" placeholder="loading ..." required disabled />
|
|
<input
|
|
type="submit"
|
|
micropython-click="handle_result"
|
|
disabled
|
|
/>
|
|
</body>
|
|
</html>
|