mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
64 lines
2.1 KiB
HTML
64 lines
2.1 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
|
<title>PyScript Next</title>
|
|
<script type="importmap">{ "imports": { "@pyscript/element": "../../pyscript.js" } }</script>
|
|
<script type="module">
|
|
// how would PyScript plugins add their own behavior?
|
|
import { hooks } from "@pyscript/element";
|
|
|
|
let counter = 0;
|
|
hooks.onBeforeRun.add((pyodide, { localName }) => {
|
|
// console.log(++counter, 'elements so far', localName, pyodide);
|
|
});
|
|
|
|
hooks.codeBeforeRunWorker.add('print("codeBeforeRunWorker")');
|
|
hooks.codeAfterRunWorker.add('print("codeAfterRunWorker")');
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<fieldset>
|
|
<legend id="dary"></legend>
|
|
Something something about something ...
|
|
</fieldset>
|
|
<py-config>
|
|
[[fetch]]
|
|
from = "../"
|
|
to_folder = "./"
|
|
files = ["a.py", "b.py"]
|
|
</py-config>
|
|
|
|
<!-- <py-script next> -->
|
|
<py-script>
|
|
import js
|
|
import a, b
|
|
print('Hello Console!')
|
|
js.console.log(a.x, b.x)
|
|
'Hello Web!'
|
|
</py-script>
|
|
<py-script>
|
|
# note the target is this element itself
|
|
display('second <py-script>')
|
|
</py-script>
|
|
<py-script>
|
|
from xworker import XWorker
|
|
# note this is late to the party simply because
|
|
# pyodide needs to be bootstrapped in the Worker too
|
|
XWorker('../a.py')
|
|
'OK'
|
|
</py-script>
|
|
|
|
<!-- <script type="py"> -->
|
|
<script type="py">
|
|
# not the target is inferred as companion element
|
|
display('first <script type="py">')
|
|
</script>
|
|
<script type="py">
|
|
# note the target here is different
|
|
display('second <script type="py">', target="dary")
|
|
</script>
|
|
</body>
|
|
</html>
|