Event dispatcher — Kivy v1.0.1-dev documentation

# Event dispatcher

All objects that produce events in Kivy implement `EventDispatcher`, providing a consistent interface for registering and manipulating event handlers.

class `kivy.event.` `EventDispatcher`

  Bases: `object`

  Generic event dispatcher interface

  See the module docstring for usage.

  `bind`

    Bind an event type or a property to a callback

    Usage:

        # With properties
        def my_x_callback(obj, value):
            print 'on object', obj', 'x changed to', value
        def my_width_callback(obj, value):
            print 'on object', obj, 'width changed to', value
        self.bind(x=my_x_callback, width=my_width_callback)

        # With event
        self.bind(on_press=self.my_press_callback)

  `dispatch`

    Dispatch an event across all the handler added in bind(). As soon as a handler return True, the dispatching stop

  `register_event_type`

    Register an event type with the dispatcher.

    Registering event types allows the dispatcher to validate event handler names as they are attached, and to search attached objects for suitable handlers. Each event type declaration must :

    > 1. start with the prefix on_
    > 2. have a default handler in the class

    Example of creating custom event:

        class MyWidget(Widget):
            def __init__(self, **kwargs):
                super(MyWidget, self).__init__(**kwargs)
                self.register_event_type('on_swipe')

            def on_swipe(self):
                pass

        def on_swipe_callback(*largs):
            print 'my swipe is called', largs
        w = MyWidget()
        w.dispatch_event('on_swipe')

  `unbind`

    Unbind properties from callback functions.

    Same usage as bind().

  `unregister_event_types`

    Unregister an event type in the dispatcher