kivy: setting suggestion_text crashes if textinput.text is empty string

Example:

import sys

from kivy.app import App
from kivy.uix.textinput import TextInput

class MyApp(App):

    def on_start(self):
        self.root.text = ""
        self.root.bind(text=lambda w, v: sys.stdout.write(v + "\n"))
        self.root.bind(suggestion_text=lambda w, v: sys.stdout.write("suggestion_text changed to: " + v + '\n'))
        self.root.suggestion_text = "foo"

    def build(self):
        return TextInput(readonly=False, multiline=False, focus=True, on_parent=lambda w, x: w.setter("focus")(True))

if __name__ == "__main__":
    MyApp().run()

and the result:

 Traceback (most recent call last):
   File "/tmp/test5.py", line 18, in <module>
     MyApp().run()
   File "/usr/lib/python2.7/site-packages/kivy/app.py", line 827, in run
     self.dispatch('on_start')
   File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7699)
   File "/tmp/test5.py", line 12, in on_start
     self.root.suggestion_text = "foo"
   File "kivy/properties.pyx", line 408, in kivy.properties.Property.__set__ (kivy/properties.c:5114)
   File "kivy/properties.pyx", line 446, in kivy.properties.Property.set (kivy/properties.c:5876)
   File "kivy/properties.pyx", line 501, in kivy.properties.Property.dispatch (kivy/properties.c:6557)
   File "kivy/_event.pyx", line 1224, in kivy._event.EventObservers.dispatch (kivy/_event.c:13497)
   File "kivy/_event.pyx", line 1130, in kivy._event.EventObservers._dispatch (kivy/_event.c:12696)
   File "/usr/lib/python2.7/site-packages/kivy/uix/textinput.py", line 2772, in on_suggestion_text
     txt = self._lines[self.cursor_row]
 IndexError: list index out of range

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 29 (29 by maintainers)

Most upvoted comments

The two are orthogonal; you might very well have suggestion_text even if text is an empty string.

Well, it’s not documented, so users won’t know this. As long as it’s explained, I think that will be fine? Will look into that shortly.

Thanks