Share a minimal executable program.
You need to use collide_point() in your touch routines.
Looks like you have a number of overlapping widgets. Can you arrange them so they do not overlap, that you can distinguish the touch by position or mode?
From: purushottam yadav
Sent: Saturday, January 2, 2021 7:55 PM
To: Kivy users support
Subject: [kivy-users] controlling swipe in carousel
I have a carousel (1) , one of its slide have scroll view and inside this scroll view , I want to add another carousel (2) to swipe images and other widgets of same width .
But here the problem is when I swipe the images , first carousel (1) is responding immediately and to swipe the second carousel , I need to swipe slowly observing the moment of images and first carousel slide .
what I want to implement is
1) when i put finger on second carousel t o swipe images , first one should not respond ,
and should only respond when swiping over other widgets in the scrollview .
I tried to implement it by locking the swipe carousel (1)
when on_touch_down( ) and unlock when on_touch_up( ) .But this is not working , it is miss behaving .
class Car_2( Carousel):
"secound carousel to swipe images "
def on_touch_down(self , touch) :
k.help_str.get_screen('hello').ids.tabs.lock_swiping=True
print("down down down ============================================================")
def on_touch_up(self , touch):
k.help_str.get_screen('hello').ids.tabs.lock_swiping=False
print(touch.spos , touch.pos )
print("up up up ========================================================================")
image is provided to describe the situation , please help me out .
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bf6e8926-2bff-4b25-8b84-03298ca5fc04n%40googlegroups.com.
Please refer to my previous post to you about collide point and how the on_touch methods work.
Let me know if you have any questions on that content.
Here is a simple example using the on_touch_down method and collide_point to illustrate how it works. Touch the label at the top of the screen, and each carousel and see what prints to the console.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.carousel import Carousel
from kivy.properties import StringProperty
kv = '''
<TouchCarousel>:
loop: True
Button:
text: root.name + ' One'
Button:
text: root.name + ' Two'
Button:
text: root.name + ' Three'
BoxLayout:
orientation: 'vertical'
Label:
text: 'Touch the Screen Here'
BoxLayout:
spacing: 10
TouchCarousel:
name: 'Car1'
TouchCarousel:
name: 'Car2'
'''
class TouchCarousel(Carousel):
name = StringProperty()
def on_touch_down(self, touch):
print(f'Screen touched at {touch.pos}') # This will print on any screen touch
if self.collide_point(*touch.pos): # Tests, was this widget touched?
print(f'{self.name} pressed at {touch.pos}')
return super().on_touch_down(touch) # Pass the touch to the parent class
else:
print(f'{self.name} not Touched') # I was not touched
return False
class NewProjectApp(App):
def build(self):
return Builder.load_string(kv)
NewProjectApp().run()
when on_touch_down( ) and unlock when on_touch_up( ) .But this is not working , it is miss behaving .
class Car_2( Carousel):"secound carousel to swipe images "
def on_touch_down(self , touch) :
k.help_str.get_screen('hello').ids.tabs.lock_swiping=True
print("down down down ============================================================")
def on_touch_up(self , touch):
k.help_str.get_screen('hello').ids.tabs.lock_swiping=False
print(touch.spos , touch.pos )
print("up up up ========================================================================")
image is provided to describe the situation , please help me out .
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bf6e8926-2bff-4b25-8b84-03298ca5fc04n%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/391403f4-9347-4967-9561-1dd0a4131a1fn%40googlegroups.com.
My suggestions:
Start with a simple example that isolates your issue.
An important concept to understand, the touches will ‘bubble’ to all widgets.
For the tab write a set of on_touch_methods that returns True if the area touched is covered by the Carousel on the tab.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b22e3944-3fa1-4d63-8fb9-92f3d9e28b41n%40googlegroups.com.
Here are some references on the on_touch events.
See: https://kivy.org/doc/stable-1.11.1/api-kivy.uix.widget.html?highlight=widget#module-kivy.uix.widget
Often you want to know if a certain point is within the bounds of your widget. An example would be a button widget where you only want to trigger an action when the button itself is actually touched. For this, you can use the collide_point() method, which will return True if the point you pass to it is inside the axis-aligned bounding box defined by the widget’s position and size.
See the example on the bottom of this page: https://kivy.org/doc/stable-1.11.1/gettingstarted/events.html
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d01eebba-aa2c-48f8-bb1f-1d01afee4b6fn%40googlegroups.com.
Do an experiment, replace the call to super() with just returning True. What happens?
The Carousel will not work. It will no longer swipe – it is not receiving the on_touch_down events.
The line that calls the super().on_touch_down() is passing the touch to the parent, the Carousel.
From: https://kivy.org/doc/stable/gettingstarted/events.html
Another thing to note is that if you override an event, you become responsible for implementing all its behaviour previously handled by the base class. The easiest way to do this is to call super():
def on_touch_down(self, touch):
if super(OurClassName, self).on_touch_down(touch):
return True
if not self.collide_point(touch.x, touch.y):
return False
print('you touched me!')
return True
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e7e265c9-5cd7-4973-b3ac-2ed26e148170n%40googlegroups.com.