mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
pyscript.ffi - expose most essential utilities (#2005)
pyscript.ffi - expose most essential utilities
This commit is contained in:
committed by
GitHub
parent
eee2f64c1d
commit
910c666319
4
pyscript.core/package-lock.json
generated
4
pyscript.core/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pyscript/core",
|
"name": "@pyscript/core",
|
||||||
"version": "0.4.9",
|
"version": "0.4.10",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pyscript/core",
|
"name": "@pyscript/core",
|
||||||
"version": "0.4.9",
|
"version": "0.4.10",
|
||||||
"license": "APACHE-2.0",
|
"license": "APACHE-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ungap/with-resolvers": "^0.1.0",
|
"@ungap/with-resolvers": "^0.1.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pyscript/core",
|
"name": "@pyscript/core",
|
||||||
"version": "0.4.9",
|
"version": "0.4.10",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "PyScript",
|
"description": "PyScript",
|
||||||
"module": "./index.js",
|
"module": "./index.js",
|
||||||
|
|||||||
18
pyscript.core/src/stdlib/pyscript/ffi.py
Normal file
18
pyscript.core/src/stdlib/pyscript/ffi.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
try:
|
||||||
|
import js
|
||||||
|
from pyodide.ffi import create_proxy as _cp
|
||||||
|
from pyodide.ffi import to_js as _py_tjs
|
||||||
|
|
||||||
|
from_entries = js.Object.fromEntries
|
||||||
|
|
||||||
|
def _tjs(value, **kw):
|
||||||
|
if not hasattr(kw, "dict_converter"):
|
||||||
|
kw["dict_converter"] = from_entries
|
||||||
|
return _py_tjs(value, **kw)
|
||||||
|
|
||||||
|
except:
|
||||||
|
from jsffi import create_proxy as _cp
|
||||||
|
from jsffi import to_js as _tjs
|
||||||
|
|
||||||
|
create_proxy = _cp
|
||||||
|
to_js = _tjs
|
||||||
26
pyscript.core/test/ffi.html
Normal file
26
pyscript.core/test/ffi.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>PyScript FFI</title>
|
||||||
|
<link rel="stylesheet" href="../dist/core.css">
|
||||||
|
<script type="module" src="../dist/core.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="mpy">
|
||||||
|
from pyscript import document
|
||||||
|
from pyscript.ffi import to_js
|
||||||
|
document.documentElement.classList.add(
|
||||||
|
to_js({"ok": "mpy"}).ok
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
<script type="py">
|
||||||
|
from pyscript import document
|
||||||
|
from pyscript.ffi import to_js
|
||||||
|
document.documentElement.classList.add(
|
||||||
|
to_js({"ok": "py"}).ok
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -83,3 +83,8 @@ test('MicroPython + Pyodide fetch', async ({ page }) => {
|
|||||||
await page.goto('http://localhost:8080/test/fetch.html');
|
await page.goto('http://localhost:8080/test/fetch.html');
|
||||||
await page.waitForSelector('html.mpy.py');
|
await page.waitForSelector('html.mpy.py');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('MicroPython + Pyodide ffi', async ({ page }) => {
|
||||||
|
await page.goto('http://localhost:8080/test/ffi.html');
|
||||||
|
await page.waitForSelector('html.mpy.py');
|
||||||
|
});
|
||||||
|
|||||||
1
pyscript.core/types/stdlib/pyscript.d.ts
vendored
1
pyscript.core/types/stdlib/pyscript.d.ts
vendored
@@ -4,6 +4,7 @@ declare namespace _default {
|
|||||||
"display.py": string;
|
"display.py": string;
|
||||||
"event_handling.py": string;
|
"event_handling.py": string;
|
||||||
"fetch.py": string;
|
"fetch.py": string;
|
||||||
|
"ffi.py": string;
|
||||||
"magic_js.py": string;
|
"magic_js.py": string;
|
||||||
"util.py": string;
|
"util.py": string;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user