Intercept keyboard request

44 views
Skip to first unread message

Ian Collins

unread,
Apr 22, 2016, 7:59:42 PM4/22/16
to Kivy users support
Hi,
Is it possible, in a textinput, to intercept the event that requests to open the keyboard?
And either cancel the open request or continue opening the keyboard?

Thanks,
Ian

ZenCODE

unread,
Apr 23, 2016, 12:53:44 PM4/23/16
to Kivy users support
As far as I remember, you can do this by sub-classing and overriding the 'on_focus' event. If you don't want to display the keyboard, return True. If you do, call the super method for it. That should do it? Shout if that's too obscure or does not work :-)

Peace
Message has been deleted

Ian Collins

unread,
Apr 24, 2016, 3:48:17 AM4/24/16
to Kivy users support
Hi, Thanks for the suggestion. What bits am I missing in the following....
 
class BTextInput(TextInput):
def __init__(self, **kwargs):
super(BTextInput, self).__init__(**kwargs)
              # whats the syntax to bind the focus event ? (if thats what I need to do).

       def on_focus(self, value)
            # do I just return true or false depending on my needs
            return ???


Cheers, Ian

ZenCODE

unread,
Apr 24, 2016, 6:36:16 AM4/24/16
to Kivy users support
Correct. Returning True will stop the event bubbling and it will never reach the TextInput, otherwise

    return super(BTextInput, self).on_focus(value)

will bubble the event as normal.

bagpuss

unread,
Apr 24, 2016, 4:58:31 PM4/24/16
to kivy-...@googlegroups.com
When I run my app - clicking on that textinput gives...

   File "C:\cygwin64\home\ian.collins\Kivy-1.9.0-py2.7-win32-x64\kivy27\kivy\uix\textinput.py", line 1047, in on_touch_down
     if super(TextInput, self).on_touch_down(touch):
   File "C:\cygwin64\home\ian.collins\Kivy-1.9.0-py2.7-win32-x64\kivy27\kivy\uix\behaviors.py", line 843, in on_touch_down
     self.focus = True
   File "kivy\properties.pyx", line 397, in kivy.properties.Property.__set__ (kivy\properties.c:4680)
   File "kivy\properties.pyx", line 429, in kivy.properties.Property.set (kivy\properties.c:5203)
   File "kivy\properties.pyx", line 484, in kivy.properties.Property.dispatch (kivy\properties.c:5852)
   File "kivy\_event.pyx", line 1168, in kivy._event.EventObservers.dispatch (kivy\_event.c:12154)
   File "kivy\_event.pyx", line 1074, in kivy._event.EventObservers._dispatch (kivy\_event.c:11451)
 TypeError: on_focus() takes exactly 2 arguments (3 given)

Process finished with exit code -1

Thats with...

def on_focus(self, value):
if value:
Logger.debug('CRV: ti focused')
else:
Logger.debug('CRV: ti DEfocused')
super(BTextInput, self).on_focus(value)

and,
self.bind(focus=self.on_focus)

???
Regards, Ian.


Regards,
Ian Collins



--
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/aUxtfDub0Ps/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

ZenCODE

unread,
Apr 24, 2016, 5:40:25 PM4/24/16
to Kivy users support
Try

def on_focus(self, widget, value):


    if value:
        Logger.debug('CRV: ti focused')
    else:
        Logger.debug('CRV: ti DEfocused')
    return super(BTextInput, self).on_focus(widget, value)

bagpuss

unread,
Apr 24, 2016, 9:47:20 PM4/24/16
to kivy-...@googlegroups.com
Hi,
Can you explain the error I now get - after adding in your previous suggestion - which I should have guessed :-)  .... (bold below)...

File "kivy\properties.pyx", line 484, in kivy.properties.Property.dispatch (kivy\properties.c:5852)
   File "kivy\_event.pyx", line 1168, in kivy._event.EventObservers.dispatch (kivy\_event.c:12154)
   File "kivy\_event.pyx", line 1074, in kivy._event.EventObservers._dispatch (kivy\_event.c:11451)
   File "C:/cygwin64/home/ian.collins/Kivy-1.9.0-py2.7-win32-x64/crv/main.py", line 1030, in on_focus
     super(BTextInput, self).on_focus(widget, value)
 AttributeError: 'super' object has no attribute 'on_focus'
libpng warning: iCCP: known incorrect sRGB profile

BTextInput is defined.... class BTextInput(TextInput):

Regards, Ian

Regards,
Ian Collins



--

ZenCODE

unread,
Apr 25, 2016, 9:55:19 AM4/25/16
to Kivy users support
Okay, the 'on_focus' event is dynamically added via the 'focus' behaviour, so using super won't work as it's not. properly speaking, an inherited method...Hmmm...

You could try setting the 'readonly' property to True? Also experiment with the 'on_enter' event, as that might be a better place to set the 'readonly' property that the 'on_focus' event.

Otherwise, you could override the '_ensure_keyboard' method to prevent the keyboard request, but that's beginning to get a bit messy.

    def _ensure_keyboard(self):
        if booNoKeyboard:
            pass
        else:
            return super(BTextInput, self)._ensure_keyboard()

Reply all
Reply to author
Forward
0 new messages