From f6018fd30121178e515b75754fbf4f72cba4232d Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Mon, 25 Aug 2014 11:11:17 -0400 Subject: [PATCH] Rename _processed_touches to ignored_touch and use it in textinput's bubble/selectors. --- kivy/uix/behaviors.py | 22 +++++++++++++++++++--- kivy/uix/textinput.py | 6 ++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/kivy/uix/behaviors.py b/kivy/uix/behaviors.py index 21746cb3e..2b731f89d 100644 --- a/kivy/uix/behaviors.py +++ b/kivy/uix/behaviors.py @@ -498,7 +498,23 @@ class FocusBehavior(object): _requested_keyboard = False _keyboard = ObjectProperty(None, allownone=True) _keyboards = {} - _processed_touches = [] + + ignored_touch = [] + '''A list of touches that should not be used to defocus. After on_touch_up, + every touch that is not in :attr:`ignored_touch` will defocus all the + focused widgets, if, the config keyboard mode is not multi. Touches on + focusable widgets that were used to focus are automatically added here. + + Example usage: + + class Unfocusable(Widget): + + def on_touch_down(self, touch): + if self.collide_point(*touch.pos): + FocusBehavior.ignored_touch.append(touch) + + Notice that you need to access this as class, not instance variable. + ''' def _set_keyboard(self, value): focused = self.focused @@ -796,14 +812,14 @@ class FocusBehavior(object): ('button' not in touch.profile or not touch.button.startswith('scroll'))): self.focused = True - FocusBehavior._processed_touches.append(touch) + FocusBehavior.ignored_touch.append(touch) return False @staticmethod def _handle_post_on_touch_up(touch): ''' Called by window after each touch has finished. ''' - touches = FocusBehavior._processed_touches + touches = FocusBehavior.ignored_touch if touch in touches: touches.remove(touch) return diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py index 64ebfdda0..166a842d9 100644 --- a/kivy/uix/textinput.py +++ b/kivy/uix/textinput.py @@ -222,6 +222,8 @@ class Selector(ButtonBehavior, Image): touch.push() touch.apply_transform_2d(self.to_widget) self._touch_diff = self.top - touch.y + if self.collide_point(*touch.pos): + FocusBehavior.ignored_touch.append(touch) return super(Selector, self).on_touch_down(touch) finally: touch.pop() @@ -245,6 +247,10 @@ class TextInputCutCopyPaste(Bubble): super(TextInputCutCopyPaste, self).__init__(**kwargs) Clock.schedule_interval(self._check_parent, .5) + def on_touch_down(self, touch): + if self.collide_point(*touch.pos): + FocusBehavior.ignored_touch.append(touch) + def on_textinput(self, instance, value): global Clipboard if value and not Clipboard and not _is_desktop: