modalview: fix successive call of open() then dismiss()

This commit is contained in:
Mathieu Virbel 2013-04-29 16:30:39 +02:00
parent 3c62069bb8
commit 662038ab56
1 changed files with 22 additions and 6 deletions

View File

@ -138,7 +138,7 @@ class ModalView(AnchorLayout):
_anim_alpha = NumericProperty(0)
_anim_duration = NumericProperty(.100)
_anim_duration = NumericProperty(.1)
_window = ObjectProperty(None, allownone=True)
@ -176,11 +176,21 @@ class ModalView(AnchorLayout):
on_resize=self._align_center,
on_keyboard=self._handle_keyboard)
self.center = self._window.center
self.bind(size=self._update_center)
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 _update_center(self, *args):
if not self._window:
return
# XXX HACK DONT REMOVE OR FOUND AND FIX THE ISSUE
# It seems that if we don't access to the center before assigning a new
# value, no dispatch will be done >_>
a = self.center
self.center = self._window.center
def dismiss(self, *largs, **kwargs):
'''Close the view if it is open. If you really want to close the
view, whatever the on_dismiss event returns, you can do this:
@ -204,6 +214,7 @@ class ModalView(AnchorLayout):
Animation(_anim_alpha=0., d=self._anim_duration).start(self)
else:
self._anim_alpha = 0
self._real_remove_widget()
return self
def on_size(self, instance, value):
@ -235,11 +246,16 @@ 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,
on_keyboard=self._handle_keyboard)
self._window = None
self._real_remove_widget()
def _real_remove_widget(self):
if self._window is None:
return
self._window.remove_widget(self)
self._window.unbind(
on_resize=self._align_center,
on_keyboard=self._handle_keyboard)
self._window = None
def on_open(self):
pass