Look at the filtering examples: https://kivy.org/doc/stable/api-kivy.uix.textinput.html?highlight=text%20input#module-kivy.uix.textinput
And do the filtering based on length.
I did a filter that does not allow characters that are not allowed in a filename, and puts up a warning message if the name is already in the library the user created:
class ValidFilenameInput(TextInput):
invalid_set = r"/\*:|'.?" + '"<>'
def insert_text(self, substring, from_undo=False):
patch_name = [c for c in substring if c not in self.invalid_set]
s = ''.join(patch_name)
return super().insert_text(s, from_undo=from_undo)
and create a widget in kivy
ValidFilenameInput:
id: patch_name
multiline: False
hint_text: 'Name'
size_hint: (None,None)
size: (400,30)
on_text: input_warning.text = 'Name is Already in Library, Change the Name' if self.text in app.mylib else ''
You could do something similar, but stop returning chars after the first 10 are input.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2a36807f-2fff-40c9-baa7-e8acbcaaaa19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/xTcDcm2eKEE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/20190223165033.VBSL4175.fed1rmfepo202.cox.net%40fed1rmimpo209.cox.net.
I'm glad to hear it helped.
You could simplify your code, something like this should work.
(I have not tested this). You do not need to examine every
character.
def insert_text(self, substring, from_undo=False)
if len(substring) < 10 : # if the length of the substring
is less than 10, return the substring
s = substring
else:
s = substring[0:10] # is the substring length is 10
or greater, only return the first 10 characters
return super().insert_text(s, from_undo=from_undo)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAEZOT5PB_QWZm7QCjwkk2wZh1ewU7gSaUXKk29tA2eiUPXr1rQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/78471846-49da-ebac-771f-50cd2aea047d%40cox.net.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0b0e9a3b-617f-4346-a49b-ac798559b447%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAEZOT5Oe4nU5UqEddt3MQFTB7LLXKZKYDgmm_rn4LYeci2Va8Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CADXYMm6OK9t5HPT0xpBp52gkH%3DZKjHHyV-muMChPuCuVqoA-NA%40mail.gmail.com.