Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/PyodideWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ const PyodideWorker = () => {
case "writeFile":
pyodide.FS.writeFile(data.filename, encoder.encode(data.content));
break;
case "setCanvas":
if (data.canvas) {
pyodide._api._skip_unwind_fatal_error = true;
// telll pyodide that this is the canvas to use for SDL2
// globalThis.canvas = data.canvas; // Store the OffscreenCanvas globally in the worker
// Now, register it with Pyodide
// pyodide.globals.set("js_canvas", data.canvas);
// console.log(data.canvas);
// globalThis.screen = { width: 100, height: 100 };
pyodide.runPython(`
#import js
#import sdl2.ext
#sdl2.ext.init()
#sdl2.ext.window = js.js_canvas
globals()['screen'] = {'width': 100, 'height': 100}
`);
pyodide.canvas.setCanvas2D(data.canvas);
}
break;

case "runPython":
runPython(data.python);
break;
Expand Down Expand Up @@ -367,6 +387,22 @@ const PyodideWorker = () => {
`);
},
},
pygame: {
before: async () => {
await pyodide.loadPackage("pygame-ce");
pyodide.runPython(`
from pygame import display
print("pygame is running!")

def _custom_flip():
print("pygame.flip() called")

display.flip = _custom_flip
display.update = _custom_flip
`);
},
after: () => {},
},
};

const fakeBasthonPackage = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@
setVisuals([]);
stdinClosed.current = false;

const canvas = document
.querySelector("editor-wc")

Check failure on line 263 in src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx

View workflow job for this annotation

GitHub Actions / test

TypeError: Cannot read properties of null (reading 'shadowRoot') at handleRun (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx:263:34) at handleRun (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx:131:7) at create (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:23189:26) at commitHookEffectListMount (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24970:11) at commitPassiveMountOnFiber (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24930:9) at commitPassiveMountEffects_complete (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24917:7) at commitPassiveMountEffects_begin (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24905:3) at commitPassiveMountEffects (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:27078:3) at flushPassiveEffectsImpl (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:27023:14) at flushPassiveEffects (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:26808:9) at callback (/home/runner/work/editor-ui/editor-ui/node_modules/react/cjs/react.development.js:2667:24) at flushActQueue (/home/runner/work/editor-ui/editor-ui/node_modules/react/cjs/react.development.js:2582:11) at actImplementation (/home/runner/work/editor-ui/editor-ui/node_modules/@testing-library/react/dist/act-compat.js:47:25) at updateRunner (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js:44:6) at Object.updateRunner (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js:98:5) at Promise.then.completed (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/utils.js:231:10) at _callCircusHook (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:281:40) at _runTest (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:246:5) at _runTestsForDescribeBlock (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:74:19) at runTestInternal (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 263 in src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx

View workflow job for this annotation

GitHub Actions / test

TypeError: Cannot read properties of null (reading 'shadowRoot') at handleRun (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx:263:34) at handleRun (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx:131:7) at create (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:23189:26) at commitHookEffectListMount (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24970:11) at commitPassiveMountOnFiber (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24930:9) at commitPassiveMountEffects_complete (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24917:7) at commitPassiveMountEffects_begin (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24905:3) at commitPassiveMountEffects (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:27078:3) at flushPassiveEffectsImpl (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:27023:14) at flushPassiveEffects (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:26808:9) at callback (/home/runner/work/editor-ui/editor-ui/node_modules/react/cjs/react.development.js:2667:24) at flushActQueue (/home/runner/work/editor-ui/editor-ui/node_modules/react/cjs/react.development.js:2582:11) at actImplementation (/home/runner/work/editor-ui/editor-ui/node_modules/@testing-library/react/dist/act-compat.js:47:25) at updateRunner (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js:44:6) at Object.updateRunner (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js:98:5) at Promise.then.completed (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/utils.js:231:10) at _callCircusHook (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:281:40) at _runTest (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:246:5) at _runTestsForDescribeBlock (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:74:19) at runTestInternal (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 263 in src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx

View workflow job for this annotation

GitHub Actions / test

TypeError: Cannot read properties of null (reading 'shadowRoot') at handleRun (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx:263:34) at handleRun (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx:131:7) at create (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:23189:26) at commitHookEffectListMount (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24970:11) at commitPassiveMountOnFiber (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24930:9) at commitPassiveMountEffects_complete (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24917:7) at commitPassiveMountEffects_begin (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:24905:3) at commitPassiveMountEffects (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:27078:3) at flushPassiveEffectsImpl (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:27023:14) at flushPassiveEffects (/home/runner/work/editor-ui/editor-ui/node_modules/react-dom/cjs/react-dom.development.js:26808:9) at callback (/home/runner/work/editor-ui/editor-ui/node_modules/react/cjs/react.development.js:2667:24) at flushActQueue (/home/runner/work/editor-ui/editor-ui/node_modules/react/cjs/react.development.js:2582:11) at actImplementation (/home/runner/work/editor-ui/editor-ui/node_modules/@testing-library/react/dist/act-compat.js:47:25) at updateRunner (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js:44:6) at Object.updateRunner (/home/runner/work/editor-ui/editor-ui/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js:98:5) at Promise.then.completed (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/utils.js:231:10) at _callCircusHook (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:281:40) at _runTest (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:246:5) at _runTestsForDescribeBlock (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/editor-ui/editor-ui/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:74:19) at runTestInternal (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/editor-ui/editor-ui/node_modules/jest-runner/build/testWorker.js:106:12)
.shadowRoot.getElementById("sdl2Canvas");
if (canvas) {
console.log("Setting up canvas for Pyodide");
let offScreenCanvas = canvas;
if (
canvas.transferControlToOffscreen &&
!(canvas instanceof OffscreenCanvas)
) {
offScreenCanvas = canvas.transferControlToOffscreen();
}
pyodideWorker.postMessage(
{ method: "setCanvas", canvas: offScreenCanvas },
[offScreenCanvas],
);
}

await Promise.allSettled(
projectImages.map(({ filename, url }) =>
fetch(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const VisualOutputPane = ({ visuals, setVisuals }) => {
return (
<div className="visual-output">
<div ref={output} className="pythonrunner-graphic" />
<canvas id="sdl2Canvas"></canvas>
{senseHatEnabled || senseHatAlways ? <AstroPiModel /> : null}
</div>
);
Expand Down
Loading