| 
     | 
    @@ -0,0 +1,66 @@ | 
  
    
     | 
     | 
  
    """ | 
    
     | 
     | 
  
    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 | 
    
     | 
     | 
  
    """ | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    UI = require('ui') | 
    
     | 
     | 
  
    ajax = require('ajax') | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    class Window(object): | 
    
     | 
     | 
  
        def __init__(self, properties): | 
    
     | 
     | 
  
            self._obj = __new__(UI.Window(properties)) | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
        def show(self): | 
    
     | 
     | 
  
            self._obj.show() | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
        def on(self, event, source, callback): | 
    
     | 
     | 
  
            self._obj.on(event, source, callback) | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    class Card(Window): | 
    
     | 
     | 
  
        def __init__(self, properties): | 
    
     | 
     | 
  
            self._obj = __new__(UI.Card(properties)) | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    def on_select_click(e): | 
    
     | 
     | 
  
        def callback(data): | 
    
     | 
     | 
  
            quote = data['contents']['quotes'][0]['quote'] | 
    
     | 
     | 
  
            author = data['contents']['quotes'][0]['author'] | 
    
     | 
     | 
  
            card = Card(dict(title='QOD', subtitle=author, body=quote)) | 
    
     | 
     | 
  
            card.show() | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
        ajax({'url': 'http://api.theysaidso.com/qod.json', | 
    
     | 
     | 
  
              'type': 'json'}, callback) | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    main = Card(dict(title='It Works!', | 
    
     | 
     | 
  
                     subtitle='Python on Pebble', | 
    
     | 
     | 
  
                     body='Press Select for Quote of The Day')) | 
    
     | 
     | 
  
    
  | 
    
     | 
     | 
  
    main.on('click', 'select', on_select_click) | 
    
     | 
     | 
  
    main.show() |