focus TextInput changes on '.' pressed

35 views
Skip to first unread message

Andrei Sima

unread,
Aug 25, 2015, 7:13:35 AM8/25/15
to Kivy users support
Hi,

I have read the docs for FocusBehavior, that i understand TextInput inherits. I got lost, and now i need your help

As per fact i have 5 TextInput widgets

TextInput:
    id: IPValue1
    write_tab: False
    multiline: False
    on_text: root.nextondot(args)

TextInput:
    id: IPValue2
    write_tab: False
    multiline: False
    on_text: root.nextondot(args)
.....

TextInput:
    id: SVport5
    write_tab: False
    multiline: False
    on_text: root.nextondot(args)

and in python

class MainView(Widget):
next = ObjectProperty()

def __init__(self, **kwargs):
super (MainView, self).__init__(**kwargs)

def nextondot(self,args):
self.myData = args[1] 
if len(self.myData)>0:
if self.myData [-1:]=='.':
print '. detected'
                                # need to focus the next TextInput
                                # TODO > check for ":" for the port value (might focus port value text input when : detected) 
                                # TODO IP info port can be validated by button or ENTER ---- TBD

else:

print 'no text input -> nothing to do here -> grab beer '

Now i want to be able to focus the next text widget when the user presses ".". I am asking for an IP and a PORT for a server. I want the user to be able to 
192. <- here i want the next text input to be focused 168. <- here i want the next text input to be focused etc. 

I am removing the dot from text input text and adding it back latter in the code at the final IPPort string.

Thank You

ZenCODE

unread,
Aug 25, 2015, 5:22:14 PM8/25/15
to Kivy users support
How does this work for you?

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App

Builder.load_string('''
<MainView>:
    orientation: '
horizontal'
    TextInput:
        focus: True
        id: t1

        write_tab: False
        multiline: False
        on_text: root.nextondot(args)
        focus_next: t2

    TextInput:
        id: t2
        focus_next: t3

        write_tab: False
        multiline: False
        on_text: root.nextondot(args)
   
    TextInput:
        id: t3
        focus_next: t1

        write_tab: False
        multiline: False
        on_text: root.nextondot(args)
''')


class MainView(BoxLayout):

   
def nextondot(self, args):
        data
= args[1]
       
if len(data) > 0:
           
# if data [-1:] == '.':  # Still allows them to insert dots in the
           
# middle.
           
if data.find('.') > 0:
                args
[0].text = data.replace('.', '')
                args
[0].focus_next.focus = True

class MainApp(App):
   
def build(self):
       
return MainView()

MainApp().run()


Andrei Sima

unread,
Aug 25, 2015, 5:57:52 PM8/25/15
to kivy-...@googlegroups.com
THANK YOU.

Your example works like a charm. I will go deep into:

args[0].text = data.replace('.', '')
args
[0].focus_next.focus = True

to see what are they doing behind the scene.

But (there always must be a but dammit).

Run the code and press dot as a firs char. :) And press it again :) and so on

PLS. do not post solution to that. I will try to fix it. I want to learn not to ask for somebody to do my stuff. 
I will post solution as soon as it is finished.

Thank you very much for your support.

____________________
Andrei Sima
0723.223.883

--
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.
For more options, visit https://groups.google.com/d/optout.

ZenCODE

unread,
Aug 26, 2015, 2:13:54 AM8/26/15
to Kivy users support
:-) One bug Line 39 should be

            if data.find('.') > -1:

not


            if data.find('.') > 0:

because that allows users to press "." as the first character and nothing will happen. After all these years of programming, I still make "fencepost" errors. <Groan> At least it keeps us humble...

Good luck, it's a pleasure, and please do post back :-)
Reply all
Reply to author
Forward
0 new messages