Last active
August 29, 2015 14:16
-
-
Save tito/f111b6916aa6a4ed0851 to your computer and use it in GitHub Desktop.
Example of mock-MotionEvent for unittest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# subclass for touch event in unit test | |
class UTMotionEvent(MotionEvent): | |
def depack(self, args): | |
self.is_touch = True | |
self.sx = args['x'] | |
self.sy = 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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very usefull, thanks !
Just a few questions :