tingbot / tingbot-python

🔩 Python APIs to write apps for Tingbot
Other
18 stars 9 forks source link

Buttons! #27

Closed furbrain closed 8 years ago

furbrain commented 8 years ago

This pull request address issue #23. It provides for responding to button presses by extending the decorator syntax, allowing the user to specify what kind of event should be responded to - down, up, (short) press and long presses. The default is "down" which maintains compatibility with existing code

joerick commented 8 years ago

Hi furbrain, thanks for this! Taking a look now...

joerick commented 8 years ago

Tests look great

joerick commented 8 years ago

It might be time to reconsider the button API - the way it is in this PR we've got button.press('left', event_type='up'), button.press('left', event_type='long_press') etc... seems confusing to me.

Thinking through some options... this is what I'm thinking for a new API:

import tingbot
from tingbot import *

@left_button.press
def prev():
    state['page'] -= 1

@right_button.press
def next():
    state['page'] += 1

@midright_button.hold
def home():
    state['page'] = 0

Those buttons could be individual instances of the Button class. I think this makes more sense conceptually - we're registering handlers with the button objects directly. Also allows access to the button with a stateful API e.g. if left_button.state == 'down':.

Sorry to spring this on you! We can add in a shim press function with a deprecation warning so existing apps on the old API will still work.