PySide on the PlayBook


Posted:   |  More posts about BB10 Python PySide PlayBook BBPyProject

In my last post [1] I talked about wanting to hook Python to the Qt port for the PlayBook. Since then, after considering other approaches, I decided to take a closer look at PySide [2]. My quick review of it concluded that I'd be duplicating key parts of its functionality if I tried doing anything from scratch.

With encouragement from the #BlackBerryDev IRC channel on Freenode, Xitij Ritesh Patel (who has been "BBX-Python's" biggest fan) and I set up a Rackspace Cloud server and got to work, sharing a single userid via screen for some remote pair programming.

We downloaded the PlayBook Native SDK, the PySide source code, the Qt source, a local copy of the shiboken binaries and various other pieces. Xitij is a tornado at this stuff, a veritable force of nature! That meant I could sit back and pretend to do useful Big Thinking strategic stuff while he typed furiously along, faster than I could follow. Between the two of us, it was a sparkling example of the effectiveness of pair programming under the right conditions. Part way along, we stumbled over Rob Paskowitz's record of his own porting attempt from November 2011 (on an isolated wiki page in my own BBX-Python repo!) and that helped a lot too.

Just 35 hours after we set up the virtual server, and after numerous missteps, steep learning curves climbed, some quick hacks and input from a handful of helpful people online, Xitij tweeted our success to the world! And again with source. And again with QML.

While there's much to be done, such as cleaning up the (relatively few) changes and contributing them back to the PySide project, those of you who are familiar with Python's strengths won't be surprised to learn how much we were then able to accomplish, immediately after achieving that first success.

Ten Second Development Cycle

The first thing I did was a proof of concept for shortening the development cycle. With any of the other SDKs for the PlayBook, you've got at least a compile/link phase, followed perhaps by packaging, then deployment to the target. It can take several minutes, especially if you've got a large app (such as the Qt ones currently are, where you've got 10-20MB of libraries to bundle).

I've now got a 25K .bar file (and most of that is the icon) which I install only once. I copy the Qt and PySide libraries (a hefty 60MB or so for now) over WiFi to my /media/misc folder on the PlayBook. Then I can edit both my .py and .qml source files directly in that folder using my text editor, save, tap the app's icon, and 6-7s later the app has launched using the code I just saved.

We've had some crazy ideas stemming from this capability as well. For example, imagine a tiny app not much bigger than this, which budding developers could sideload (using something like the DDPB Installer) without needing to install a full official SDK. They run it, and it downloads the required libraries from the web, and installs "starter" source code to the shared/misc folder. The developer could immediately begin modifying that code, with instant feedback for their efforts. There could even be templates for various styles of apps (e.g. with or without QML) from which one could choose.

And imagine all that plus a one-button packager which takes all their latest code and wraps it up in a shiny new .bar file. App development completely on-device is not only feasible, but not even that difficult!

Test Automation and Interactive Testing

If there's one area where Python really shines it's in automating tests for your software. Your program is far more "malleable" than those generated with statically typed languages. Using the aforementioned command line interface [1] code, I was able to connect in to the running PySide app and explore "from inside". I could inspect the entire state of the app, starting with the top-level QApplication object, and navigate down to any of the on-screen widgets, modify them (e.g. change scaling, colour, contents of Text objects), and interact in other ways such as by emitting signals to them. I could write a new routine on the fly, to run in a new thread, or even hot-patch an existing routine with new code, and inject new behaviour into the app.

Using the same sort of capabilities, writing automated tests for an app becomes a relatively simple process, and often a surprisingly fun one. In this case, there's no need to incorporate the test code into the app itself, either, other than by providing a hook like the telnet-based interace I was using interactively. An external script running on your desktop machine can be the one initiating the various actions, and it doesn't have to be all "canned" sequences either, as the test code can respond dynamically to the state of the app.

Next Steps

Wow, there's just so much that's possible with this... and so much that would need to be done of course. More people involved would be really nice (hint, hint!). Even if your only contribution is to help spread the word about the possibilities, however, it would be valuable to the effort.

We'll get something usable posted up shortly. Presumably one key item will be to make sure we've published all code changes, since PySide's license is LGPL. If you're interested in getting access to this, direct contact from you would definitely encourage us to maintain our momentum on this project.

Please, if you're following our efforts and interested in helping this succeed, send a tweet my way, blog about it and let me know, come visit us in #BlackBerryDev on IRC (Freenode), or email me at peter at engcorp.com with your story. I've now had contact from several dozen people who have expressed a keen interest in writing apps for the PlayBook and BB10 with Python (and more who said merely "that's awesome!"), but that number is still too low to mean much to those who aren't convinced. Get the word out, and help us build a community around Python on the new BlackBerry BB10 platform.

Let's make it happen!

Oh, and in the credit where credit is due department, it would be wrong not to mention that none of this would even be possible without Nokia's excellent open source efforts with both Qt and PySide. I'm very much a newcomer to both communities (mainly having used wxPython before) but so far I'm very impressed with what I've seen in both.

Note

As of June 2012, we've renamed this the BlackBerry-Py Project. You can follow news about it at @BBPyProject and the web site has moved too.


[1](1, 2) The Command Line Interface mentioned in the earlier post is now in bitbucket and quite usable, though still without more line editing capability than the backspace key provides.
[2]PySide is now part of the Qt project so it has another page there: http://qt-project.org/wiki/Category:LanguageBindings::PySide
Comments powered by Disqus