From 32a21e29b1ab0b789f1017ee9136857c12717fb2 Mon Sep 17 00:00:00 2001 From: qua-non Date: Thu, 3 Oct 2013 21:51:49 +0530 Subject: [PATCH] uix:carousel introduce `load_slide` method to animate to the provided slide --- examples/widgets/carousel_buttons.py | 4 ++++ kivy/uix/carousel.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/examples/widgets/carousel_buttons.py b/examples/widgets/carousel_buttons.py index 7b22181f6..12bf3dedd 100644 --- a/examples/widgets/carousel_buttons.py +++ b/examples/widgets/carousel_buttons.py @@ -17,6 +17,10 @@ Builder.load_string(''' Button Button Button + text: 'load(page 3)' + on_release: + carousel = root.parent.parent + carousel.load_slide(carousel.slides[2]) Button Button text: 'prev' diff --git a/kivy/uix/carousel.py b/kivy/uix/carousel.py index 339f9f355..e04c04855 100644 --- a/kivy/uix/carousel.py +++ b/kivy/uix/carousel.py @@ -234,6 +234,20 @@ class Carousel(StencilView): self._position_visible_slides, -1) super(Carousel, self).__init__(**kwargs) + def load_slide(self, slide): + '''Animate to the slide that is passed as the argument. + + .. versionchanged:: 1.8.0 + ''' + slides = self.slides + start, stop = slides.index(self.current_slide), slides.index(slide) + if stop > start: + self.index = stop - 1 + self.load_next() + else: + self.index = stop + 1 + self.load_previous() + def load_previous(self): '''Animate to the previous slide.