screenmanager: ensure the screen position is fixed to the screenmanager position.

This commit is contained in:
Mathieu Virbel 2012-07-27 12:35:22 +02:00
parent fa921c3fa7
commit ba58922163
1 changed files with 24 additions and 1 deletions

View File

@ -118,7 +118,7 @@ __all__ = ('Screen', 'ScreenManager', 'ScreenManagerException',
from kivy.event import EventDispatcher
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import StringProperty, ObjectProperty, \
NumericProperty, ListProperty, OptionProperty
NumericProperty, ListProperty, OptionProperty, BooleanProperty
from kivy.animation import Animation, AnimationTransition
from kivy.uix.relativelayout import RelativeLayout
from kivy.lang import Builder
@ -222,6 +222,13 @@ class TransitionBase(EventDispatcher):
None, read-only.
'''
is_active = BooleanProperty()
'''Indicate if the transition is currently active
:data:`is_active` is a :class:`~kivy.properties.BooleanProperty`, default to
False, read-only.
'''
# privates
_anim = ObjectProperty(allownone=True)
@ -246,6 +253,7 @@ class TransitionBase(EventDispatcher):
self.screen_out.transition_progress = 0.
self.screen_out.transition_mode = 'out'
self.is_active = True
self._anim.start(self)
self.dispatch('on_progress', 0)
@ -257,6 +265,7 @@ class TransitionBase(EventDispatcher):
self._anim.cancel(self)
self.dispatch('on_complete')
self._anim = None
self.is_active = False
def add_screen(self, screen):
'''(internal) Used to add a screen into the :class:`ScreenManager`
@ -281,6 +290,7 @@ class TransitionBase(EventDispatcher):
self.dispatch('on_progress', progress)
def _on_complete(self, *l):
self.is_active = False
self.dispatch('on_complete')
self._anim = None
@ -550,6 +560,10 @@ class ScreenManager(FloatLayout):
default to None, read-only.
'''
def __init__(self, **kwargs):
super(ScreenManager, self).__init__(**kwargs)
self.bind(pos=self._update_pos)
def add_widget(self, screen):
if not isinstance(screen, Screen):
raise ScreenManagerException(
@ -584,6 +598,7 @@ class ScreenManager(FloatLayout):
self.transition.screen_out = previous_screen
self.transition.start(self)
else:
screen.pos = self.pos
self.real_add_widget(screen)
def get_screen(self, name):
@ -620,6 +635,14 @@ class ScreenManager(FloatLayout):
except ValueError:
return
def _update_pos(self, instance, value):
for child in self.children:
if self.transition.is_active and \
(child == self.transition.screen_in or \
child == self.transition.screen_out):
continue
child.pos = value
if __name__ == '__main__':
from kivy.app import App
from kivy.uix.button import Button