-
Notifications
You must be signed in to change notification settings - Fork 0
/
customtransition.py
65 lines (57 loc) · 2.12 KB
/
customtransition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
from kivy.properties import OptionProperty
from kivy.uix.screenmanager import TransitionBase
class CustomTransition(TransitionBase):
'''CustomTransition, can be used to show a new screen from any direction:
left, right, up or down.
'''
direction = OptionProperty('left', options=('left', 'right', 'up', 'down'))
'''Direction of the transition.
:attr:`direction` is an :class:`~kivy.properties.OptionProperty` and
defaults to 'left'. Can be one of 'left', 'right', 'up' or 'down'.
'''
origpos = None
def on_progress(self, progression):
a = self.screen_in
b = self.screen_out
manager = self.manager
x, y = manager.pos
width, height = manager.size
direction = self.direction
progression = self.al(progression)
if direction == 'left':
a.y = b.y = y
a.x = x + width * (1 - progression)
b.x = x - width * progression
elif direction == 'right':
a.y = b.y = y
b.x = x + width * progression
a.x = x - width * (1 - progression)
elif direction == 'down':
a.x = b.x = x
a.y = y + height * (1 - progression)
b.y = y - height * progression
elif direction == 'up':
a.x = b.x = manager.x
b.y = y + height * progression
a.y = y - height * (1 - progression)
for c in b.children:
try:
if 'yellow' in c.source:
if not self.origpos:
self.origpos = c.pos_hint
c.pos_hint = {}
c.y += 10
except (AttributeError, TypeError):
pass
def on_complete(self):
for c in self.screen_out.children:
try:
if 'yellow' in c.source:
c.pos_hint = self.origpos
except (AttributeError, TypeError):
pass
self.origpos = None
self.screen_in.pos = self.manager.pos
self.screen_out.pos = self.manager.pos
super(CustomTransition, self).on_complete()