Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi Touch event issue in kivy #5295

Closed
susheel-selvamani opened this issue Jul 21, 2017 · 6 comments
Closed

Multi Touch event issue in kivy #5295

susheel-selvamani opened this issue Jul 21, 2017 · 6 comments
Labels
awaiting-reply Waiting for reply from issue opener, will be closed if no reply

Comments

@susheel-selvamani
Copy link

susheel-selvamani commented Jul 21, 2017

Hi,

Actually I'm working on an application in kivy and the main part is using 2 sliders that are able to reset to its initial state when released.

ISSUE here is: Both the sliders are being used .,when one is released, the other one is also going back to its initial state. is there any way to overcome this??

@KeyWeeUsr
Copy link
Contributor

Unless there's a reproducible example, the issue is most likely in your code. Therefore please read again the issue template and submit the appropriate stuff otherwise it's only about guessing.

@KeyWeeUsr KeyWeeUsr added the awaiting-reply Waiting for reply from issue opener, will be closed if no reply label Jul 21, 2017
@susheel-selvamani
Copy link
Author

susheel-selvamani commented Jul 21, 2017

this is the code i used, please look into it., so how do I manage two sliders ?


Kivy Example App for the slider widget

from kivy.app import App

 

from kivy.uix.gridlayout import GridLayout

from kivy.uix.slider import Slider

from kivy.uix.button import Button

from kivy.uix.label import Label

from kivy.properties  import (NumericProperty, AliasProperty, OptionProperty,
                             ReferenceListProperty, BoundedNumericProperty,
                             StringProperty, ListProperty, BooleanProperty)

 

 

class WidgetContainer(GridLayout):

   

    def __init__(self, **kwargs):

        super(WidgetContainer, self).__init__(**kwargs)
 

        # 2 columns in grid layout

        self.cols = 4

        self.velocity = Slider(min=-100, max =100, value=0, orientation = 'vertical',
                               value_track_width = '3dp',value_track=True, cursor_width = '36sp', cursor_height = '36sp')

        self.steering = Slider(min=-100, max=100, value=0)




        #3rd

        self.add_widget(Label(text='position'))

        self.angle = Label(text='0')
     
        self.add_widget(self.angle)
       
        #angle bind

        self.steering.bind(value=self.valu)




        # 4th 

        self.add_widget(Label(text='speed'))

        self.speed = Label(text='0')

        self.add_widget(self.speed)

        self.velocity.bind(value=self.val)

    
        
        self.add_widget(Label(text='steering'))

        self.add_widget(self.steering)




         

        self.add_widget(Label(text='acceleration'))

        self.add_widget(self.velocity)


        
    def val(self, instance, speed):

        self.speed.text = "%d"%speed


    def valu(self, instance, angle):

        self.angle.text = "%d"%angle

    def on_touch_up(self, touch):

  
                self.clear_widgets()

                self.__init__()
           

            # touch is on the button...do not want to send this event any further

                return False

        
                   
  # The app class

class SliderExample(App):

    def build(self):

        widgetContainer = WidgetContainer()

        
        return widgetContainer

        

 

# Run the app       

if __name__ == '__main__':

    SliderExample().run()

@KeyWeeUsr
Copy link
Contributor

KeyWeeUsr commented Jul 22, 2017

class WidgetContainer(GridLayout):
    # Sliders spawned in __init__()
    def on_touch_up(self, touch):  # this, bad!
        self.clear_widgets()
        self.__init__()

What you basically did is that you removed the sliders and added new ones on each time a touch from the GridLayout is released. It's definitely a bad on_touch_up placement, because you should handle it in the Slider class, or better said in your own class that inherits from Slider.

There's nothing wrong with multitouch, only you choose a very bad method of resetting two widgets via removing the whole parent's content instead of editing the widget's behavior only.

@susheel-selvamani
Copy link
Author

can u suggest a best way for it?

@KeyWeeUsr
Copy link
Contributor

I already did. Reset the touch in the widget instance only, not in its parent. For example:

class MySlider(Slider):
    def on_touch_up(self, touch):
        # do stuff here

e.g. self.value = 0 or something else, depending on your needs. See MotionEvent.grab.

@susheel-selvamani
Copy link
Author

susheel-selvamani commented Jul 22, 2017

okay i think i almost did, yet I'm facing a new problem !!
I used touch events to control the two sliders as ,

def on_touch_down(self,touch):

    touch.grab(self)
    
    self.steering.value_pos = touch.pos

    self.velocity.value.pos = touch.pos

def on_touch_move(self,touch):

    print (touch.pos)

    if touch.grab_current == self:

        self.steering.value_pos = touch.pos

        self.velocity.value.pos = touch.pos

def on_touch_up(self, touch):

    if touch.grab_current == self:
    
        self.velocity.value = "0"

        self.steering.value = "0"

the touch event is affecting both the sliders..
how i limit it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-reply Waiting for reply from issue opener, will be closed if no reply
Projects
None yet
Development

No branches or pull requests

2 participants