Book Image

Kivy Cookbook

By : Hugo Solis
Book Image

Kivy Cookbook

By: Hugo Solis

Overview of this book

Table of Contents (16 chapters)
Kivy Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Recording gestures


A gesture is a particular succession of touches, which we will give some special significance to. Kivy eases the way to handle gestures.

Getting ready

In this recipe, we will use some predefined graphics in the Kivy framework just to highlight the gesture, and you do not need any further knowledge about it. Also, we have a predefined gesture that is provided in this recipe to you.

How to do it…

In this recipe, we have the next steps:

  1. Call the gesture database.

  2. Make a method to categorize the gesture.

  3. Set a marker for the initial touch.

  4. Record the touch.

  5. Do the comparison with the predefined gesture.

  6. Print the result:

    from kivy.app import App
    
    from kivy.uix.widget import Widget
    from kivy.uix.button import Button
    from kivy.graphics import Color, Ellipse, Line
    from kivy.gesture import Gesture, GestureDatabase
    
    gdb = GestureDatabase()
    
    check =\ gdb.str_to_gesture('eNq1l0tuI0cMhvd9EXsTofgmL6BsA/gAgcYWb\GMmtmBpksztwyY1kgZI0rNpbdr+u+pjkX+9+v718+uf3zbP++Pp68d++v\X8PIzp/ukA08Pd2+6P/d10wPwzHzQdH...