Skip to content

Instantly share code, notes, and snippets.

@tito tito/
Last active Aug 29, 2015

What would you like to do?
Example of mock-MotionEvent for unittest
# subclass for touch event in unit test
class UTMotionEvent(MotionEvent):
def depack(self, args):
self.is_touch = True = args['x'] = args['y']
self.profile = ['pos']
super(UTMotionEvent, self).depack(args)
# then create a touch
touch = UTMotionEvent("unittest", 1, {"x": 0, "y": 0})
# dispatch it manually into kivy
# using post_dispatch_input doesn't pass the touch to any input post-proc
# we don't have the capability to dispatch manually a touch at the beginning
# of the input pipeline, except if you create a touch provider and emit them.
from kivy.base import EventLoop
EventLoop.post_dispatch_input("begin", touch)
# reminder, sx/sy must be size agnostic. So must be between 0-1 range.
touch.move({"x": 0.1, "y": 0})
EventLoop.post_dispatch_input("update", touch)
EventLoop.post_dispatch_input("end", touch)

This comment has been minimized.

Copy link

harmo commented Mar 1, 2015

Very usefull, thanks !

Just a few questions :

  • What are all the event types we can pass in post_dispatch_input function ?
  • How can I do if I want to mouse_touch_down at given coordinates ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.