PUTools: Python Utility Tools for PyS60 Python

Symbian S60 now supports also Python programming. Here you can find a Python interpreter that takes input and shows output on PC, connects over Bluetooth to phone, and executes on the phone. You also get simple shell functionality for the phone (cd, ls, rm, etc.). The tool also allows you to synchronize files both from PC to phone (very useful in application development) and from phone to PC (your images, logfiles from the program you are working on, etc.).

Latest development

PUTools has now been tested on 3rd edition. (Dec 3, 2006).

Downloads and prerequisites


The tools provided here mostly concern with Bluetooth (BT) communication between a phone and a PC, as well as shell-types of tools.
Here are the current components:

Setting up Bluetooth

Bluetooth is nice for communicating between the phone and PC. Not only can you use it to edit python files on PC and sync them to the phone (or any other files such as MP3s, etc.), transfer files (log files, photos, etc.) from the phone to your PC, get a console and shell that uses PC display and keyboard but executes on the phone, you can also use phone to control an application running on the PC. However, different Bluetooth HW and drivers behave differently and are often not straightforward to set up.

On my laptop (Windows XP, Widcomm BT driver), this is what you need to do.
Open Bluetooth  configuration, you can find that from the Control Panel.
Choose Bluetooth Configuration from Control Panel
From the Accessibility tab select "Let other Bluetooth devices discover this computer."
Enable other devices to discover the computer
In the Local Services tab add at least two Serial Services that associate a BT serial connection with a COM port. Select Auto Startup. Unselect Secure Connection. Give them a name that lets you recognize which COM port the service corresponds to.
Add serial ports
If you don't have Widcomm drivers (which have worked quite nicely for me), you might find something like this under Control Panel -> Bluetooth Devices. Turn the Discovery on and allow others to connect.
Turn discovery on, allow connections
Then add a couple of incoming serial (COM) ports. As I did this on another laptop, the ports were named automatically (COM5, COM10, etc.).
add incoming COM ports
The BT connection may require you to pair the PC and phone. On the phone go to Connections -> Bluetooth, there go to Paired Devices, and set up a new pairing to your PC.

Getting started with push (Python Utility Shell)

Download the distribution file.

On the phone
Here's what you should see now.
ivt serial, COM port

What can you do?

Python interpreter. push provides a Python interpreter that runs on the phone but takes the input from the PC and echos output on the PC.

File synchronization. push has also integrated file synchronization. In the example above, sync first detected that no files had been edited since last sync. I made a trivial edit to phpush.py one directory level above, the next sync sent it over to the phone. Finally, quit sends a signal to phone to stop phpush.py and also push on the PC side will end. A variant called syncl exists, that also reloads a module if you upload a module that was already imported.

Shell commands. Various shell commands such as cd, ls, rm, etc. exist. To find out which ones, type man, man ls, etc.

Snapshots from your phone screen. Now you can also get snapshots of the phone screen (or image files on the phone) and display them on PC (great for demoing your Python program through a projector attached to the PC). You can even save them on files. Type man snap and man view to find out more, these are interactive shell commands.. You can also instrument your Python program's display routine to send the snapshot automatically to the PC by calling sys.stdout.snap() to get animated PC display. Thanks to Larry Rudolph for suggesting the snapshot functionality. Some sample snapshots below.

Startup file. In the beginning the interpreter runs a startup script if one exist on the phone at C:\startup.py. In this example that file simply contains print 'my startup script'. The distribution includes a sample startup file in putools/other/startup.py.

Application development workflow. When developing a simple application (hello.py), the workflow can be as follows. Create hello.py in the putools directory. (It can really be anywhere on the PC, study putools/pcfiles/sync.config comments for details.) In push, type sync. Test it by run hello.py (or import hello or reload(hello), this is regular Python now, run is just a shortcut for execfile). Edit file on the PC, repeat.

More details about the program

push is a modification of the great PyShell / PyCrust tools that come with wxPython. It does a lot of processing on the PC side (formatting and color coding input and output, for example, as well as good multiline editing. It echoes the stderr and stdout outputs of the Python interpreter back to PC over Bluetooth.

push also supports unicode characters. In the example above the title on the phone is reset, the new string contains unicode characters, and things work just right.

If your program grabs the ownership of stdout/stderr/stdin or wants to create its own code.InteractiveInterpreter, you might want to use btconsole.py that comes with the S60Py distribution (or look here for the earlier version of these tools). btconsole.py is more general, it just echos stdout/stderr/stdin over BT to a terminal, but that is a relatively primitive tool..

Troubleshooting and tips



The following people have contributed ideas or code: Mark Adler, Albert Huang, Jukka Laurila, Larry Rudolph, Jurgen Scheible, Paul Wisner, Emily Yan.

You can find the latest version at Kari Pulli's page at http://people.csail.mit.edu/kapu/symbian/python.html.