I want to dispatch events from a LayoutDemoApp to a child widget. The goal is to have a websocket listener dispatch events, allowing any widget to listen to them (e.g. updating labels and so forth). I am probably misunderstanding how events works here and the Kivy examples. Is the register_event_type simply local to the LayoutDemoApp object, and this not possible?
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
class MyButton(Button):
def __init__(self, **kwargs):
super(MyButton, self).__init__(**kwargs)
self.bind(on_foo=self.on_foo)
def on_foo(self, *args, **kwargs):
print("MyButton.on_foo")
class LayoutDemoApp(App):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.register_event_type("on_foo")
def build(self):
root = BoxLayout(orientation='vertical')
r1 = BoxLayout()
button12 = MyButton(text='B1')
button12.bind(on_press=self.on_bar)
r1.add_widget(button12)
root.add_widget(r1)
return root
def on_bar(self, *args, **kwargs):
print("LayoutDemoApp.on_bar")
self.dispatch("on_foo")
def on_foo(self, *args, **kwargs):
pass
if __name__ == '__main__':
LayoutDemoApp().run()