39,59 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 241
Veröffentlichungsjahr: 2015
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
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
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.
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.
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 <[email protected]> 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.
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.
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.
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 graphics.
Chapter 7, The API in Detail, introduces API and covers the logging objects, parsing, applying utils, using spelling, adding effects, and adding text.
Chapter 8, Packaging our Apps for PC, shows how to perform packing for Windows, Linux, and MacOs. It also shows multimedia for Windows and running apps in Windows and MacOS.
Chapter 9, Kivy for Mobile Devices, explains various methods, such as packaging for iOS and resizing the screen into iOS. You'll learn preparing for the App Store, packaging for Android, and resizing the screen into Android.
To complete the recipes in this book, you'll need the following:
This book is intended for developers who want to use features of the Kivy framework and develop multitouch applications. Prior experience with Kivy is not required although familiarity with Python is expected.
In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).
To give clear instructions on how to complete a recipe, we use these sections as follows:
This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.
This section contains the steps required to follow the recipe.
This section usually consists of a detailed explanation of what happened in the previous section.
This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.
This section provides helpful links to other useful information for the recipe.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We are using again our KV file with a simple button and empty label with ID button1 and label1 respectively"
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "We are going to use one simple Python files that will just show our Hello World text"
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
In this first chapter, we will cover the following recipes:
The first chapter is going to introduce the reader to the Kivy framework, its basis, and the Kv language. This is necessary work and a common base for the next chapters. If this is your first time using Kivy, it is advised that you do not skip this chapter. However, if you do, remember to return to this chapter if you need to install a supporting tool or verify any concept that you need to support your current solution.
This recipe will teach you how to install Kivy on a personal computer, which is the first step in starting to develop great software.
We will assume that you already have GNU/Linux (preferably Ubuntu/Debian/Trisquel, we recommend the last one) and Python installed on it. Usually, Python is already installed on the aforementioned GNU/Linux distributions. We will also assume that you are using Python version 2.7 or higher.
There are many ways to get Kivy installed on your computer. Here we are describing probably the easiest way using your distribution's package manager. In the first step, we are adding a PPA as an APT repository to provide you with two different options: the stable one, for which all the Kivy products have been well tested, and the nightly one, which are packages under active development. Actually, for Ubuntu, you can skip the first step; it was just to get the latest version of Kivy.
In the second step, we update the list of available packages to include the Kivy repository. The third step is where the installation of Kivy really happens by using the distribution's package manager. In the last step, we verify if Kivy is working with the command that imports Kivy. If everything is OK we will see the following:
It shows the Kivy version that you installed in your system, which is v1.9.0 in this case. Remember to exit Python, for which we use the command quit().
Now we will say something about Mac OS X and Microsoft Windows; for them, Kivy provides what is called portable packages. For an easy way to get Kivy running, just go to http://kivy.org/#download.
Download the dmg file, double-click to open it, and drag the Kivy.app into your Applications folder. Ready!
You should run the make-symlinks script to make Kivy available in the shell system. Thus, you can run Kivy from the terminal.
Download the .zip file and unzip it. There is a file named kivy.bat that must be copied as a shortcut into your SendTo folder.
Well, if you are using a different operating system, you are always able to go to http://kivy.org/#download and look for the one that you are using. Also, if you want to build Kivy from the source code, refer to Chapter 8, Packaging our Apps for PC the recipe Packing for Linux.