Mopad: Gamepad support for Python is finally here!
Posted by cantdutchthis@reddit | Python | View on Reddit | 13 comments
What my project does:
Browsers have a gamepad API these days, but these weren't exposed to Python notebooks yet. Thanks to mopad, you can now use a widget (made with anywidget!) to control Python with a game controller. It's more useful that you might initially think because this also means that you can build labelling interfaces in your notebook and add labels to data with a device that makes everything feel like a fun video game.
Target audience:
It's mainly meant for ML/AI people that like to work with Python notebooks. The main target for the widget is marimo but because it's made with anywidget it should also work in Jupyter/VSCode/colab.
Comparison:
I'm not aware of other projects that add gamepad support, but one downside that's fair to mention is that this approach only works in browser based notebook because we need the web API. Not all gamepads are supported by all vendors (MacOS only allows for bluetooth gamepads AFAIK), but I've tried a bunch of pads and they all work great!
If you're keen to see a demo, check the YT video here: https://www.youtube.com/watch?v=4fXLB5_F2rg&ab_channel=marimo
If you have a gamepad in your hand, you can also try it out on Github Pages on the project repository here: https://github.com/koaning/mopad
unalivepool@reddit
u/cantdutchthis is there a way I can use this in jupyter-notebook or other notebook interface, pretty please??
unalivepool@reddit
holyshit!! I tried this with databricks and it works out of the box!! whoa!!
cantdutchthis@reddit (OP)
Yeah it should work pretty much anywhere since we use anywidget under the hood.
unalivepool@reddit
Yeah. The widget renders, and the live display of the widget gives real time values.
I tried noting real time values in databricks.. But it only notes the initial state and does not reflect subsequent press of buttons.
```python
My findings are
- mopad widget visually updates axes in the browser (JS)
- widget.get_state("axes") will update return value if I run the function in a single cell while pressing the stick, but does not change behaviour if I run a loop on widget.get_state("axes")
- No change is observed in Python even if the sticks are visibly moving
Gif
unalivepool@reddit
please ignore, discovered `molabel` /\ . thank you
unalivepool@reddit
Yeah. The widget renders, and the live display of the widget gives real time values.
I tried noting real time values in databricks.. But it only notes the initial state and does not reflect subsequent press of buttons.
)
My findings are
mopad
widget visually updates axes in the browser (JS)widget.get_state("axes")
always returns[0.0, 0.0, 0.0, -1.0]
or staticwidget.get_state("axes")
will update return value if I run the function in a single cell while pressing the stick, but does not change behaviour if I run a loop onwidget.get_state("axes")
GatorForgen@reddit
Any support for unlimited number of axes? axes list[float] only shows two x y pairs in the Readme.
cantdutchthis@reddit (OP)
I would certainly be open to that but I don't have a gamepad with more than two axes. Do you have an example?
n1k0h1k0@reddit
Super cool to see more Python support for games
cantdutchthis@reddit (OP)
It's not meant for games though! It's meant to capture events that can in turn trigger Python functions.
GambAntonio@reddit
seems easier than https://pypi.org/project/vgamepad/ ?????
cantdutchthis@reddit (OP)
It is I think! But that's mainly because all of the heavy lifting is done by the browser. That also means that you're limited by what the browser can handle but for notebook users this should be plenty.
AalbatrossGuy@reddit
A really cool project!