'Kivy Access Touch Object

I'm new to kivy and I want to access the touch Object without overwriting motion event functions like on_touch_down(self,touch), on_touch_up(), etc..

I want to access touch.pos in order to dynamically draw lines on an Image in a Scatter Class.

Simplified my kv file looks like the following:

<Map@Scatter>:
    source: None
    do_rotation: False
    Image:
        id: main_image
        source: root.parent.parent.parent.parent.map_path
        allow_stretch: True
        keep_ratio: True
        size_hint_y: None
        size_hint_x: None
        width: self.parent.width
        height: self.parent.width/self.image_ratio

<Zoom>:
    id: zoom_class
    Map:
        id: map_class

<RoomMarkerScreen>:
    id: room_marker_screen
    AnchorLayout:
        rows: 2
        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'top'
            Zoom:
                id: zoom_class
        AnchorLayout:
            anchor_x:'center'
            anchor_y: 'bottom'
            Button:
                text: "Fix/Unfix Map"
                size_hint: 0.5, 0.05
                on_press:
                    root.fix_unfix(root.fix)

Knowing that Class Zoom Inherits from FloatLayout, how can I access Touch Object in Zoom?

Thanks in advance!

If I take the touch.pos from the event motion functions, they will be overwritten and I won't be able use the drag and scale features that came with the Scatter Class.



Solution 1:[1]

Whenever you write a function that exists in a super class, you should call that that super class method, otherwise, you will be interfering in the functioning of that super class (for example, DragBehavior). So, I suggest trying something like:

class Zoom(FloatLayout):
     fixed_map = BooleanProperty(False)
     def on_touch_down(self, touch):
         print(touch.pos)
         return super(Zoom, self).on_touch_down(touch)

And returning True from a on_touch_down() method stops all further dispatching of that touch event, so other widgets do not see that event. See the documentation.

Also, from the same documentation:

on_touch_down(), on_touch_move(), on_touch_up() don’t do any sort of collisions. If you want to know if the touch is inside your widget, use collide_point().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Anderson