Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event in callbacks should be optional. #10

Open
tompreston opened this issue Aug 22, 2013 · 0 comments
Open

Event in callbacks should be optional. #10

tompreston opened this issue Aug 22, 2013 · 0 comments

Comments

@tompreston
Copy link
Member

The InputEventListener.register function should have a flag to optionally send events to callback functions.

import pifacedigitalio

def somefunction():
    """This function has no event argument."""
    pass

listener = pifacedigitalio.InputEventListener()
l.register(0, p.IODIR_DIR, somefunction, send_event=False)
l.activate()

somefunction is not passed an event object because send_event was set to False in the register function. send_event will default to True.

I'm not sure whether this should be implemented or not because it allows programmers to be inconsistent in callback definitions and you can just ignore the event anyway.

It is useful for directly calling existing library functions, that don't accept event objects. For example:

import robot

listener = pifacedigitalio.InputEventListener()
l.register(0, p.IODIR_DIR, robot.walk, send_event=False)
l.activate()

robot.walk() is not expecting any event objects so we do not send it any. Currently this can be wrapped up with:

import robot

def do_robot_walk(event):
    robot.walk()

listener = pifacedigitalio.InputEventListener()
l.register(0, p.IODIR_DIR, do_robot_walk)
l.activate()
@ghost ghost assigned tompreston Aug 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant