Python for Nokia S60
Daniel Ashbrook
anjiro@[Link]
Introduction
● Hello world!
import appuifw
[Link](u“Hello World!”,\
“info”)
● appuifw: application user interface
framework
● u“Hello World!”
S60 uses Unicode, hence the u on all strings
● but don't need it on Python-only strings:
[Link] = “full”
Menus
● import appuifw
list = [u”Item 1”, u”Item 2”,\
u”Item 3”]
picked = appuifw.popup_menu(list, \
u”Pick an item:”)
if picked == 0:
[Link](u”Picked item one!”)
if picked == 1:
[Link](u”Picked item two!”)
if picked == 2:
[Link](u”Picked item three!”)
Take a picture
● import camera
print camera.image_sizes()
[(1280, 960), (640, 480), (160, 120)]
image = camera.take_photo(size = (160,120))
[Link](u”D:\\[Link]”)
Send the Picture!
● import socket
address, services = socket.bt_discover()
bt_obex_send_file(address, 4, \
u”D:\\[Link]”)
● The second argument is the channel to send the file on –
generally 4 will work
Where Am I?
● import location
mcc, mnc, lac, cellid = location.gsm_location()
print u”\
Mobile Country Code: %d\n \
Mobile Network Code: %d\n \
Location Area Code: %d\n \
Cell ID: %d” % (mcc,mnc,lac,cellid)
Mobile Country Code: 310
Mobile Network Code: 260
Location Area Code: 2461
Cell ID: 10162
Record & Play Audio
● Record audio
import audio
sndfile = [Link](u”D:\\[Link]”)
[Link]()
[Link]()
● Play audio
[Link]()
Send an SMS
● import messaging
messaging.sms_send(u”4045551234”, u”This \
is a test message! Hooray!”)
● import messaging
import location
phnum = u”4045551234”
myloc = u”I'm at Cell ID %d!” % \
location.gsm_location()[3]
messaging.sms_send(phnum, myloc)
Use the Canvas
● import appuifw
import graphics
canvas = [Link]()
[Link] = ”large”
[Link] = canvas
[Link]((10, 20, 100, 150), \
0xff0000, fill = 0x00ff00)
Use the Canvas 2
import appuifw
import e32
def quit():
global running
running = 0
[Link].exit_key_handler = quit
[Link] = 'large' # or 'full'
canvas = [Link]()
[Link] = canvas
while running:
do stuff here
Use the Canvas 3
import appuifw running = 1
import e32
import graphics while running:
import sysinfo x1 = [Link](res_x)
import random x2 = [Link](x1, res_x)
y1 = [Link](res_y)
def quit(): y2 = [Link](y1, res_y)
global running color = [Link](0xffffff)
running = 0 [Link]((x1, y1, x2, y2),
color, fill=color)
res_x, res_y = e32.ao_yield()
sysinfo.display_pixels()
[Link].exit_key_handler =
quit
[Link] = 'large'
canvas = [Link]()
[Link] = canvas
Canvas + Camera 1
import appuifw while running:
import e32 image = camera.take_photo(size =
import graphics (160, 120))
import camera [Link](image)
e32.ao_yield()
def quit():
global running
running = 0
[Link].exit_key_handler =
quit
[Link] = 'large'
canvas = [Link]()
[Link] = canvas
running = 1
import appuifw
Canvas + Camera 2a
import e32
import graphics
import camera
import key_codes
running = 0
take_picture = 0
class KeyboardHandler(object):
def handle_event(self, event):
global take_picture
if event["type"] == [Link]:
if event["scancode"] == key_codes.EScancodeSelect:
take_picture = 1
elif event["scancode"] == key_codes.EScancodeNo:
running = 0
kbhandle = KeyboardHandler()
[Link] = 'large'
canvas = [Link](event_callback = kbhandle.handle_event)
[Link] = canvas
Canvas + Camera 2b
running = 1
while running:
if(take_picture):
im = camera.take_photo(size = (1280, 960))
[Link]("E:\\Images\\[Link]")
running = 0
else:
image = camera.take_photo(size = (160, 120))
[Link](image)
e32.ao_yield()
Handy Links
● My S60 Python links
● [Link]
● S60 Python tutorial pages
● [Link]
● Nokia's official Python discussion forum
● [Link]