What is the best way to test the pyxel supported (I believe v0.23) version out? #1367
Replies: 2 comments 1 reply
-
Pyodide 0.23.0 isn't officially supported in PyScript yet (there's an open PR by yours truly trying to get it supported). Once that's merged, the Pyxel integration will be available in unstable. That said, Pyodide 0.23.0 mostly works with the current 2023.03.1 release. If you just want to try out the Pyxel support, you can do so by pointing the Fair warning - as you've probably seen, support for this is still experimental on the Pyodide side. For instance, <!-- index.html -->
<head>
<script defer src="https://pyscript.net/releases/2023.03.1/pyscript.js"></script>
<link rel="stylesheet" href="https://pyscript.net/releases/2023.03.1/pyscript.css">
</head>
<body>
<py-config>
packages=['pyxel']
[[interpreters]]
src = "https://cdn.jsdelivr.net/pyodide/v0.23.0/full/pyodide.js"
name = "pyodide-0.23.0"
lang = "python"
</py-config>
<py-script src="pyxel_demo.py"></py-script>
<canvas id="canvas" tabindex="-1"></canvas>
</body> #pyxel_demo.py
import js
import pyodide
import pyodide_js
import pyxel
# Tell Pyodide/Emscripten where to draw the output
pyodide_js.canvas.setCanvas2D(js.document.getElementById("canvas"))
# Suppress a fatal error - running the Pyxel infinite loop leaves dead frames on the call stack;
# This supresses this warning for now. See https://github.com/pyodide/pyodide/pull/3508#issuecomment-1488837896
pyodide_js._api._skip_unwind_fatal_error = True
# Pyxel requires some additional setup for its onscreen gamepad before running
# Haven't personally figured out why it's necessary to set manually
pyodide.code.run_js(
"""_virtualGamepadStates = [
false, // Up
false, // Down
false, // Left
false, // Right
false, // A
false, // B
false, // X
false, // Y
];
"""
)
# Now you're set up to run your aplication code.
# A very simple Pyxel game. Press up and down to adjust the color of the text
class App():
def __init__(self):
self.color = 1
pyxel.init(256, 256)
pyxel.run(self.update, self.draw)
def draw(self):
pyxel.cls(0)
for y in range(0, 256, 16):
pyxel.text(0, y, "Hello world!", self.color)
def update(self):
if pyxel.btnp(pyxel.KEY_UP):
self.color = (self.color + 1) % 15 + 1
if pyxel.btnp(pyxel.KEY_DOWN):
self.color = (self.color + 13) % 15 + 1
App() |
Beta Was this translation helpful? Give feedback.
-
Thanks @JeffersGlass, much appreciated the work on these pieces! |
Beta Was this translation helpful? Give feedback.
-
Is there a build of this in unstable yet? Or should I wait until there is? Once it is there (or a branch) how is best to call it from pyscript.com or the like...
<script defer src="https://pyscript.net/unstable/pyscript.js"></script> or a direct branch call?
Love the work so far, really impressive.
Thanks a ton!
Beta Was this translation helpful? Give feedback.
All reactions