Fun with python for Nokia series 60

Monday, August 15, 2005

View and close running applications

When you use the py2sis tool, a common bug is that the application you create cannot be closed using the exit functionality.

If you want to see what is running, hold down the menu key and a list will appear at the left of the phone. To close one of these apps, press the “c” or backspace key, and the phone will ask if you want to close the app. This tip courtesy Tim. (Thanks Tim)

Wednesday, July 20, 2005

Requesting a UID for releasing your program

For when you want to create a sis file and release it

email to with the subject "UID Request"
- specify your name or program name
- specify your email address
- specify the number of UIDs you request (up to 10).
To ensure that each UID is genuinely unique, Symbian - through the Symbian Developer Network - allocates UIDs from a centrally administrated database. This is a free process

Wednesday, June 22, 2005

Reset the phone

So, you foobared your phone.

To reset a nokia 6600
turn the phone off,
- hold down the keys: green/talk, *, and 3
- Once it starts formatting, release the keys

I think this will restore the phone to factory settings and erase any user data.

One thing to check before you start resetting the phone - make sure it's not out of power. :)

Monday, June 20, 2005

python 1.1.3 released.

New version. Pre-Alpha.

Monday, June 06, 2005

1.1.0 pre-alpha version released!!

It's in prealpha, so some of the APIs may change. They expect 1.1.2 build out soon.

Try it from:,,034-821,00.html

Wednesday, June 01, 2005

Nokia 6600 Manual

Predictive Text

One of the phones I was working on got set on predictive text.

To set predictive text input on or off, press # twice quickly when writing text.
(of course! why didn't I think of that)

Monday, May 30, 2005

File Explorer

Power tool I can't live without
FExplorer by Eric Bustarret

Combining Form Flags

FFormEditModeOnly - When this flag is set, the form remains in edit mode while execute() runs.
FFormViewModeOnly - When this flag is set, the form cannot be edited at all.
FFormAutoLabelEdit - This flag enables support for allowing the end-users to edit the labels of the form fields.
FFormAutoFormEdit - This flag enables the automatic support for allowing the end-users to add and delete the form fields. (This is an experimental feature and not guaranteed to work with all SDK versions.)
FFormDoubleSpaced - When this flag is set, double-spaced layout is applied when the form is executed: one field takes two lines, as the label and the value field are on different lines.

These flags are just 1, 2, 4, 8, 16, which means you can combine them to get new flags like:
doubleSpaced_noedit = 18 # bitwise double spaced (16) and no edit (2)
doubleSpaced__edit = 17 # bitwise double spaced (16) and edit (1)

Sunday, May 29, 2005

Dealing with the time module

you can "import time" and use it

The description for the time tuple is:

0 tm_year (for example, 1993)
1 tm_mon range [1,12]
2 tm_mday range [1,31]
3 tm_hour range [0,23]
4 tm_min range [0,59]
5 tm_sec range [0,61]; see (1) in strftime() description
6 tm_wday range [0,6], Monday is 0
7 tm_yday range [1,366]
8 tm_isdst 0, 1 or -1; see below

so you can grab tm_wday to get the weekday value.

(yr, mo, da, h, m, s, wd, jd, ds) = time.localtime(time.time())
time.mktime((year, month, day, hours, mins, seconds, wd, jd, ds))

The last thing is daylight savings time. From experiments, 1 is true for DST.
"since the dst flag is needed; use -1 as the dst flag if it is unknown "

I tried to use strptime to enter the date without the whole tuple, but it didn't work in the emulator, so I assume it isn't supported on the phone. :(
eg time.mktime(time.strptime(da+u"/"+mo+u"/"+yr, "%d/%m/%Y"))

So then I wrote functions to calcuate the day of week, day of year etc, but then I found out you don't need to because the function is smart and will fix it when you enter.

>>newTime = time.mktime((2005, 05, 29, 0, 0,0, 0, 0, -1))
>>(yr, mo, da, h, m, s, wd, jd, ds) = time.localtime(newTime)
>>print wd
6 (It's a sunday)
>>print jd


Thursday, May 26, 2005

Configuring you phone

.. or how to make your phone like you

Setting shortcut keys
One thing that cuts down transfer time is setting the left shortcut key to infrared.

Conveniently located at:
Menu – tools – settings – phone – standby mode – left selection key

Moving python to the top of the menu

Select python. click "options" - "move"
I recommend the top left hand corner.

Friday, May 20, 2005

Splitting string messages

This works on the phones and is good when you are sending text messages and you want to delimit them with a , : etc


from string import split
stuff =u"{type}:{from}:{message}"

contents = split(stuff,":")
# contents is now a list of the bits in 'stuff'
contents_type = contents[0]
contents_from = contents[1]
contents_message = contents[2]

[Ed note.] The most frustrating thing about python is if you can't figure out how to do something, and then when you do find out it is so obvious

Editing the background image on the phone

The background image is stored in C:\system\Data\backgroundimage.mbm , so hypothetically you could just change it, but you may have to do some sort of update command/wait for the phone to reboot. I haven't tried yet.

If anyone has any idea how to change the screen saver, let me know.

Nokia Python Release 1.1

I saw this note on the developer boards about 1.1. I don't know when it will be available, but I hope it's soon. It looks like they're going to put in a lot of features that will be really useful.

For more info see this PPT presentation

Most especially:
* sysinfo module
* camera module
* calendar module
* contacts module

The following extensions to Python modules have been included:
* appuifw module
* Application() type has a new screen attribute
* Text() type has new attributes: color, font, hlcolor, and style

New module level function available_fonts()
The following standard Python library modules are now also supported:
* zipfile

* line((x1,y1),(x2,y2),(r,g,b))
* rectfill((x1,y1),(x2,y2),(r,g,b))
* clear([(r,g,b)])
* text((x,y),unicode,(r,g,b))
* bind(event_code, callable)

* draw (read/write) is called when refreshing the display is needed with parameters: (Canvas,((x1,y1),(x2,y2)))
* resize (read/write) is called when the canvas is resized with Canvas as parameter

Update: Now available!

Friday, May 06, 2005

Writing SQL in python - make it unicode

Remember to make sure all SQL calls are unicode.


sql_string = "SELECT * FROM steps WHERE date>=#%s#"% e32db.format_time(today_start)

dbv.prepare(self.native_db, unicode(sql_string))

Thursday, May 05, 2005

List of python apps and links

List of python apps and links
X10 programming

Symbian Hacking page

  • Traffic Cam Proof Of Concept - Rapid Development in Python
  • Technorati - an incomplete and buggy implementation. Needs further work: Will do so when I get my new phone.
  • Locative Tech - Location based exploration
  • wikkit - wikilike scratchpad
  • Keycodes - some code for finding keybindings

Wednesday, May 04, 2005

From Nokia

Setting up messaging code (IRS Specific)

Put (from CVS\socialmobile\py\symbian) on your phone

Install as python lib module

Import and use!

If you set test mode to true, then the messages go to a directory on your phone (C:\\system\\temp) rather than sending, so you save minutes.

(If you have trouble, you may need the pyd)
Install sm_messaging_inbox.pyd (CVS\socialmobile\py\symbian\bin)
This is where you and the emulator part ways.

Friday, April 29, 2005

Adventures in AIF (Changing the snake)

The AIF is the application information file.

If you want to change the icon, you need to edit this file.

Generating AIFs

Developer discussion icons

what is an AIF?

Reading and Writing Files on the Nokia

Just like regular python! (I didn't know python, so I had to figure it out.) Here's an example:

def readFile(self,file_name):
the_file = open(file_name)
the_contents =
appuifw.note(unicode(the_contents), 'info')

def writeFile(self,file_name):
the_file = open(file_name,'w') # w = open for reading and writing
the_file.write(u"here is some text for the file")

Use or something else to figure out where a good place to put files is. You can write html files too.

Reading from Forms

result = f[row][col]
rows start at 0, columns at 1

def run_form(self):
(u'a', 'number', 300),
(u'b', 'text', u'start message'),
(u"c", 'combo', (options_intarray, default_int))#,
f = appuifw.Form(data,appuifw.FFormEditModeOnly)

def save_form(self,f):
a = f[0][2]
b = f[1][2] #unicode
c = f[2][2][1] #long

Note that combo boxes need an extra array index.

Text fields come back as unicode. Just use type(x) to figure out what type f[x][y] is.

Python bits I wish I knew before I started

print type (x)
prints out the type of x

int (x) casts to int
repr(x) makes it a string representation

when repr(x) gives you 1232L, x is a long

Imaging on the Phone

Right now there is no good image control on the phone in python
Workaround ideas:
  • Construct and html page and view it instead
  • Construct a .png file and view it
  • use urllib/urlretrieve to get a .png file off the server
  • fake it using ascii characters

HTML on the Nokia

I'm working on getting this integrated with python, but right now I know you can create an html file and send it to the phone. It will automagically install and show you the html. You can send .png images (I have red.png etc which are 1 pixel colour images, very useful for bar graphs) and then do stuff like img src="C:\\red.png" height="10" width="20" . If you do this you need to create new directories and move stuff around, but it does work. What is super-cool is you can then from python run:


It works pretty well, although html files go through this handler which breaks up the flow of your program.

If you want to deal with locks properly you can use:
import e32
lock = e32.Ao_lock()
handler = appuifw.Content_handler(lock.signal) # eg. an image file
lock.wait() # wait for lock.signal to unlock

cite: codesnippets

Alleged modules

From here

I can't seem to get random to work on the phone though, so maybe I have to add it. It works on the emulator.

anydbm, atexit, base64, bdb, binascii, cmd, code, codecs, codeop, copy, copy_reg, cStringIO, dis, errno, exceptions, future, httplib, imp, keyword, linecache, marshal, math, md5, mimetools, operator, os, pdb, quopri, random, re, repr, rfc822, socket, sre, string, StringIO, struct, sys, thread, threading, time, traceback, types, urllib, urlparse (urlsplit only), uu, warnings, whichdb, xreadlines, as well as a “location” module for determining GSM cell info and “messaging” for sending SMS messages. Additionally, there is a UI Specific module, appuifw, the e32 Module, which offers some Symbian related utilities, e32db, a relational database module, and the e32dbm module, which offers an API to the Symbian RDBMS

Getting contact Info

Symbian Error Codes

Setting up Python in Eclipse

This is a bit of a pain. I'm not sure how I did it. You can download the PyDev plugin off the eclipse plugin webpage.


Install FAQ

You can just grab the zip from sourceforge, extract it and drop the plugins folders into the eclipse plugins folder.

Miso Utility Library

I think this lets you take pictures on the cameraphone etc.



The Py2Sis program lets you create SiS files that will run on the phone without having to run python first. More info :Developer Discussion Boards

Script as standalone

Finding Py2Sis

py2sis should show up in C:\Nokia\Tools\Python_for_Series_60\py2sis
If it doesn't use winzip (or some other tool) to explore the python SDK zip
Look in the exe, and then in should be in there.
Extract to a folder, put it in your path etc.
Make sure you take all the tmp files and put them in a separate folder called templates.

Using Py2Sis

py2sis is a utility for packaging a Python script as a SIS file to be installed in the Symbian Series 60 2nd edition devices. py2sis comes with the Python for Series 60 SDK installation package.

Use the command line utility in the following way:
py2sis [sisfile] [--uid=0x12345678] [--appname=myapp] [--presdk20]
giving the path to the script or directory as parameter. If you are packaging a whole directory, the directory must contain a file named which will be used as the main script.

py2sis uses the command line tools from the Symbian SDK, so the SDK needs to be installed and properly configured. This means that the makesis and uidcrc utilities need to be in your system path.
By default, the SIS file is created in the current working directory, but optionally you can specify the path where you want to save the resulting SIS with the sisfile parameter.

Example: py2sis c:\mysis.sis

All Symbian applications need to have an UID, which you can provide from the command line using the --uid switch. The UID can also be embedded in the main script by including the line:

# SYMBIAN_UID = 0x01234567

The name of the application is taken from the source name, but the name can also be specified using the --appname switch.

Useful Links

Setting up an Emulator

The secret is to have Microsoft Visual Studio, and install

SDK for C++ / Symbian Operating System

Go for:
SDK for 2nd Edition, FP 2

and then

Python for series 60

Go for:

One more trick: Run the debug emulator and not the release emulator. You should have python in your menu. (Options-> Move and you can put it at the top of the menu)

Running code on the Emulator

Drop code into the python directory
Example: C:\Symbian\7.0s\Series60_v21\Epoc32\release\wins\udeb\z\system\apps\PYTHON
(to find yours, search for

To install python library modules, put the code in the library folder
Example: C:\Symbian\7.0s\Series60_v21\Epoc32\release\wins\udeb\z\system\libs

Setup on the phone

To setup python for the phone, go to Python for Series 60

and download at the right

The Sys file is a file that runs on your phone. Call infrared on the phone, put it near your computer and send it across. The messaging on the phone will automatically install it. Now you have python in your menu! Run and let the python fun begin!