Live Coding with Kivy and IPython

I recently began to implement some game prototypes with the help of Kivy, a very interesting Python library originally developed to prototype innovative user interfaces. Combined with IPython, Kivy could also be interesting for live coding, and so I checked out how the input hooks for other event loops work in IPython. Currently, there are hooks for Qt, glut, pyglet, GTK, wx and tk build in. That means that you can use any of those frameworks to develop GUI apps interactively from within an IPython shell.

For Kivy, I copied one of the existing hooks and came up with the following code:

The function enable_kivy() would return an Kivy app object that you can then use to add widget interactively. Just start an IPython shell and add a rectangle to a Kivy window, for example:

[1] import helpers
[2] app = helpers.enable_kivy()
[3] from import *
[4] with app.root.canvas:
    Color(1.0, 0.2, 0.0)
    Rectangle(pos=(850,450), size=(200,200))

Unfortunately, you have to patch the Kivy sources to run in interactive mode at the moment. Kivy has a so-called slave mode, but it is not available when you call the default run() method on the App object. Here is a simple patch that just pipes the slave parameter to the runcTouchApp() method and will allow you to start the Kivy app in slave mode:

Have fun!

About me

My name is Peter Bouda and I am a software developer with more than 20 years of professional experience in application development. I help you to bring your application to market as quickly as possible.

Read about my work
Contact me

Send me a message and I will get back to you.

RSS Feed