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

Proposal to Use __events__ instead of register_event_type #1726

Open
kengoon opened this issue Aug 11, 2024 · 1 comment
Open

Proposal to Use __events__ instead of register_event_type #1726

kengoon opened this issue Aug 11, 2024 · 1 comment
Labels
Status: Needs analysis Issue needs to be analyzed if it's real Type: Enhancement Feature request/Feature implementation

Comments

@kengoon
Copy link

kengoon commented Aug 11, 2024

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 HeaTTheatR added Type: Enhancement Feature request/Feature implementation Status: Needs analysis Issue needs to be analyzed if it's real labels Aug 12, 2024
@HeaTTheatR
Copy link
Member

Thanks, let's check it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs analysis Issue needs to be analyzed if it's real Type: Enhancement Feature request/Feature implementation
Projects
None yet
Development

No branches or pull requests

2 participants