Merge branch 'master' into color_label

This commit is contained in:
Mathieu Virbel 2012-11-19 16:49:54 +01:00
commit 842b284c0d
3 changed files with 22 additions and 7 deletions

View File

@ -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'),

View File

@ -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.

View File

@ -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,10 +171,13 @@ 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
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):
@ -226,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):
@ -235,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