Mercurial > libervia-desktop-kivy
annotate cagou/backport/carousel.py @ 350:1ac40d3121f6
core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jan 2020 18:44:35 +0100 |
parents | 5bd583d00594 |
children |
rev | line source |
---|---|
323
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 Carousel |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 ======== |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 .. image:: images/carousel.gif |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 :align: right |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 .. versionadded:: 1.4.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 The :class:`Carousel` widget provides the classic mobile-friendly carousel view |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 where you can swipe between slides. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 You can add any content to the carousel and have it move horizontally or |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 vertically. The carousel can display pages in a sequence or a loop. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 Example:: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 from kivy.app import App |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 from kivy.uix.carousel import Carousel |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from kivy.uix.image import AsyncImage |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 class CarouselApp(App): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 def build(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 carousel = Carousel(direction='right') |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 for i in range(10): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 src = "http://placehold.it/480x270.png&text=slide-%d&.png" % i |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 image = AsyncImage(source=src, allow_stretch=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 carousel.add_widget(image) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 return carousel |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 CarouselApp().run() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 Kv Example:: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 Carousel: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 direction: 'right' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 AsyncImage: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 source: 'http://placehold.it/480x270.png&text=slide-1.png' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 AsyncImage: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 source: 'http://placehold.it/480x270.png&text=slide-2.png' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 AsyncImage: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 source: 'http://placehold.it/480x270.png&text=slide-3.png' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 AsyncImage: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 source: 'http://placehold.it/480x270.png&text=slide-4.png' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 .. versionchanged:: 1.5.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 The carousel now supports active children, like the |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 :class:`~kivy.uix.scrollview.ScrollView`. It will detect a swipe gesture |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 according to the :attr:`Carousel.scroll_timeout` and |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 :attr:`Carousel.scroll_distance` properties. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 In addition, the slide container is no longer exposed by the API. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 The impacted properties are |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 :attr:`Carousel.slides`, :attr:`Carousel.current_slide`, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 :attr:`Carousel.previous_slide` and :attr:`Carousel.next_slide`. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 __all__ = ('Carousel', ) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 from functools import partial |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 from kivy.clock import Clock |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 from kivy.factory import Factory |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 from kivy.animation import Animation |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 from kivy.uix.stencilview import StencilView |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 from kivy.uix.relativelayout import RelativeLayout |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 from kivy.properties import BooleanProperty, OptionProperty, AliasProperty, \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 NumericProperty, ListProperty, ObjectProperty, StringProperty |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 class Carousel(StencilView): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 '''Carousel class. See module documentation for more information. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 slides = ListProperty([]) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 '''List of slides inside the Carousel. The slides are the |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 widgets added to the Carousel using the :attr:`add_widget` method. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 :attr:`slides` is a :class:`~kivy.properties.ListProperty` and is |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 read-only. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 def _get_slides_container(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 return [x.parent for x in self.slides] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 slides_container = AliasProperty(_get_slides_container, bind=('slides',)) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 direction = OptionProperty('right', |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 options=('right', 'left', 'top', 'bottom')) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 '''Specifies the direction in which the slides are ordered. This |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 corresponds to the direction from which the user swipes to go from one |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 slide to the next. It |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 can be `right`, `left`, `top`, or `bottom`. For example, with |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 the default value of `right`, the second slide is to the right |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 of the first and the user would swipe from the right towards the |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 left to get to the second slide. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 :attr:`direction` is an :class:`~kivy.properties.OptionProperty` and |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 defaults to 'right'. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 min_move = NumericProperty(0.2) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 '''Defines the minimum distance to be covered before the touch is |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 considered a swipe gesture and the Carousel content changed. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 This is a expressed as a fraction of the Carousel's width. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 If the movement doesn't reach this minimum value, the movement is |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 cancelled and the content is restored to its original position. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 :attr:`min_move` is a :class:`~kivy.properties.NumericProperty` and |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 defaults to 0.2. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 anim_move_duration = NumericProperty(0.5) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 '''Defines the duration of the Carousel animation between pages. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 :attr:`anim_move_duration` is a :class:`~kivy.properties.NumericProperty` |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 and defaults to 0.5. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 anim_cancel_duration = NumericProperty(0.3) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 '''Defines the duration of the animation when a swipe movement is not |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 accepted. This is generally when the user does not make a large enough |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 swipe. See :attr:`min_move`. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 :attr:`anim_cancel_duration` is a :class:`~kivy.properties.NumericProperty` |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 and defaults to 0.3. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 loop = BooleanProperty(False) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 '''Allow the Carousel to loop infinitely. If True, when the user tries to |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 swipe beyond last page, it will return to the first. If False, it will |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 remain on the last page. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 :attr:`loop` is a :class:`~kivy.properties.BooleanProperty` and |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 defaults to False. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 def _get_index(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 if self.slides: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 return self._index % len(self.slides) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 return None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 def _set_index(self, value): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 if self.slides: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 self._index = value % len(self.slides) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 self._index = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 index = AliasProperty(_get_index, _set_index, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 bind=('_index', 'slides'), |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 cache=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 '''Get/Set the current slide based on the index. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 :attr:`index` is an :class:`~kivy.properties.AliasProperty` and defaults |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 to 0 (the first item). |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 def _prev_slide(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 slides = self.slides |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 len_slides = len(slides) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 index = self.index |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 if len_slides < 2: # None, or 1 slide |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 return None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 if self.loop and index == 0: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 return slides[-1] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 if index > 0: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 return slides[index - 1] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 previous_slide = AliasProperty(_prev_slide, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 bind=('slides', 'index', 'loop'), |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 cache=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 '''The previous slide in the Carousel. It is None if the current slide is |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 the first slide in the Carousel. This ordering reflects the order in which |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 the slides are added: their presentation varies according to the |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 :attr:`direction` property. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 :attr:`previous_slide` is an :class:`~kivy.properties.AliasProperty`. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 .. versionchanged:: 1.5.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 This property no longer exposes the slides container. It returns |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 the widget you have added. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 def _curr_slide(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 if len(self.slides): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 return self.slides[self.index or 0] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 current_slide = AliasProperty(_curr_slide, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 bind=('slides', 'index'), |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 cache=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 '''The currently shown slide. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 :attr:`current_slide` is an :class:`~kivy.properties.AliasProperty`. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 .. versionchanged:: 1.5.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 The property no longer exposes the slides container. It returns |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 the widget you have added. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 def _next_slide(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 if len(self.slides) < 2: # None, or 1 slide |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 return None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 if self.loop and self.index == len(self.slides) - 1: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 return self.slides[0] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 if self.index < len(self.slides) - 1: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 return self.slides[self.index + 1] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 next_slide = AliasProperty(_next_slide, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 bind=('slides', 'index', 'loop'), |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 cache=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 '''The next slide in the Carousel. It is None if the current slide is |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 the last slide in the Carousel. This ordering reflects the order in which |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 the slides are added: their presentation varies according to the |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 :attr:`direction` property. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 :attr:`next_slide` is an :class:`~kivy.properties.AliasProperty`. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 .. versionchanged:: 1.5.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 The property no longer exposes the slides container. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 It returns the widget you have added. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 scroll_timeout = NumericProperty(200) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 '''Timeout allowed to trigger the :attr:`scroll_distance`, in milliseconds. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 If the user has not moved :attr:`scroll_distance` within the timeout, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 no scrolling will occur and the touch event will go to the children. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 :attr:`scroll_timeout` is a :class:`~kivy.properties.NumericProperty` and |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 defaults to 200 (milliseconds) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 .. versionadded:: 1.5.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 scroll_distance = NumericProperty('20dp') |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 '''Distance to move before scrolling the :class:`Carousel` in pixels. As |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 soon as the distance has been traveled, the :class:`Carousel` will start |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 to scroll, and no touch event will go to children. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 It is advisable that you base this value on the dpi of your target device's |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 screen. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 :attr:`scroll_distance` is a :class:`~kivy.properties.NumericProperty` and |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 defaults to 20dp. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 .. versionadded:: 1.5.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 anim_type = StringProperty('out_quad') |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 '''Type of animation to use while animating to the next/previous slide. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 This should be the name of an |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 :class:`~kivy.animation.AnimationTransition` function. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 :attr:`anim_type` is a :class:`~kivy.properties.StringProperty` and |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 defaults to 'out_quad'. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 .. versionadded:: 1.8.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 ignore_perpendicular_swipes = BooleanProperty(False) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 '''Ignore swipes on axis perpendicular to direction. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 :attr:`ignore_perpendicular_swipes` is a |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 :class:`~kivy.properties.BooleanProperty` and defaults to False. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 .. versionadded:: 1.10.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 # private properties, for internal use only ### |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 _index = NumericProperty(0, allownone=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 _prev = ObjectProperty(None, allownone=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 _current = ObjectProperty(None, allownone=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 _next = ObjectProperty(None, allownone=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 _offset = NumericProperty(0) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 _touch = ObjectProperty(None, allownone=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 _change_touch_mode_ev = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 def __init__(self, **kwargs): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 self._trigger_position_visible_slides = Clock.create_trigger( |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 self._position_visible_slides, -1) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 super(Carousel, self).__init__(**kwargs) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 self._skip_slide = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 self.touch_mode_change = False |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 self._prioritize_next = False |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 self.fbind('loop', lambda *args: self._insert_visible_slides()) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 def load_slide(self, slide): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 '''Animate to the slide that is passed as the argument. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 .. versionchanged:: 1.8.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 slides = self.slides |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 start, stop = slides.index(self.current_slide), slides.index(slide) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 if start == stop: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 self._skip_slide = stop |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 if stop > start: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 self._prioritize_next = True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 self._insert_visible_slides(_next_slide=slide) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 self.load_next() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 self._prioritize_next = False |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 self._insert_visible_slides(_prev_slide=slide) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 self.load_previous() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 def load_previous(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 '''Animate to the previous slide. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 .. versionadded:: 1.7.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 self.load_next(mode='prev') |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 def load_next(self, mode='next'): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 '''Animate to the next slide. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 .. versionadded:: 1.7.0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 ''' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 if self.index is not None: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 w, h = self.size |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 _direction = { |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 'top': -h / 2, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 'bottom': h / 2, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 'left': w / 2, |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 'right': -w / 2} |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 _offset = _direction[self.direction] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 if mode == 'prev': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 _offset = -_offset |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 self._start_animation(min_move=0, offset=_offset) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 def get_slide_container(self, slide): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 return slide.parent |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 @property |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 def _prev_equals_next(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 return self.loop and len(self.slides) == 2 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 def _insert_visible_slides(self, _next_slide=None, _prev_slide=None): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 get_slide_container = self.get_slide_container |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 previous_slide = _prev_slide if _prev_slide else self.previous_slide |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 if previous_slide: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 self._prev = get_slide_container(previous_slide) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 self._prev = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 current_slide = self.current_slide |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 if current_slide: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 self._current = get_slide_container(current_slide) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 self._current = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 next_slide = _next_slide if _next_slide else self.next_slide |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 if next_slide: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 self._next = get_slide_container(next_slide) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 self._next = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 if self._prev_equals_next: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 setattr(self, '_prev' if self._prioritize_next else '_next', None) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 super_remove = super(Carousel, self).remove_widget |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 for container in self.slides_container: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 super_remove(container) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 if self._prev and self._prev.parent is not self: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 super(Carousel, self).add_widget(self._prev) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 if self._next and self._next.parent is not self: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 super(Carousel, self).add_widget(self._next) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 if self._current: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 super(Carousel, self).add_widget(self._current) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 def _position_visible_slides(self, *args): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 slides, index = self.slides, self.index |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 no_of_slides = len(slides) - 1 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 if not slides: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 x, y, width, height = self.x, self.y, self.width, self.height |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 _offset, direction = self._offset, self.direction[0] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 _prev, _next, _current = self._prev, self._next, self._current |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 get_slide_container = self.get_slide_container |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 last_slide = get_slide_container(slides[-1]) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 first_slide = get_slide_container(slides[0]) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 skip_next = False |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 _loop = self.loop |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 if direction in 'rl': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 xoff = x + _offset |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 x_prev = {'l': xoff + width, 'r': xoff - width} |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 x_next = {'l': xoff - width, 'r': xoff + width} |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 if _prev: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 _prev.pos = (x_prev[direction], y) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 elif _loop and _next and index == 0: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 # if first slide is moving to right with direction set to right |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 # or toward left with direction set to left |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 if ((_offset > 0 and direction == 'r') or |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 (_offset < 0 and direction == 'l')): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 # put last_slide before first slide |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 last_slide.pos = (x_prev[direction], y) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 skip_next = True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 if _current: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 _current.pos = (xoff, y) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 if skip_next: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 if _next: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 _next.pos = (x_next[direction], y) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 elif _loop and _prev and index == no_of_slides: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 if ((_offset < 0 and direction == 'r') or |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 (_offset > 0 and direction == 'l')): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 first_slide.pos = (x_next[direction], y) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 if direction in 'tb': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 yoff = y + _offset |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 y_prev = {'t': yoff - height, 'b': yoff + height} |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 y_next = {'t': yoff + height, 'b': yoff - height} |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
418 if _prev: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 _prev.pos = (x, y_prev[direction]) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 elif _loop and _next and index == 0: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 if ((_offset > 0 and direction == 't') or |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 (_offset < 0 and direction == 'b')): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 last_slide.pos = (x, y_prev[direction]) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 skip_next = True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 if _current: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 _current.pos = (x, yoff) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 if skip_next: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 if _next: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 _next.pos = (x, y_next[direction]) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 elif _loop and _prev and index == no_of_slides: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 if ((_offset < 0 and direction == 't') or |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 (_offset > 0 and direction == 'b')): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
434 first_slide.pos = (x, y_next[direction]) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 def on_size(self, *args): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
437 size = self.size |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 for slide in self.slides_container: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
439 slide.size = size |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
440 self._trigger_position_visible_slides() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
442 def on_pos(self, *args): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 self._trigger_position_visible_slides() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
445 def on_index(self, *args): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
446 self._insert_visible_slides() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 self._trigger_position_visible_slides() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 self._offset = 0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 def on_slides(self, *args): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 if self.slides: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
452 self.index = self.index % len(self.slides) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 self._insert_visible_slides() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 self._trigger_position_visible_slides() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 def on__offset(self, *args): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 self._trigger_position_visible_slides() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 # if reached full offset, switch index to next or prev |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 direction = self.direction[0] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 _offset = self._offset |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 width = self.width |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 height = self.height |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 index = self.index |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 if self._skip_slide is not None or index is None: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 # Move to next slide? |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 if (direction == 'r' and _offset <= -width) or \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 (direction == 'l' and _offset >= width) or \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 (direction == 't' and _offset <= - height) or \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 (direction == 'b' and _offset >= height): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 if self.next_slide: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 self.index += 1 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 # Move to previous slide? |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 elif (direction == 'r' and _offset >= width) or \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 (direction == 'l' and _offset <= -width) or \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 (direction == 't' and _offset >= height) or \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 (direction == 'b' and _offset <= -height): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 if self.previous_slide: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 self.index -= 1 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 elif self._prev_equals_next: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 new_value = (_offset < 0) is (direction in 'rt') |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 if self._prioritize_next is not new_value: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 self._prioritize_next = new_value |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 if new_value is (self._next is None): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 self._prev, self._next = self._next, self._prev |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 def _start_animation(self, *args, **kwargs): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 # compute target offset for ease back, next or prev |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
492 new_offset = 0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 direction = kwargs.get('direction', self.direction)[0] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 is_horizontal = direction in 'rl' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 extent = self.width if is_horizontal else self.height |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 min_move = kwargs.get('min_move', self.min_move) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
497 _offset = kwargs.get('offset', self._offset) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
498 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
499 if _offset < min_move * -extent: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
500 new_offset = -extent |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 elif _offset > min_move * extent: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
502 new_offset = extent |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
504 # if new_offset is 0, it wasnt enough to go next/prev |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 dur = self.anim_move_duration |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 if new_offset == 0: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 dur = self.anim_cancel_duration |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
508 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 # detect edge cases if not looping |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 len_slides = len(self.slides) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
511 index = self.index |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 if not self.loop or len_slides == 1: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
513 is_first = (index == 0) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
514 is_last = (index == len_slides - 1) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
515 if direction in 'rt': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 towards_prev = (new_offset > 0) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
517 towards_next = (new_offset < 0) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
519 towards_prev = (new_offset < 0) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 towards_next = (new_offset > 0) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
521 if (is_first and towards_prev) or (is_last and towards_next): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
522 new_offset = 0 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
523 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 anim = Animation(_offset=new_offset, d=dur, t=self.anim_type) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 anim.cancel_all(self) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
526 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
527 def _cmp(*l): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
528 if self._skip_slide is not None: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
529 self.index = self._skip_slide |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
530 self._skip_slide = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
531 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
532 anim.bind(on_complete=_cmp) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
533 anim.start(self) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
534 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
535 def _get_uid(self, prefix='sv'): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
536 return '{0}.{1}'.format(prefix, self.uid) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
537 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
538 def on_touch_down(self, touch): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
539 if not self.collide_point(*touch.pos): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
540 touch.ud[self._get_uid('cavoid')] = True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
541 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
542 if self.disabled: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
543 return True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
544 if self._touch: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
545 return super(Carousel, self).on_touch_down(touch) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
546 Animation.cancel_all(self) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
547 self._touch = touch |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
548 uid = self._get_uid() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
549 touch.grab(self) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
550 touch.ud[uid] = { |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
551 'mode': 'unknown', |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
552 'time': touch.time_start} |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
553 self._change_touch_mode_ev = Clock.schedule_once( |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
554 self._change_touch_mode, self.scroll_timeout / 1000.) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
555 self.touch_mode_change = False |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
556 return True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
557 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
558 def on_touch_move(self, touch): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
559 if not self.touch_mode_change: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
560 if self.ignore_perpendicular_swipes and \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
561 self.direction in ('top', 'bottom'): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
562 if abs(touch.oy - touch.y) < self.scroll_distance: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
563 if abs(touch.ox - touch.x) > self.scroll_distance: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
564 self._change_touch_mode() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
565 self.touch_mode_change = True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
566 elif self.ignore_perpendicular_swipes and \ |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
567 self.direction in ('right', 'left'): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
568 if abs(touch.ox - touch.x) < self.scroll_distance: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
569 if abs(touch.oy - touch.y) > self.scroll_distance: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
570 self._change_touch_mode() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
571 self.touch_mode_change = True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
572 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 if self._get_uid('cavoid') in touch.ud: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
574 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
575 if self._touch is not touch: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
576 super(Carousel, self).on_touch_move(touch) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
577 return self._get_uid() in touch.ud |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
578 if touch.grab_current is not self: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
579 return True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
580 ud = touch.ud[self._get_uid()] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
581 direction = self.direction[0] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
582 if ud['mode'] == 'unknown': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
583 if direction in 'rl': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
584 distance = abs(touch.ox - touch.x) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
585 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
586 distance = abs(touch.oy - touch.y) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
587 if distance > self.scroll_distance: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
588 ev = self._change_touch_mode_ev |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
589 if ev is not None: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 ev.cancel() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
591 ud['mode'] = 'scroll' |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
593 if direction in 'rl': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
594 self._offset += touch.dx |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
595 if direction in 'tb': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
596 self._offset += touch.dy |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
597 return True |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
598 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
599 def on_touch_up(self, touch): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
600 if self._get_uid('cavoid') in touch.ud: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
601 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
602 if self in [x() for x in touch.grab_list]: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
603 touch.ungrab(self) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
604 self._touch = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
605 ud = touch.ud[self._get_uid()] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
606 if ud['mode'] == 'unknown': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
607 ev = self._change_touch_mode_ev |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
608 if ev is not None: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
609 ev.cancel() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
610 super(Carousel, self).on_touch_down(touch) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
611 Clock.schedule_once(partial(self._do_touch_up, touch), .1) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
612 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
613 self._start_animation() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
614 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
615 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
616 if self._touch is not touch and self.uid not in touch.ud: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
617 super(Carousel, self).on_touch_up(touch) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
618 return self._get_uid() in touch.ud |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
619 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
620 def _do_touch_up(self, touch, *largs): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
621 super(Carousel, self).on_touch_up(touch) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
622 # don't forget about grab event! |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
623 for x in touch.grab_list[:]: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
624 touch.grab_list.remove(x) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
625 x = x() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
626 if not x: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 continue |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
628 touch.grab_current = x |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
629 super(Carousel, self).on_touch_up(touch) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
630 touch.grab_current = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
631 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
632 def _change_touch_mode(self, *largs): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
633 if not self._touch: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
634 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
635 self._start_animation() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
636 uid = self._get_uid() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
637 touch = self._touch |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
638 ud = touch.ud[uid] |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
639 if ud['mode'] == 'unknown': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
640 touch.ungrab(self) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
641 self._touch = None |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 super(Carousel, self).on_touch_down(touch) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 return |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
644 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
645 def add_widget(self, widget, index=0, canvas=None): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
646 container = RelativeLayout( |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
647 size=self.size, x=self.x - self.width, y=self.y) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
648 container.add_widget(widget) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
649 super(Carousel, self).add_widget(container, index, canvas) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
650 if index != 0: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 self.slides.insert(index - len(self.slides), widget) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
652 else: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
653 self.slides.append(widget) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
654 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
655 def remove_widget(self, widget, *args, **kwargs): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
656 # XXX be careful, the widget.parent refer to the RelativeLayout |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
657 # added in add_widget(). But it will break if RelativeLayout |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
658 # implementation change. |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
659 # if we passed the real widget |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
660 slides = self.slides |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
661 if widget in slides: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 if self.index >= slides.index(widget): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
663 self.index = max(0, self.index - 1) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
664 container = widget.parent |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
665 slides.remove(widget) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
666 super(Carousel, self).remove_widget(container) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
667 return container.remove_widget(widget, *args, **kwargs) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
668 return super(Carousel, self).remove_widget(widget, *args, **kwargs) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
669 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
670 def clear_widgets(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
671 for slide in self.slides[:]: |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
672 self.remove_widget(slide) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
673 super(Carousel, self).clear_widgets() |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
674 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
675 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
676 if __name__ == '__main__': |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
677 from kivy.app import App |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
678 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
679 class Example1(App): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
681 def build(self): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
682 carousel = Carousel(direction='left', |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 loop=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
684 for i in range(4): |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
685 src = "http://placehold.it/480x270.png&text=slide-%d&.png" % i |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
686 image = Factory.AsyncImage(source=src, allow_stretch=True) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
687 carousel.add_widget(image) |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
688 return carousel |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
689 |
5bd583d00594
backport: added a new "backport" module for using unreleased code from Kivy:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
690 Example1().run() |