mirror of
https://github.com/pyscript/pyscript.git
synced 2026-03-25 23:00:02 -04:00
Use registerJSModule when available (#1573)
This commit is contained in:
committed by
GitHub
parent
7813c3f03f
commit
a14e701be4
@@ -15,7 +15,7 @@
|
||||
print(document.currentScript.id == my_target.id)
|
||||
</script>
|
||||
<script type="micropython">
|
||||
# XWorker is globally defined
|
||||
from xworker import XWorker
|
||||
print(XWorker != None)
|
||||
</script>
|
||||
<script type="micropython">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import js
|
||||
import matplotlib
|
||||
from xworker import xworker
|
||||
|
||||
try:
|
||||
js.document
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<script type="micropython">
|
||||
from xworker import XWorker
|
||||
w = XWorker('./matplot.py', **{'type': 'pyodide', 'config': './config.toml'})
|
||||
|
||||
# xworker.window made the following completely unnecessary
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
export const python = { content: "", target: null };
|
||||
export const loadMicroPython = () => ({
|
||||
registerJsModule() {
|
||||
|
||||
},
|
||||
runPython(content) {
|
||||
if (document.currentScript?.target) {
|
||||
python.content = content;
|
||||
|
||||
@@ -7,6 +7,9 @@ export const setTarget = (value) => {
|
||||
export const python = { content: "", target: null, packages: null };
|
||||
export const loadPyodide = () => ({
|
||||
loadPackage() {},
|
||||
registerJsModule() {
|
||||
|
||||
},
|
||||
pyimport() {
|
||||
return {
|
||||
install(packages) {
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
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')
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<script type="module">
|
||||
import { XWorker } from "@pyscript/core";
|
||||
|
||||
const w = new XWorker("./worker.py", { type: "micropython" });
|
||||
const w = new XWorker("./worker.py", { type: "micropython", config: "../fetch.toml" });
|
||||
w.postMessage("JavaScript: Hello MicroPython 👋");
|
||||
w.onmessage = (event) => {
|
||||
console.log(event.data);
|
||||
@@ -31,26 +31,32 @@
|
||||
|
||||
<!-- XWorker - MicroPython to MicroPython -->
|
||||
<script type="micropython">
|
||||
from xworker import XWorker
|
||||
|
||||
def handle_message(event):
|
||||
print(event.data)
|
||||
|
||||
w = XWorker('./worker.py')
|
||||
w = XWorker('./worker.py', **{'config': '../fetch.toml'})
|
||||
w.postMessage('MicroPython: Hello MicroPython 👋')
|
||||
w.onmessage = handle_message
|
||||
</script>
|
||||
|
||||
<!-- XWorker - MicroPython to Pyodide -->
|
||||
<script type="micropython">
|
||||
<script type="pyodide">
|
||||
from xworker import XWorker
|
||||
|
||||
def handle_message(event):
|
||||
print(event.data)
|
||||
|
||||
w = XWorker('./worker.py', **{'type': 'pyodide', 'async': True, 'config': '../fetch.toml'})
|
||||
w = XWorker('./worker.py', **{'type': 'pyodide', 'async_': True, 'config': '../fetch.toml'})
|
||||
w.postMessage('MicroPython: Hello Pyodide 👋')
|
||||
w.onmessage = handle_message
|
||||
</script>
|
||||
|
||||
<!-- XWorker - MicroPython to Lua -->
|
||||
<script type="micropython">
|
||||
from xworker import XWorker
|
||||
|
||||
def handle_message(event):
|
||||
print(event.data)
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<body>
|
||||
<script type="micropython">
|
||||
from js import Promise, document
|
||||
from xworker import XWorker
|
||||
|
||||
deferred = Promise.withResolvers()
|
||||
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
from xworker import xworker
|
||||
|
||||
print("What is 2 + 3?")
|
||||
print("Answer: " + xworker.sync.input("What is 2 + 3?"))
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import re
|
||||
import a, b
|
||||
from xworker import xworker
|
||||
|
||||
|
||||
def on_message(event):
|
||||
|
||||
Reference in New Issue
Block a user