Book Image

Kivy: Interactive Applications in Python

By : Roberto Ulloa
4 (1)
Book Image

Kivy: Interactive Applications in Python

4 (1)
By: Roberto Ulloa

Overview of this book

Mobiles and tablets have brought with them a dramatic change in the utility of applications. Compatibility has become essential, and this has increased the kind of interaction that users expect: gestures, multi-touches, animations, and magic pens. Kivy is an open source Python solution that covers these market needs with an easy-to-learn and rapid development approach. Kivy is growing fast and gaining attention as an alternative to the established developing platforms. Kivy: Interactive Applications in Python quickly introduces you to the Kivy development methodology. You will learn some examples of how to use many of the Kivy components, as well as understand how to integrate and combine them into big projects. This book serves as a reference guide and is organized in such a way that once finished, you will have already completed your first project. You will start by learning the Kivy Language for building User Interfaces (UI) and vector figures. We then proceed to the uses of Kivy events and properties to glue the UI with the application logic. You then go on to build an entire User Interface (UI) starting from a hand-made sketch. Furthermore, you will go on to understand how to use the canvas and drawing instructions to create different types of geometrical figures. Finally, you will be introduced to a big set of interactive and smooth features: transformations (scale, rotate, and translate), gestures, animations, scheduling tasks, and multi-touch elements. Kivy: Interactive Applications in Python expands your knowledge by introducing various components that improve the User Experience (UX). Towards the end of the book, you will be confident to utilize Kivy components and strategies to start any application or game you have in mind.
Table of Contents (13 chapters)
Kivy: Interactive Applications in Python
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Recording gestures – line, circles, and cross


What about drawing with one finger? Can we recognize gestures? It is possible to do this with Kivy, but first we need to record the gestures that we want to use. A gesture is represented as a long string that contains the points of a stroke over the screen. The following code is not part of the project and can be run with python gesturerecorder.py:

170. # File Name: gesturerecorder.py
171. from kivy.app import App
172. from kivy.uix.floatlayout import FloatLayout
173. from kivy.graphics import Line, Ellipse
174. from kivy.gesture import Gesture, GestureDatabase
175. 
176. class GestureRecorder(FloatLayout):
177. 
178.     def on_touch_down(self, touch):
179.         self.points = [touch.pos]
180.         with self.canvas:
181.             Ellipse(pos=(touch.x-5,touch.y-5),size=(10,10))
182.             self.line = Line(points=(touch.x, touch.y))
183. 
184.     def on_touch_move(self, touch):
185.         self.points += [touch.pos]
186.       ...