Proposal to Use `__events__` instead of `register_event_type`
kengoon opened this issue · 1 comments
kengoon commented
Description of the Feature
So kivy has two ways for registering an event, one way is to use register_event_type
method, which involves calling this method at the __init__
level. But there's a drawback on this approach; this does not allow binding an event during when an object is created. Example code of binding an event object during object creation, assuming on_fire
to be the event:
Object(height=2, on_fire=self.fire)
But with the current implementation of event registering in kivymd, you get to write two lines of code
obj = Object(height=2)
obj.bind(on_fire=self.fire)
A quick fix for this while using register_event_type
would be to call register_event_type
before super
Example code:
class Object(Widget):
def __init__(self, **kwargs):
self.register_event_type("on_fire")
super().__init__(**kwargs)
def on_fire(self):
pass
A more cleaner fix would be
class Object(Widget):
__events__ = ("on_fire",)
def on_fire(self):
pass
HeaTTheatR commented
Thanks, let's check it out!