From 777a46a1f696af719f3f6fa2037d7accbc70b2bd Mon Sep 17 00:00:00 2001 From: tshirtman Date: Sat, 27 Oct 2012 19:37:46 +0200 Subject: [PATCH 1/3] put the dispatching of the on_open event of modalview after the animation --- kivy/uix/modalview.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kivy/uix/modalview.py b/kivy/uix/modalview.py index 1ed15af5b..77d117ac2 100644 --- a/kivy/uix/modalview.py +++ b/kivy/uix/modalview.py @@ -167,8 +167,9 @@ class ModalView(AnchorLayout): self._window.add_widget(self) self._window.bind(on_resize=self._align_center) self.center = self._window.center - Animation(_anim_alpha=1., d=self._anim_duration).start(self) - self.dispatch('on_open') + a = Animation(_anim_alpha=1., d=self._anim_duration) + a.bind(on_complete=lambda *x: self.dispatch('on_open')) + a.start(self) return self def dismiss(self, *largs, **kwargs): From 06372db288a84bf8dfccd450a3e2f8ddc7818dee Mon Sep 17 00:00:00 2001 From: Julien Miotte Date: Sat, 17 Nov 2012 14:15:03 +0100 Subject: [PATCH 2/3] Spacing is different from padding, fixing doc. --- kivy/uix/gridlayout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kivy/uix/gridlayout.py b/kivy/uix/gridlayout.py index bbf7197b0..559946244 100644 --- a/kivy/uix/gridlayout.py +++ b/kivy/uix/gridlayout.py @@ -105,7 +105,7 @@ class GridLayout(Layout): ''' spacing = NumericProperty(0) - '''Spacing between widget box and children, in pixels. + '''Spacing between children, in pixels. :data:`spacing` is a :class:`~kivy.properties.NumericProperty`, default to 0. From 7180c1ceb2cf1586a0b1de15c3813013f5440557 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 19 Nov 2012 16:46:23 +0100 Subject: [PATCH 3/3] modalview: allow to close the modalview by hitting escape, if the auto_dismiss is allowed. closes #776 --- examples/demo/showcase/main.py | 3 +-- kivy/uix/modalview.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/demo/showcase/main.py b/examples/demo/showcase/main.py index 3eba89786..0ae5f9a3b 100644 --- a/examples/demo/showcase/main.py +++ b/examples/demo/showcase/main.py @@ -255,8 +255,7 @@ class ShowcaseApp(App): content.add_widget(Label(text='Hello world')) content.add_widget(btnclose) popup = Popup(content=content, title='Modal popup example', - size_hint=(None, None), size=('300dp', '300dp'), - auto_dismiss=False) + size_hint=(None, None), size=('300dp', '300dp')) btnclose.bind(on_release=popup.dismiss) button = Button(text='Open popup', size_hint=(None, None), size=('150sp', '70dp'), diff --git a/kivy/uix/modalview.py b/kivy/uix/modalview.py index 77d117ac2..92ebe7a18 100644 --- a/kivy/uix/modalview.py +++ b/kivy/uix/modalview.py @@ -61,6 +61,12 @@ view from closing by explictly returning True from your callback :: view.bind(on_dismiss=my_callback) view.open() + +.. versionchanged:: 1.5.0 + + The ModalView can be closed by hitting escape key on the keyboard, if the + :data:`ModalView.auto_dismiss` is allowed. + ''' __all__ = ('ModalView', ) @@ -165,7 +171,9 @@ class ModalView(AnchorLayout): Logger.warning('ModalView: cannot open view, no window found.') return self self._window.add_widget(self) - self._window.bind(on_resize=self._align_center) + self._window.bind( + on_resize=self._align_center, + on_keyboard=self._handle_keyboard) self.center = self._window.center a = Animation(_anim_alpha=1., d=self._anim_duration) a.bind(on_complete=lambda *x: self.dispatch('on_open')) @@ -227,7 +235,9 @@ class ModalView(AnchorLayout): def on__anim_alpha(self, instance, value): if value == 0 and self._window is not None: self._window.remove_widget(self) - self._window.unbind(on_resize=self._align_center) + self._window.unbind( + on_resize=self._align_center, + on_keyboard=self._handle_keyboard) self._window = None def on_open(self): @@ -236,6 +246,11 @@ class ModalView(AnchorLayout): def on_dismiss(self): pass + def _handle_keyboard(self, window, key, *largs): + if key == 27 and self.auto_dismiss: + self.dismiss() + return True + if __name__ == '__main__': from kivy.base import runTouchApp