Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kivy: Building GUI and Mobile apps with Python by Thomas Hansen and Mathieu Virbel

Kivy: Building GUI and Mobile apps with Python by Thomas Hansen and Mathieu Virbel

This talk will introduce the Kivy project (http://kivy.org). Kivy’s mission is to make building graphical user interfaces on any device fun, efficient, and pythonic.

The talk will focus on giving attendees an overview of how they can use kivy to build exiting UIs and mobile apps.

PyCon 2013

March 15, 2013
Tweet

More Decks by PyCon 2013

Other Decks in Programming

Transcript

  1. Kivy Kivy: Building GUI and Mobile apps with Python Thomas

    Hansen - fresk - @hansent Mathieu Virbel - Melting Rocks - @mathieuvirbel PyCon 2013
  2. Issues #kivy GPU's have a different computing paradigm More /

    Higher Bandwidth Inputs increase complexity Composition / Authoring of Interfaces is hard. · · · 4/25
  3. Kivy #kivy Use GPU power, but keep simple things simple

    Events are still good, but async / callbacks suck Zen of Python · · · 5/25
  4. Kivy - Graphics #kivy Everything is GPU accelerated (GLES) 3D

    and Shaders! (if you know what you're doing...power!) Optimized rendering using Cython/C Graphics Instructions for sequential programming & "JIT graphics compiler" Also eases porting, if there is a GPU, GLES isn't far away... · · · · · 6/25
  5. Kivy - Input #kivy Fundamentally based on concept of multi-input

    Conceptual tools / approaches to event handling / interpretation Provider based library design / architechture · · · 7/25
  6. Kivy - Core Providers Providers / Interfaces for: #kivy Image,

    Font Rendering, Window, Video, Audio, Camera, Clipboard, Spelling, etc. Load/process/store/render accessible to Python and/or GL Allows swapping out Dependencies Makes porting / supporting new platforms easier · · · · 8/25
  7. Kivy - The Zen of Kivy #kivy Zen of Python

    KV language. UI composition/styling DSL Indentation based Declarative, concise, auto-binding Works well with graphics instructions approach · · · · · 9/25
  8. Kivy - Batteries Included! Extensive Widget collection #kivy Labels, Buttons,

    Sliders, Images Layouts, ListViews, Screens, Transistions Interactions like scatter, zoom, pan, rotate Support different input modalities out of box (e.g. Virtual Keybords). · · · · 10/25
  9. Kivy - Develop once... Develop & test on workstation, deploy

    to mobile...(not emulated) #kivy Linux, OSX, Windows Android, iOS, Meego Raspberry Pi ? · · · 12/25
  10. Kivy Organization All the projects are available at github.com/kivy #kivy

    7 core developers 13 public projects 2 mailing lists (kivy-users, kivy-dev), ~ 760 users IRC channel #kivy · · · · 13/25
  11. History PyMT Kivy #kivy Created in 2007 Mainly focused for

    NUI on custom hardware Place for experimentation Direct GL API, no way to run it on mobile. · · · · born in 2010 API renamed and stabilized New graphics pipeline, built on OpenGL ES 2 Android and iOS added during 2011 · · · · 14/25
  12. Building for mobile: toolchain We provide toolchain to compile app

    for Android and iOS Python-for-android Kivy iOS #kivy Cross compilation toolchain for ARM/Android Python, SDL, pygame, and many others libraries are shipped One tool for packaging into APK ! Our project is at http://github.com/kivy/python-for-android/ · · · · Cross compilation toolchain for ARM/iOS Not modular, few libraries are available Goal: redo it with the same architecture as Python for Android · · · 15/25
  13. Building for mobile: buildozer Buildozer #kivy One definition file called

    "buildozer.spec" Create application packages for Android and iOS · · $ b u i l d o z e r i n i t $ v i m b u i l d o z e r . s p e c $ b u i l d o z e r a n d r o i d d e b u g d e p l o y r u n S H E L L It hides the complexity of packaging · 16/25
  14. Building for mobile: buildozer #kivy [ a p p ]

    t i t l e = L o g o t o u c h p a c k a g e . n a m e = l o g o t o u c h p a c k a g e . d o m a i n = o r g . e r a s m e s o u r c e . d i r = . s o u r c e . i n c l u d e _ e x t s = i n i , p y , p n g , j p g , t t f , k v , m o , a t l a s v e r s i o n . r e g e x = _ _ v e r s i o n _ _ = ' ( . * ) ' v e r s i o n . f i l e n a m e = % ( s o u r c e . d i r ) s / m a i n . p y r e q u i r e m e n t s = p i k a , k i v y p r e s p l a s h . f i l e n a m e = % ( s o u r c e . d i r ) s / d a t a / p r e s p l a s h . p n g i c o n . f i l e n a m e = % ( s o u r c e . d i r ) s / d a t a / i c o n . p n g # a n d r o i d s p e c i f i c a n d r o i d . p e r m i s s i o n s = I N T E R N E T # i o s s p e c i f i c i o s . c o d e s i g n . d e b u g = " i P h o n e D e v e l o p e r : M a t h i e u V i r b e l ( P S W 9 2 G 0 T X 8 ) " S P E C 17/25
  15. Accessing mobile API Mobile have Accelerometer, Camera, Compass, Contacts, Geolocation

    (GPS, Wifi), Notification etc. We don't provide abstraction for it (yet). What if we could have access to anything in Java from Python ? #kivy 18/25
  16. Accessing mobile API PyJNIus - Access Java classes from Python

    PyOBJus - Access Objective-C from Python #kivy Works on Desktop and Android It uses JNI / Java reflection · · It uses Objective C reflection (Still in progress, doesn't work) · · 19/25
  17. Accessing mobile API: PyJNIus Using Text-To-Speech: Make your phone say

    "Hello World" #kivy f r o m j n i u s i m p o r t a u t o c l a s s L o c a l e = a u t o c l a s s ( ' j a v a . u t i l . L o c a l e ' ) P y t h o n A c t i v i t y = a u t o c l a s s ( ' o r g . r e n p y . a n d r o i d . P y t h o n A c t i v i t y ' ) T e x t T o S p e e c h = a u t o c l a s s ( ' a n d r o i d . s p e e c h . t t s . T e x t T o S p e e c h ' ) t t s = T e x t T o S p e e c h ( P y t h o n A c t i v i t y . m A c t i v i t y , N o n e ) t t s . s e t L a n g u a g e ( L o c a l e . U S ) t t s . s p e a k ( ' H e l l o W o r l d . ' , T e x t T o S p e e c h . Q U E U E _ F L U S H , N o n e ) P Y T H O N 20/25
  18. Accessing mobile API: PyJNIus One step further: implement Java class

    in Python! (wip). #kivy c l a s s G p s L i s t e n e r ( P y t h o n J a v a C l a s s ) : _ _ j a v a i n t e r f a c e s _ _ = [ ' a n d r o i d / l o c a t i o n / L o c a t i o n L i s t e n e r ' ] @ j a v a _ m e t h o d ( ' ( L a n d r o i d / l o c a t i o n / L o c a t i o n ; ) ' ) d e f o n L o c a t i o n C h a n g e d ( s e l f , l o c a t i o n ) : p r i n t ' l a t ' , l o c a t i o n . g e t L a t i t u d e ( ) p r i n t ' l o n ' , l o c a t i o n . g e t L o n g i t u d e ( ) L o c a t i o n M a n a g e r = a u t o c l a s s ( ' a n d r o i d . l o c a t i o n . L o c a t i o n M a n a g e r ' ) P y t h o n A c t i v i t y = a u t o c l a s s ( ' o r g . r e n p y . a n d r o i d . P y t h o n A c t i v i t y ' ) C o n t e x t = a u t o c l a s s ( ' a n d r o i d . c o n t e n t . C o n t e x t ' ) l o c a t i o n M a n a g e r = P y t h o n A c t i v i t y . m A c t i v i t y . g e t S y s t e m S e r v i c e ( C o n t e x t . L O C A T I O N _ S E R V I C E ) l o c a t i o n M a n a g e r . r e q u e s t L o c a t i o n U p d a t e s ( L o c a t i o n M a n a g e r . G P S _ P R O V I D E R , 1 0 0 0 0 , 1 0 , G p s L i s t e n e r ( ) ) P Y T H O N 21/25
  19. Accessing mobile API: Plyer Platform-independant wrapper for python, for platform-dependant

    apis Not started at the moment, but GSOC is coming :) #kivy 22/25
  20. Funding PSF granted $5,000 USD to Kivy project for porting

    Kivy and all the subprojects to Python 3. Thank you PSF! #kivy 23/25
  21. Funding We asked $600 USD to run Kivy on Raspberry

    Pi from Bounty Source We got funded in 5 days ! The next step is $1,000 USD for doing a POC with ANGLE on Windows. Thank you backers! #kivy 24/25