All objects that produce events in Kivy implement EventDispatcher, providing a consistent interface for registering and manipulating event handlers.
Bases: object
Generic event dispatcher interface
See the module docstring for usage.
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 an event across all the handler added in bind(). As soon as a handler return True, the dispatching stop
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 :
- start with the prefix on_
- 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 properties from callback functions.
Same usage as bind().
Unregister an event type in the dispatcher