Created
May 19, 2016 17:05
-
-
Save spinningD20/865b82a106d650d3cdda88ce0064b53d to your computer and use it in GitHub Desktop.
custom event binding order issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from kivy.app import App | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.uix.button import Button | |
class AfterSuperButton(Button): | |
def __init__(self, **kwargs): | |
super(AfterSuperButton, self).__init__(**kwargs) | |
self.register_event_type('on_custom') | |
def on_custom(self, *args): | |
self.text += ' - buttons on custom hit - ' | |
class BeforeSuperButton(Button): | |
def __init__(self, **kwargs): | |
self.register_event_type('on_custom') | |
super(BeforeSuperButton, self).__init__(**kwargs) | |
def on_custom(self, *args): | |
self.text += ' - buttons on custom hit - ' | |
class NoPostBindBox(BoxLayout): | |
def __init__(self, **kwargs): | |
super(NoPostBindBox, self).__init__(**kwargs) | |
self.add_widget(BeforeSuperButton(text='before, no post bind', on_custom=self.update_text)) | |
self.add_widget(AfterSuperButton(text='after, no post bind', on_custom=self.update_text)) | |
def update_text(self, button): | |
print('update_text NoPostBindBox') | |
button.text += 'changed from NoPostBindBox' | |
class PostBindBox(BoxLayout): | |
def __init__(self, **kwargs): | |
super(PostBindBox, self).__init__(**kwargs) | |
before = BeforeSuperButton(text='before, with post bind') | |
before.bind(on_custom=self.update_text) | |
after = AfterSuperButton(text='after, with post bind') | |
after.bind(on_custom=self.update_text) | |
self.add_widget(before) | |
self.add_widget(after) | |
def update_text(self, button): | |
print('update_text PostBindBox') | |
button.text += 'changed from BindBox' | |
class SuperApp(App): | |
pass | |
if __name__ == '__main__': | |
SuperApp().run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<AfterSuperButton>: | |
text: 'AfterSuperButton' | |
on_release: self.dispatch('on_custom') | |
<BeforeSuperButton>: | |
text: 'BeforeSuperButton' | |
on_release: self.dispatch('on_custom') | |
GridLayout: | |
cols: 1 | |
NoPostBindBox: | |
PostBindBox: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment