Skip to content

Instantly share code, notes, and snippets.

@BRuDesDev
Forked from hiway/pybble.py
Created June 29, 2023 23:46
Show Gist options
  • Save BRuDesDev/aabf2ec66c78bd299864a87ea08c56e6 to your computer and use it in GitHub Desktop.
Save BRuDesDev/aabf2ec66c78bd299864a87ea08c56e6 to your computer and use it in GitHub Desktop.

Revisions

  1. @hiway hiway revised this gist Aug 20, 2016. 1 changed file with 14 additions and 15 deletions.
    29 changes: 14 additions & 15 deletions pybble.py
    Original file line number Diff line number Diff line change
    @@ -27,40 +27,39 @@
    6. :-D
    """

    UI = require('ui')
    ajax = require('ajax')
    _UI = require('ui')

    __pragma__('kwargs')

    class Window(object):
    def __init__(self, properties):
    self._obj = __new__(UI.Window(properties))

    def show(self):
    self._obj.show()
    class UI(object):
    @classmethod
    def Window(**kwargs):
    return __new__(_UI.Window(kwargs))

    def on(self, event, source, callback):
    self._obj.on(event, source, callback)
    @classmethod
    def Card(**kwargs):
    return __new__(_UI.Card(kwargs))


    class Card(Window):
    def __init__(self, properties):
    self._obj = __new__(UI.Card(properties))
    __pragma__('nokwargs')


    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 = UI.Card(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 = 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()
  2. @hiway hiway created this gist Aug 20, 2016.
    66 changes: 66 additions & 0 deletions pybble.py
    Original file line number Diff line number Diff line change
    @@ -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()