From a546c9828c295ab8618112516f1fd6dd89dc8556 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sat, 28 Jul 2012 18:24:01 +0200 Subject: [PATCH] textinput: prevent the bubble to be showed if the textinput is not on the screen anymore (Check is done twice per seconds). --- kivy/uix/textinput.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py index 6b06e6b7e..df19cb6e7 100644 --- a/kivy/uix/textinput.py +++ b/kivy/uix/textinput.py @@ -133,6 +133,24 @@ class TextInputCutCopyPaste(Bubble): textinput = ObjectProperty(None) + def __init__(self, **kwargs): + super(TextInputCutCopyPaste, self).__init__(**kwargs) + Clock.schedule_interval(self._check_parent, .5) + + def _check_parent(self, dt): + # this is a prevention to get the Bubble staying on the screen, if the + # attached textinput is not on the screen anymore. + parent = self.textinput + while parent is not None: + if parent == parent.parent: + break + parent = parent.parent + if parent is None: + Clock.unschedule(self._check_parent) + if self.textinput: + self.textinput._hide_cut_copy_paste() + + def do(self, action): textinput = self.textinput @@ -618,7 +636,10 @@ class TextInput(Widget): self._hide_cut_copy_paste(win) return True - def _hide_cut_copy_paste(self, win): + def _hide_cut_copy_paste(self, win=None): + win = win or self._win + if win is None: + return bubble = self._bubble if bubble is not None: win.remove_widget(bubble)