From afd670942af6838e7715206e54df0d6d664199d7 Mon Sep 17 00:00:00 2001 From: Gendo Ikari Date: Wed, 7 Nov 2012 19:02:57 +0100 Subject: [PATCH 1/2] performance fix in widget constructor for event binding --- kivy/uix/widget.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kivy/uix/widget.py b/kivy/uix/widget.py index 0ce503f42..ae3153a4e 100644 --- a/kivy/uix/widget.py +++ b/kivy/uix/widget.py @@ -154,9 +154,9 @@ class Widget(EventDispatcher): # Builder.idmap.pop('root') # Bind all the events - for argument, value in kwargs.items(): - if argument.startswith('on_'): - self.bind(**{argument: value}) + for argument in kwargs: + if argument[:3] == 'on_': + self.bind(**{argument: kwargs[argument]}) # # Collision From 6ddafdbfa8de5bbaa4ddec5995ab2f06b9e816ac Mon Sep 17 00:00:00 2001 From: Gendo Ikari Date: Wed, 7 Nov 2012 19:19:27 +0100 Subject: [PATCH 2/2] examples: using new api for event binding in kwargs --- examples/animation/animate.py | 3 +-- examples/canvas/canvas_stress.py | 12 ++++++------ examples/demo/showcase/main.py | 4 ++-- examples/widgets/popup_with_kv.py | 3 +-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/animation/animate.py b/examples/animation/animate.py index 0b642b036..cb28e48f8 100644 --- a/examples/animation/animate.py +++ b/examples/animation/animate.py @@ -28,8 +28,7 @@ class TestApp(App): def build(self): # create a button, and attach animate() method as a on_press handler - button = Button(size_hint=(None, None), text='plop') - button.bind(on_press=self.animate) + button = Button(size_hint=(None, None), text='plop', on_press=self.animate) return button if __name__ == '__main__': diff --git a/examples/canvas/canvas_stress.py b/examples/canvas/canvas_stress.py index 458559cc7..b52998f0c 100644 --- a/examples/canvas/canvas_stress.py +++ b/examples/canvas/canvas_stress.py @@ -34,14 +34,14 @@ class StressCanvasApp(App): label = Label(text='0') - btn_add100 = Button(text='+ 100 rects') - btn_add100.bind(on_press=partial(self.add_rects, label, wid, 100)) + btn_add100 = Button(text='+ 100 rects', + on_press=partial(self.add_rects, label, wid, 100)) - btn_add500 = Button(text='+ 500 rects') - btn_add500.bind(on_press=partial(self.add_rects, label, wid, 500)) + btn_add500 = Button(text='+ 500 rects', + on_press=partial(self.add_rects, label, wid, 500)) - btn_reset = Button(text='Reset') - btn_reset.bind(on_press=partial(self.reset_rects, label, wid)) + btn_reset = Button(text='Reset', + on_press=partial(self.reset_rects, label, wid)) layout = BoxLayout(size_hint=(1, None), height=50) layout.add_widget(btn_add100) diff --git a/examples/demo/showcase/main.py b/examples/demo/showcase/main.py index db966fcc4..3eba89786 100644 --- a/examples/demo/showcase/main.py +++ b/examples/demo/showcase/main.py @@ -259,8 +259,8 @@ class ShowcaseApp(App): auto_dismiss=False) btnclose.bind(on_release=popup.dismiss) button = Button(text='Open popup', size_hint=(None, None), - size=('150sp', '70dp')) - button.bind(on_release=popup.open) + size=('150sp', '70dp'), + on_release=popup.open) popup.open() col = AnchorLayout() col.add_widget(button) diff --git a/examples/widgets/popup_with_kv.py b/examples/widgets/popup_with_kv.py index 61bf7ca8d..0a42c4527 100644 --- a/examples/widgets/popup_with_kv.py +++ b/examples/widgets/popup_with_kv.py @@ -22,8 +22,7 @@ class CustomPopup(Popup): class TestApp(App): def build(self): - b = Button() - b.bind(on_press=self.show_popup) + b = Button(on_press=self.show_popup) return b def show_popup(self, b):