figuring out when a widget is focusable?

13 views
Skip to first unread message

Bill Janssen

unread,
Sep 27, 2016, 2:57:10 PM9/27/16
to Kivy users support
I have a TextInput I add to an already existing and visible window, a Popup.  I'd like to make it focused when it appears.  How do I do that?  I've tried:

1.  Add it to the already-visible window with add_widget(), then set the "focus" property to True.

2.  Set up a Clock callback in the TextInput's __init__, like this:

     Clock.schedule_once(self.check_connected)

and then

    def check_connected(self, *args):
       
if not self.disabled and self.get_root_window() is not None:
           
self.focus = True
       
else:
           
Clock.schedule_once(self.check_connected)

Neither works.

Bill

Bill Janssen

unread,
Sep 28, 2016, 12:10:09 PM9/28/16
to Kivy users support
What appears to be happening is that the TextInput does get the focus, and then it's removed again.  Is there some way to track which widget has the focus?

Bill

Bill Janssen

unread,
Sep 28, 2016, 12:38:04 PM9/28/16
to Kivy users support
What's going on is that I do the add of the TextInput in response to a button press.  That code is bound to the "on_press" event of the button.  However, it seems that any on_touch_up event, after a widget has received focus, will result in de-focussing it.  So the on_touch_up event of the button will defocus the already-focussed TextInput.  If I add the TextInput in response to the "on_release" event of the button, instead, I can just set the "focus" property directly, as in case (1) below.

This is actually sort of documented under the "ignored_touch" property of FocusBehavior (probably should be "ignored_touches").  Basically, any on_touch_up event will defocus the focussed widget unless that touch is in the "ignored_touch" list.

Bill
Reply all
Reply to author
Forward
0 new messages