Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Kivy Cookbook
Kivy Cookbook
Kivy Cookbook
Ebook674 pages2 hours

Kivy Cookbook

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Enhance your skills in developing multi-touch applications with Kivy

About This Book
  • Create most diverse apps and learn how to distribute them with the help of the Kivy framework
  • Explore Kivy API to develop user interfaces and control multi-touch events
  • Step-by-step recipes that provide deeper understanding of the Kivy 1.9.0 framework
  • Build and use your own events, widgets and gestures using features and tools in Kivy
Who This Book Is For

This book is intended for developers who want to use features of the Kivy framework and develop multi-touch applications. Prior experience with Kivy is not required, although familiarity with Python is expected.

What You Will Learn
  • Access widgets defined inside Kv language in your Python code
  • Handle Kivy events to control widgets, touches, the mouse, the keyboard, and animations
  • Recognize touch shapes and detecting multi-tapping
  • Create custom events and declare properties
  • Organizing your layouts while working with the ActionBar
  • Store and retrieve the coordinate space context
  • Create your own shader and render in a framebuffer
  • Leverage Factory objects, multi-touch in iOS and multi-touch in Android
In Detail

Kivy is an open-source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. It is a promising Python framework to develop UI and UX apps in a cross-platform environment, under the Python philosophy.

Kivy Cookbook is a practical book that will guide you through the Kivy framework to develop apps and get your apps ready for distribution in App Store and Android devices.

You will start off with installing Kivy and building your interfaces. You will learn how to work the accelerometer and create custom events. Then, you will understand how to use the basics, buttons, labels and text inputs and manipulate the widget tree. Next, you will be able to work with manipulating instructions, create an atlas and layouts. Moving on, you will learn packing for Windows and packing for iOS, and use TestDrive.

By the end of the book, you will have learnt in detail the relevant features and tools in Kivy and how to create portable packages to distribute your apps in the most used platforms.

Style and approach

This is an easy-to-follow practical guide packed with graspable recipes that cover important tasks to be performed while developing multi-touch applications with Kivy. All the code used in each recipe is explained in detail.

LanguageEnglish
Release dateAug 21, 2015
ISBN9781783987399
Kivy Cookbook
Author

Hugo Solis

Hugo Solis is an assistant professor in the physics department at the University of Costa Rica. In the same institution, he collaborates with CITIC and CICIMA. His current research interests include computational cosmology, complexity, and the influence of hydrogen on material properties. He has wide experience in languages, including C/C++ and Python for scientific programming and visualization. He is a member of the Free Software Foundation and has contributed code to some free software projects. He has also been a technical reviewer for Mastering Object-oriented Python, Kivy: Interactive Applications in Python, and Learning Object-Oriented Programming by Packt Publishing. Currently, he is in charge of the IFT, a Costa Rican scientific nonprofit organization for the multidisciplinary practice of physics (http://iftucr.org).

Related to Kivy Cookbook

Related ebooks

Programming For You

View More

Related articles

Reviews for Kivy Cookbook

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Kivy Cookbook - Hugo Solis

    Table of Contents

    Kivy Cookbook

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    Why Subscribe?

    Free Access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Sections

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. Kivy and the Kv Language

    Introduction

    Installing Kivy

    Getting ready

    How to do it…

    How it works…

    There's more…

    Mac OS X

    Microsoft Windows

    See also

    Building your interfaces

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Declaring properties within a class

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Relating Python code and the Kv language

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Referencing widgets

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Accessing widgets defined inside the Kv language in your Python code

    Getting ready

    How to do it…

    How it works…

    See also

    Reusing styles in multiple widgets

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Designing with the Kv language

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Running your code

    Getting ready

    How to do it…

    How it works…

    There's more…

    Mac OS X

    Microsoft Windows

    See also

    Using Kivy garden

    Getting ready

    How to do it…

    There's more…

    Packing

    2. Input, Motion, and Touch

    Introduction

    Using the mouse

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Evolving to the touchscreen

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Working with the accelerometer

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Using the gyroscope

    Getting ready

    How to do it…

    How it works…

    See also

    The differences between the touch and motion events

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Recognizing touch shapes

    Getting ready

    How to do it…

    How it works…

    See also

    Detecting multitapping

    Getting ready

    How to do it…

    How it works…

    Grabbing touch events

    Getting ready

    How to do it…

    How it works…

    Recording gestures

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    3. Events

    Introduction

    Scheduling a one-time event

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Scheduling a repetitive event

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Triggering events

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Defining widget events

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Creating custom events

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Attaching callbacks

    Getting ready

    How to do it…

    How it works…

    See also

    Declaring a property

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Compounding properties

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    4. Widgets

    Introduction

    Using the basics: buttons, labels, and text inputs

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Manipulating the widget tree

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Traversing the tree

    Getting ready

    How to do it…

    How it works…

    Using swappable widgets

    Getting ready

    How to do it…

    How it works…

    See also

    Organizing with layouts

    Getting ready

    How to do it…

    How it works…

    There's more…

    Using FloatLayout

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Using BoxLayout

    Getting ready

    How to do it…

    How it works…

    There's more…

    Using GridLayout

    How to do it…

    How it works…

    There's more…

    Using StackLayout

    Getting ready

    How to do it…

    How it works…

    There's more…

    Using RelativeLayout

    Getting ready

    How to do it…

    How it works…

    Using AnchorLayout

    How to do it…

    How it works…

    Working with ActionBar

    Getting ready

    How to do it…

    How it works…

    See also

    5. Graphics – Canvas and Instructions

    Introduction

    Separating with the screen manager

    Getting ready

    How to do it…

    How it works…

    There's more…

    Using drawing instructions

    Getting ready

    How to do it…

    How it works…

    There's more…

    Using context instructions

    Getting ready

    How to do it…

    How it works…

    There's more…

    Working with manipulating instructions

    Getting ready

    How to do it…

    How it works…

    There's more…

    Rotating, translating, and scaling the canvas

    Getting ready

    How to do it…

    How it works…

    There's more…

    Modifying with multitouching

    Getting ready

    How to do it…

    How it works…

    There's more…

    Storing and retrieving the coordinate space context

    Getting ready

    How to do it…

    Introducing animations

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    6. Advanced Graphics – Shaders and Rendering

    Introduction

    Using Carousel

    Getting ready

    How to do it…

    How it works…

    There's more…

    Creating and using Atlas

    Getting ready

    How to do it…

    How it works…

    Creating layouts

    Getting ready

    How to do it…

    How it works…

    Editing shaders

    Getting ready

    How to do it…

    How it works…

    There's more…

    Creating widgets

    Getting ready

    How to do it…

    How it works…

    See also

    Creating your own shader

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Rendering in a Framebuffer

    Getting ready

    How to do it…

    How it works…

    Optimizing graphics

    Getting ready

    How to do it…

    There's more…

    See also

    7. The API in Detail

    Introduction

    Getting to know the API

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Using the asynchronous data loader

    Getting ready

    How to do it…

    How it works…

    There's more…

    Logging objects

    How to do it…

    How it works…

    There's more…

    See also

    Parsing

    How to do it…

    How it works…

    See also

    Applying utils

    How to do it…

    How it works…

    See also

    Leveraging the factory object

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Working with audio

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Working with video

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Working with a camera

    Getting ready

    How to do it…

    There's more…

    Using spelling

    Getting ready

    How to do it…

    How it works…

    Adding effects

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Advanced text manipulation

    How to do it…

    How it works…

    There's more…

    See also

    8. Packaging our Apps for PC

    Introduction

    Packaging for Windows

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Including multimedia for Windows

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Running apps in Windows

    Getting ready

    How to do it…

    How it works…

    See also

    Packaging for Mac OS

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Including multimedia for Mac OS

    Getting ready

    How to do it…

    How it works…

    There's more…

    Running apps in Mac OS

    Getting ready

    How to do it…

    How it works…

    See also

    Packaging for Linux

    Getting ready

    How to do it…

    Including multimedia for Linux

    Getting ready

    How to do it…

    Running apps in Linux

    Getting ready

    How to do it…

    How it works…

    9. Kivy for Mobile Devices

    Introduction

    Packaging for iOS

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Resizing the screen into iOS

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Leveraging mobile features in iOS

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Preparing for the App Store

    Getting ready

    How to do it…

    How it works…

    See also

    Packaging for Android

    Getting ready

    How to do it…

    How it works…

    See also

    Resizing the screen into Android

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Leveraging mobile features in Android

    Getting ready

    How to do it…

    How it works…

    There's more…

    See also

    Index

    Kivy Cookbook


    Kivy Cookbook

    Copyright © 2015 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: August 2015

    Production reference: 1170815

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78398-738-2

    www.packtpub.com

    Credits

    Author

    Hugo Solis

    Reviewers

    Davide Depau

    Abhinav Jangda

    Matt Lebrun

    Patrick Louis

    Commissioning Editor

    Usha Iyer

    Acquisition Editor

    Richard Gall

    Content Development Editor

    Mamata Walkar

    Technical Editor

    Tejaswita Karvir

    Copy Editor

    Dipti Mankame

    Project Coordinator

    Shipra Chawhan

    Proofreader

    Safis Editing

    Indexer

    Priya Sane

    Graphics

    Sheetal Aute

    Production Coordinator

    Shantanu N. Zagade

    Cover Work

    Shantanu N. Zagade

    About the Author

    Hugo Solis is an assistant professor in the physics department at the University of Costa Rica. In the same institution, he collaborates with CITIC and CICIMA. His current research interests include computational cosmology, complexity, and the influence of hydrogen on material properties. He has wide experience in languages, including C/C++ and Python for scientific programming and visualization. He is a member of the Free Software Foundation and has contributed code to some free software projects. He has also been a technical reviewer for Mastering Object-oriented Python, Kivy: Interactive Applications in Python, and Learning Object-Oriented Programming by Packt Publishing. Currently, he is in charge of the IFT, a Costa Rican scientific nonprofit organization for the multidisciplinary practice of physics (http://iftucr.org).

    I would like to thank God for this life and all his blessings. One of those blessings is my beloved mother, Katty Sanchez, whom I have to thank for her support and vanguard thoughts.

    I am grateful to my amazing friends Laura Rojas, Jose David Cojal, Gerardo Lacy, Allan Lacy, Pamela Saborio, and Ana Segura for sharing this long ride in the life with me.

    A special thanks to my professors, colleagues, and friends—Manuel Ortega, Daniel Azofeifa, Neville Clark, William Vargas, Max Chaves, and Gabriela Barrantes—and MICITT and CONICIT for supporting my PhD studies.

    I would also like to thank my brothers, Harry and Geancarlo, for enduring a geek brother, and Helena Oses for her endearment and unique words.

    I owe the most to all the people behind Kivy, Python, and Packt Publishing. Thank you.

    About the Reviewers

    Abhinav Jangda has a deep interest in the field of application development. He is an open source enthusiast. He has contributed to open source projects, including Kivy and GNOME. He was one of the main contributors to the development of Kivy designer. He has been using Kivy as his primary application development framework. Besides Python, he has developed applications in C, C++, Java, and C# using some framework, such as GTK+, Qt, Java SWT, and Windows Presentation Foundation. He has been researching in the fields of operating systems, compilers, and virtual machines. He loves working with Linux and developing applications for it.

    Matt Lebrun is a software engineer from the Philippines. He recalls his first dibs in programming using QBasic when he was 13, and since then, he's only gone deeper into this sleep-depriving yet overly rewarding field.

    After college education, he started his career customizing in-house and commercial ERP systems. Then, he moved on to telecoms support systems, where he mainly dabbled with C++, Perl, and Shell scripts.

    Nowadays, he's making up for lost times with his passion for hacking on data-oriented and web-related technologies through Python and Django in Save22 Inc.

    On his days off, you'll catch him volunteering for the local Python community, hacking on a side project with his girlfriend, or in hermit mode learning something new.

    I would like to thank my girlfriend, Mickey, for supporting me in writing this book review.

    Patrick Louis is an advocate of the learn by/from curiosity movement. For him, programming is just another way of expression—an art. He likes to contribute his free time to the open source projects that catch his attention. He's a core member of the nixers.net community.

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    For support files and downloads related to your book, please visit www.PacktPub.com.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why Subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Free Access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

    Preface

    The book is full of practical task-based recipes to be performed while developing multitouch applications with Kivy. The focus of this book is to guide you through the Kivy framework to develop apps and get your apps ready for distribution in App Stores and Android devices. We'll focus on common, real-world scenarios. You'll be able to leverage these recipes right away, which allows you to create most diverse apps and learn how to distribute them using the Kivy framework, and widen your proficiency in developing multitouch applications with Kivy.

    What this book covers

    Chapter 1, Kivy and the Kv Language, introduces the Python code, Kv language, widgets, and Kivy garden. The topics covered in this chapter lay the foundation for the remaining code samples in each chapter.

    Chapter 2, Input, Motion, and Touch, demonstrates some of the most common recipient-related management tasks, such as evolving to the touchscreen, using the gyroscope, and detecting multitapping. You'll also learn how to recognize touch shapes, record gestures, and differentiate between touch and motion events.

    Chapter 3, Events, shows how to schedule a one-time event and a repetitive event. Triggering events, defining widget events, creating custom events are also covered in this chapter.

    Chapter 4, Widgets, covers the manipulation of widget tree, traversing of tree. It also covers the FloatLayout, BoxLayout, StackLayout, AnchorLayout, and action bar.

    Chapter 5, Graphics – Canvas and Instructions, explains various methods, such as separating with the screen manager, using context instructions, and using drawing instructions. You'll learn how to modify with multitouching and storing and retrieving the coordinate space context.

    Chapter 6, Advancing Graphics – Shaders and Rendering, covers Carousel, layouts, and shaders. The other topics covered in this chapter are rendering in a Framebuffer and optimizing

    Enjoying the preview?
    Page 1 of 1