Skip to content

Instantly share code, notes, and snippets.

@Bakterija
Created June 1, 2017 01:27
Show Gist options
  • Save Bakterija/ccc7ec6e2afe148c6b1bb4b80ccdae2a to your computer and use it in GitHub Desktop.
Save Bakterija/ccc7ec6e2afe148c6b1bb4b80ccdae2a to your computer and use it in GitHub Desktop.
Quickly selectable textinput inside scrollview when widget is focused
# The ScrollView widget
from kivy.uix.scrollview import ScrollView
class ScrollView2(ScrollView):
dont_do_scrolling = False
def on_touch_down(self, touch):
if self.dont_do_scrolling:
self.simulate_touch_down(touch)
return True
elif self.dispatch('on_scroll_start', touch):
self._touch = touch
touch.grab(self)
return True
# And the TextInput widget
from kivy.properties import ObjectProperty
from kivy.uix.textinput import TextInput
from kivy.base import EventLoop
from time import time
class TextInput2(TextInput):
scroller = ObjectProperty()
def on_scroller(self, _, value):
if value:
value.bind(on_touch_down=self.testmethod)
def testmethod(self, _, touch):
if self.focus:
x, y = self.to_widget(touch.x, touch.y)
if self.collide_point(x, y):
self.scroller.dont_do_scrolling = True
def on_touch_up(self, touch):
if self.scroller:
if self.scroller.dont_do_scrolling:
self.scroller.dont_do_scrolling = False
return super(TextInput2, self).on_touch_up(touch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment