Repository: kivy/kivy

Issue:
Error in Kivy Carousel 1.11.0rc2





### Versions

* Python: Python 3.7.3
* OS: Windows 10
* Kivy: Kivy 1.11.0rc2
* Kivy installation method: Installed via pip --pre

### Description
Carousel will not function and throws an error in the logs.

Error is here

    def _curr_slide(self):
            return self.slides[self.index]

This fixes the issue:
    def _curr_slide(self):
        if len(self.slides):
            if self.index is None:
                self.index = 0
            return self.slides[self.index]


Note that I had to switch from 1.10 to the 1.11 version due to some DLL issues that were occuring with the 1.10 version.

### Code and Logs

This even breaks in the carousel.py provided by kivy so I copied and pasted the code from there:
    from kivy.app import App

    class Example1(App):

        def build(self):
            carousel = Carousel(direction='left',
                                loop=True)
            for i in range(4):
                src = "http://placehold.it/480x270.png&text=slide-%d&.png" % i
                image = Factory.AsyncImage(source=src, allow_stretch=True)
                carousel.add_widget(image)
            return carousel

    Example1().run()


"C:\Users\Chris Kostakis\PycharmProjects\GymButlerClean\venv\Scripts\python.exe" "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\pydevconsole.py" --mode=client --port=56620
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['C:\\Users\\Chris Kostakis\\Projects\\GymButlerClean', 'C:\\Users\\Chris Kostakis\\Projects\\GymButlerClean\\src', 'C:/Users/Chris Kostakis/Projects/GymButlerClean'])
PyDev console: starting.
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
runfile('C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py', wdir='C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix')
[INFO   ] [Logger      ] Record log in C:\Users\Chris Kostakis\.kivy\logs\kivy_19-05-31_86.txt
[INFO   ] [Kivy        ] v1.11.0rc2, git-e828f22, 20190529
[INFO   ] [Kivy        ] Installed at "C:\Users\Chris Kostakis\PycharmProjects\GymButlerClean\venv\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\Chris Kostakis\PycharmProjects\GymButlerClean\venv\Scripts\python.exe"
[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.1.17
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.1.12
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.1.22
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.5.0 - Build 24.20.100.6136'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) Iris(R) Plus Graphics 640'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 5
[INFO   ] [GL          ] Shading version <b'4.50 - Build 24.20.100.6136'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Loader      ] using a thread pool of 2 workers
 Traceback (most recent call last):
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "kivy\properties.pyx", line 1503, in kivy.properties.AliasProperty.trigger_change
   File "kivy\properties.pyx", line 1505, in kivy.properties.AliasProperty.trigger_change
   File "C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py", line 196, in _curr_slide
     return self.slides[self.index]
 TypeError: list indices must be integers or slices, not NoneType
 Exception ignored in: 'kivy.properties.observable_list_dispatch'
 Traceback (most recent call last):
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "kivy\properties.pyx", line 1503, in kivy.properties.AliasProperty.trigger_change
   File "kivy\properties.pyx", line 1505, in kivy.properties.AliasProperty.trigger_change
   File "C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py", line 196, in _curr_slide
     return self.slides[self.index]
 TypeError: list indices must be integers or slices, not NoneType
 Traceback (most recent call last):
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "kivy\properties.pyx", line 1503, in kivy.properties.AliasProperty.trigger_change
   File "kivy\properties.pyx", line 1505, in kivy.properties.AliasProperty.trigger_change
   File "C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py", line 196, in _curr_slide
     return self.slides[self.index]
 TypeError: list indices must be integers or slices, not NoneType
 Exception ignored in: 'kivy.properties.observable_list_dispatch'
 Traceback (most recent call last):
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "kivy\properties.pyx", line 1503, in kivy.properties.AliasProperty.trigger_change
   File "kivy\properties.pyx", line 1505, in kivy.properties.AliasProperty.trigger_change
   File "C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py", line 196, in _curr_slide
     return self.slides[self.index]
 TypeError: list indices must be integers or slices, not NoneType
 Traceback (most recent call last):
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "kivy\properties.pyx", line 1503, in kivy.properties.AliasProperty.trigger_change
   File "kivy\properties.pyx", line 1505, in kivy.properties.AliasProperty.trigger_change
   File "C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py", line 196, in _curr_slide
     return self.slides[self.index]
 TypeError: list indices must be integers or slices, not NoneType
 Exception ignored in: 'kivy.properties.observable_list_dispatch'
 Traceback (most recent call last):
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "kivy\properties.pyx", line 1503, in kivy.properties.AliasProperty.trigger_change
   File "kivy\properties.pyx", line 1505, in kivy.properties.AliasProperty.trigger_change
   File "C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py", line 196, in _curr_slide
     return self.slides[self.index]
 TypeError: list indices must be integers or slices, not NoneType
 Traceback (most recent call last):
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "kivy\properties.pyx", line 1503, in kivy.properties.AliasProperty.trigger_change
   File "kivy\properties.pyx", line 1505, in kivy.properties.AliasProperty.trigger_change
   File "C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py", line 196, in _curr_slide
     return self.slides[self.index]
 TypeError: list indices must be integers or slices, not NoneType
 Exception ignored in: 'kivy.properties.observable_list_dispatch'
 Traceback (most recent call last):
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "kivy\properties.pyx", line 1503, in kivy.properties.AliasProperty.trigger_change
   File "kivy\properties.pyx", line 1505, in kivy.properties.AliasProperty.trigger_change
   File "C:/Users/Chris Kostakis/PycharmProjects/GymButlerClean/venv/Lib/site-packages/kivy/uix/carousel.py", line 196, in _curr_slide
     return self.slides[self.index]
 TypeError: list indices must be integers or slices, not NoneType
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Base        ] Leaving application in progress...
[INFO   ] [WindowSDL   ] exiting mainloop and closing.




Discussion:
https://github.com/kivy/kivy/blob/374802fbeca39f2ca9325677770b655aa2a70290/kivy/uix/carousel.py#L152-L154

`cache=False` fixes the issue. It's probably not a proper way though.
The problem still exist in 1.11.0

Resolving patch:
diff --git a/kivy/uix/carousel.py b/kivy/uix/carousel.py
--- a/kivy/uix/carousel.py
+++ b/kivy/uix/carousel.py
@@ -191,7 +191,7 @@ def _prev_slide(self):
 
     def _curr_slide(self):
         if len(self.slides):
-            return self.slides[self.index]
+            return self.slides[self.index or 0]
 
     current_slide = AliasProperty(_curr_slide,
                                   bind=('slides', 'index'),


Test patch: