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

Scatter – multitouching to drag, rotate, and scale


In the previous chapter you learned how to use events to drag widgets. You learned how to use the on_touch_up, on_touch_move and on_touch_down events. However, the Scatter class already provides that functionality and also lets us scale and rotate using two fingers. All the functionality is included inside the Scatter class, however, we need to apply a few changes to keep our project consistent. In particular, we still want our group mode to work, so that translating, scaling, and rotating can be happening at the same time. Let us implement the changes in four big steps in the comicwidgets.py file:

  1. Substitute in the DraggableWidget base class. Let's use Scatter instead of RelativeLayout (line 122 and 125):

    121. # File name: comicwidgets.py
    122. from kivy.uix.scatter import Scatter
    123. from kivy.graphics import Line
    124. 
    125. class DraggableWidget(Scatter):

    Note

    Both, Scatter and RelativeLayout use relative coordinates.

  2. Make sure that the on_touch_down...