Skip to content

Instantly share code, notes, and snippets.

@hiway
Last active June 29, 2023 23:46
Show Gist options
  • Save hiway/cd237eb1040c38e7ab5306a63575ded5 to your computer and use it in GitHub Desktop.
Save hiway/cd237eb1040c38e7ab5306a63575ded5 to your computer and use it in GitHub Desktop.
Python on Pebble. Yes. It works, with a bit of space to write a decent app and some heap memory to spare. AJAX works, as shown in code.
"""
pybble.py
Yup, you can run Python on your Pebble too! Go thank the good folks who
made Transcrypt, a dead-simple way to take your Python code and translate
it to *very* lean Javascript. In our case, instead of browser, we run it
on Pebble using their equally dead-simple Online IDE and Pebble.js library.
Here's a working example, it runs on a real Pebble Classic.
Usage:
1. Install transcrypt (You should use a Python virtual environment)
pip install transcrypt
2. Python becomes Javascript
transcrypt pybble.py
3. Get the (minified) source code
- on MacOS
cat __javascript__/pybble.min.js | pbcopy
OR
open __javascript__/pybble.min.js
- On other OSes, copy the content, or optn the file in an editor and do so
cat __javascript__/pybble.min.js
4. Create a new project on https://cloudpebble.net
- Select Pebble.js as the project type
- Open `app.js` and replace the example code with the code you copied.
5. Click the Run button
6. :-D
"""
ajax = require('ajax')
_UI = require('ui')
__pragma__('kwargs')
class UI(object):
@classmethod
def Window(**kwargs):
return __new__(_UI.Window(kwargs))
@classmethod
def Card(**kwargs):
return __new__(_UI.Card(kwargs))
__pragma__('nokwargs')
def on_select_click(e):
def callback(data):
quote = data['contents']['quotes'][0]['quote']
author = data['contents']['quotes'][0]['author']
card = UI.Card(title='QOD', subtitle=author, body=quote)
card.show()
ajax({'url': 'http://api.theysaidso.com/qod.json',
'type': 'json'}, callback)
main = UI.Card(title='It Works!',
subtitle='Python on Pebble',
body='Press Select for Quote of The Day')
main.on('click', 'select', on_select_click)
main.show()
@matiasinsaurralde
Copy link

Very cool

@pjockey
Copy link

pjockey commented Apr 28, 2020

Has this project had any further development?

@hiway
Copy link
Author

hiway commented May 7, 2020

@pjockey soon after creating the project, Pebble company was shut down. I haven't continued work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment