BB10 Python: Command Line Interface


Posted:   |  More posts about BB10 Python PlayBook BBPyProject

Just a quick update since it's been months of silence (and waiting, mostly) and things are starting to move again.

Tonight I decided that it was time to take the QML "Hello World" code I'd written a couple of weeks ago, and see what it would take to hook that up to Python somehow.

The idea would be to launch with the Qnx/Python entry point into Python code, then instantiate a QApplication, a QDeclarativeContext, and invoke the GUI that way. Using some to-be-determined method, I'd then "bridge" the Python and QML code bidirectionally, allowing some basic form of RPC, blobs of JSON data going back and forth, or something else.

I figured I'd need to do a whole lot of experimentation, which would be made much easier if I had an interactive Python prompt running on the PlayBook side, in the app's context, so I wrote one.

It's not in the repo just yet as it needs some command-line editing capability, but I now have a working telnet server which accepts one client connection at a time, hooks it to a code.InteractiveConsole subclass, and basically acts like a regular Python prompt.

To use it you simply "telnet PBIP 2223" and start typing:

peter@magic:~$ telnet 192.168.0.101 2223
Trying 192.168.0.101...
Connected to 192.168.0.101.
Escape character is '^]'.
Python 3.2.2 (default, Jan 19 2012, 10:50:31)
[GCC 4.4.2] on qnx6
Type "help", "copyright", "credits" or "license" for more information.
(MyConsole)
>>> import sys
>>> sys.path
['/apps/ca.microcode.bbxpython.demo.testDev_python_demoe0b184ea/python',
    '/usr/lib/python32.zip', '/usr/lib/python3.2', '/usr/lib/python3.2/plat-qnx6',
    '/usr/lib/python3.2/lib-dynload', '/usr/lib/python3.2/site-packages']
>>> import os
>>> os.getcwd()
'/accounts/1000/appdata/ca.microcode.bbxpython.demo.testDev_python_demoe0b184ea'
>>> open('/etc/os.version').read()
'2.0.0.7971\n'
>>> ^Z
Connection closed by foreign host.

If you haven't been following things lately, RIM has involved KDAB to help port Qt to the PlayBook, and Cascades will work on top of Qt (C++) and QML (a declarative language for describing a GUI, with Javascript support and some other features that make it very easy to use). At this point, considering anything but Qt/QML/Cascades for the GUI of a native app makes no sense, so I'm heading down this path as it holds the greatest hope of providing Python apps with GUI support, and it will put them on par with any other native app using the same stuff.

More to come...

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.

Comments powered by Disqus