You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: show matplotlib/Pillow images and add experimental SDL support
- Move Pyodide setup into src/runtime.js, shared by the worker and the
new SDL runtime; Python helpers live in src/python and are installed
into site-packages
- matplotlib: custom Agg backend (MPLBACKEND) posts figures as PNG to
the console on plt.show(); unshown figures are shown when a run ends
- Pillow: Image.show() displays in the console
- Experimental SDL (pygame): programs with an async game loop run in a
main-thread Pyodide drawing to a <canvas id="canvas"> in the console.
SDL setup is checked with pygame.display.init() and any failure falls
back to the worker. Keyboard input is limited to the canvas, Acode's
document title is restored, and re-running or closing the console
cancels the game
- Worker runs pygame headless (SDL_VIDEODRIVER=dummy): without a canvas
Emscripten's SDL video crashed Pyodide fatally
- Handle Pyodide fatal errors: report them and restart Python on the
next run instead of leaving the console stuck
- Hide "already loaded" package messages on every run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,32 @@ import micropip
27
27
await micropip.install("snowballstemmer")
28
28
```
29
29
30
+
### Plots and images
31
+
32
+
`matplotlib` figures are shown in the console when you call `plt.show()`, and any figures left open are shown when the program ends. Pillow's `Image.show()` works too.
33
+
34
+
### pygame (experimental)
35
+
36
+
pygame programs can draw to a canvas in the console using Pyodide's [SDL support](https://pyodide.org/en/stable/usage/sdl.html). The game loop must be async so the app stays responsive:
37
+
38
+
```python
39
+
import asyncio
40
+
import pygame
41
+
42
+
pygame.init()
43
+
screen = pygame.display.set_mode((320, 240))
44
+
45
+
asyncdefmain():
46
+
whileTrue:
47
+
screen.fill((30, 30, 60))
48
+
pygame.display.flip()
49
+
await asyncio.sleep(1/60)
50
+
51
+
await main()
52
+
```
53
+
54
+
If SDL cannot start, the program runs without a display. Running again or closing the console stops the game.
Copy file name to clipboardExpand all lines: changelog.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,9 @@
8
8
- Console output can now be selected and copied
9
9
- Header button to toggle line wrap in the console (remembered between sessions)
10
10
- Thin progress line under the console header while Python loads or code is running
11
+
- matplotlib plots are shown in the console (`plt.show()`, or automatically at the end of a run), as are Pillow `Image.show()` images
12
+
- Experimental SDL support: pygame programs with an async game loop draw to a canvas in the console, falling back to running without a display if SDL cannot start
13
+
- Python crashes no longer leave the console stuck; Python restarts on the next run
11
14
- Fixed Python failing to load (or staying on "loading...") on some devices
12
15
- Clear error message when Python fails to load, with automatic retry on the next run
13
16
- Smaller plugin size (removed stale Pyodide files)
0 commit comments