~ubuntu-branches/debian/stretch/electrum/stretch

« back to all changes in this revision

Viewing changes to gui/kivy/tools/.buildozer/android/platform/python-for-android/dist/kivy/python-install/lib/python2.7/site-packages/kivy/effects/dampedscroll.py

  • Committer: Package Import Robot
  • Author(s): Tristan Seligmann
  • Date: 2016-04-04 03:02:39 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20160404030239-0szgkio8yryjv7c9
Tags: 2.6.3-1
* New upstream release.
  - Drop backported install-wizard-connect.patch.
* Add Suggests: python-zbar and update the installation hint to suggest
  apt-get instead of pip (closes: #819517).
* Bump Standards-Version to 3.9.7 (no changes).
* Update Vcs-* links.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''
 
2
Damped scroll effect
 
3
====================
 
4
 
 
5
.. versionadded:: 1.7.0
 
6
 
 
7
This damped scroll effect will use the
 
8
:attr:`~kivy.effects.scroll.ScrollEffect.overscroll` to calculate the scroll
 
9
value, and slows going back to the upper or lower limit.
 
10
 
 
11
'''
 
12
 
 
13
__all__ = ('DampedScrollEffect',)
 
14
 
 
15
 
 
16
from kivy.effects.scroll import ScrollEffect
 
17
from kivy.properties import NumericProperty, BooleanProperty
 
18
from kivy.metrics import sp
 
19
 
 
20
 
 
21
class DampedScrollEffect(ScrollEffect):
 
22
    '''DampedScrollEffect class. See the module documentation for more
 
23
    information.
 
24
    '''
 
25
 
 
26
    edge_damping = NumericProperty(0.25)
 
27
    '''Edge damping.
 
28
 
 
29
    :attr:`edge_damping` is a :class:`~kivy.properties.NumericProperty` and
 
30
    defaults to 0.25
 
31
    '''
 
32
 
 
33
    spring_constant = NumericProperty(2.0)
 
34
    '''Spring constant.
 
35
 
 
36
    :attr:`spring_constant` is a :class:`~kivy.properties.NumericProperty` and
 
37
    defaults to 2.0
 
38
    '''
 
39
 
 
40
    min_overscroll = NumericProperty(.5)
 
41
    '''An overscroll less than this amount will be normalized to 0.
 
42
 
 
43
    .. versionadded:: 1.8.0
 
44
 
 
45
    :attr:`min_overscroll` is a :class:`~kivy.properties.NumericProperty` and
 
46
    defaults to .5.
 
47
    '''
 
48
 
 
49
    round_value = BooleanProperty(True)
 
50
    '''If True, when the motion stops, :attr:`value` is rounded to the nearest
 
51
    integer.
 
52
 
 
53
    .. versionadded:: 1.8.0
 
54
 
 
55
    :attr:`round_value` is a :class:`~kivy.properties.BooleanProperty` and
 
56
    defaults to True.
 
57
    '''
 
58
    def update_velocity(self, dt):
 
59
        if abs(self.velocity) <= self.min_velocity and self.overscroll == 0:
 
60
            self.velocity = 0
 
61
            # why does this need to be rounded? For now refactored it.
 
62
            if self.round_value:
 
63
                self.value = round(self.value)
 
64
            return
 
65
 
 
66
        total_force = self.velocity * self.friction
 
67
        if abs(self.overscroll) > self.min_overscroll:
 
68
            total_force += self.velocity * self.edge_damping
 
69
            total_force += self.overscroll * self.spring_constant
 
70
        else:
 
71
            self.overscroll = 0
 
72
 
 
73
        stop_overscroll = ''
 
74
        if not self.is_manual:
 
75
            if self.overscroll > 0 and self.velocity < 0:
 
76
                stop_overscroll = 'max'
 
77
            elif self.overscroll < 0 and self.velocity > 0:
 
78
                stop_overscroll = 'min'
 
79
 
 
80
        self.velocity = self.velocity - total_force
 
81
        if not self.is_manual:
 
82
            self.apply_distance(self.velocity * dt)
 
83
            if stop_overscroll == 'min' and self.value > self.min:
 
84
                self.value = self.min
 
85
                self.velocity = 0
 
86
                return
 
87
            if stop_overscroll == 'max' and self.value < self.max:
 
88
                self.value = self.max
 
89
                self.velocity = 0
 
90
                return
 
91
        self.trigger_velocity_update()
 
92
 
 
93
    def on_value(self, *args):
 
94
        scroll_min = self.min
 
95
        scroll_max = self.max
 
96
        if scroll_min > scroll_max:
 
97
            scroll_min, scroll_max = scroll_max, scroll_min
 
98
        if self.value < scroll_min:
 
99
            self.overscroll = self.value - scroll_min
 
100
        elif self.value > scroll_max:
 
101
            self.overscroll = self.value - scroll_max
 
102
        else:
 
103
            self.overscroll = 0
 
104
        self.scroll = self.value
 
105
 
 
106
    def on_overscroll(self, *args):
 
107
        self.trigger_velocity_update()
 
108
 
 
109
    def apply_distance(self, distance):
 
110
        os = abs(self.overscroll)
 
111
        if os:
 
112
            distance /= 1. + os / sp(200.)
 
113
        super(DampedScrollEffect, self).apply_distance(distance)