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