0

I made a little Kivy application as an interface. The carousel seems to be working, but I would like to make the carousel start by itself (that means without using a mouse). In fact, the app will be deployed on a little robot that does not have any mouse or keybord, thus that is why I need the carousel passing the images by itself.

As you can see in my code, the carousel does work, but I just can't figure out how to make it start without clicking on it with a mouse.

class Logo(App):

    def build(self):

        carousel = Carousel(direction='right')
        for i in range(2):
                src = "image.png"
                image = Factory.AsyncImage(source=src, allow_stretch=True)
                carousel.add_widget(image)

        return carousel


if __name__ == '__main__':

    Logo().run()

Any ideas ? Thanks.

hacks4life
  • 691
  • 5
  • 16
  • 38

1 Answers1

2

You want an event to trigger the movement, i think the easiest way would be to use a Clock.

from kivy.clock import Clock

then in your build, you could schedule incrementing the position of the carousel at some interval, carousel has a convenient function for that load_next, but if you just do that, it'll get stuck on the last frame pretty fast, so you'll probably want to pass loop=True to the Carousel instantiation.

from kivy.app import App
from kivy.factory import Factory
from kivy.uix.carousel import Carousel
from kivy.clock import Clock


class Logo(App):
    def build(self):

        carousel = Carousel(direction='right', loop=True)
        for i in range(2):
            image = Factory.Label(text=str(i))
            carousel.add_widget(image)

        Clock.schedule_interval(carousel.load_next, 1)
        return carousel


if __name__ == '__main__':
    Logo().run()

(i changed the images by labels to see the difference more easily)

Tshirtman
  • 5,859
  • 1
  • 19
  • 26
  • Thank you it worked, this is exactly what I need. Just one precision, in my case I am using pictures, how can I use several sources to have different images passing in the carousel ? – hacks4life Apr 08 '14 at 07:31
  • And actually if I place a `return carousel` here, I can't use any Layout then in my App right ? Because imagine I want to split my screen into a header at the top and the carousel in the rest of the window, this `return carousel` will take the whole screen right ? – hacks4life Apr 08 '14 at 08:29