From 94895cd36139679363e86247a7aaa5b08fc33f77 Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Sat, 22 Feb 2014 23:02:23 -0500 Subject: [PATCH] Add to de-focus on escape. --- kivy/uix/behaviors.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kivy/uix/behaviors.py b/kivy/uix/behaviors.py index a80f089a4..b1812b8b3 100644 --- a/kivy/uix/behaviors.py +++ b/kivy/uix/behaviors.py @@ -422,7 +422,8 @@ class FocusBehavior(object): Focus, very different then selection, is intimately tied with the keyboard; each keyboard can focus on zero or one widgets, and each widget can only have the focus of one keyboard. However, multiple keyboards can focus - simultaneously on different widgets. + simultaneously on different widgets. When escape is hit, the widget having + the focus of that keyboard will de-focus. In essence, focus is implemented as a doubly linked list, where each node holds a (weak) reference to the instance before it and after it, @@ -749,8 +750,16 @@ class FocusBehavior(object): keyboard and will be called for every input release. The parameters are the same as :meth:`kivy.core.window.WindowBase.on_key_up`. + When overwriting the method in the derived widget, super should be + called to enable de-focusing on escape. If the derived widget wishes + to use escape for its own purposes, it can call super at the end after + it is done if it didn't consume escape. + See :meth:`on_key_down` ''' + if keycode[1] == 'escape': + self.focused = False + return True return False def link_focus(self, previous=None, next=None):