0% found this document useful (0 votes)
56 views

Python For Nokia S60

This document provides an overview of using Python for application development on Nokia S60 phones. It demonstrates how to perform common tasks like displaying text, creating menus, taking photos, recording and playing audio, sending SMS messages, and using the phone's canvas. Code samples are provided for importing necessary frameworks, interacting with components like the camera and audio, and handling events. Links are also included for additional Python and S60 resources.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Python For Nokia S60

This document provides an overview of using Python for application development on Nokia S60 phones. It demonstrates how to perform common tasks like displaying text, creating menus, taking photos, recording and playing audio, sending SMS messages, and using the phone's canvas. Code samples are provided for importing necessary frameworks, interacting with components like the camera and audio, and handling events. Links are also included for additional Python and S60 resources.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Python for Nokia S60

Daniel Ashbrook
[email protected]
Introduction
● Hello world!
import appuifw
appuifw.note(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:
appuifw.app.screen = “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:
appuifw.note(u”Picked item one!”)
if picked == 1:
appuifw.note(u”Picked item two!”)
if picked == 2:
appuifw.note(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))


image.save(u”D:\\image.jpg”)
Send the Picture!
● import socket

address, services = socket.bt_discover()


bt_obex_send_file(address, 4, \
u”D:\\image.jpg”)
● 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 = audio.Sound.open(u”D:\\test.wav”)
sndfile.record()
sndfile.stop()

● Play audio
sndfile.play()
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 = appuifw.Canvas()
appuifw.app.screen = ”large”
appuifw.app.body = canvas

canvas.rectangle((10, 20, 100, 150), \


0xff0000, fill = 0x00ff00)
Use the Canvas 2
import appuifw
import e32

def quit():
global running
running = 0

appuifw.app.exit_key_handler = quit

appuifw.app.screen = 'large' # or 'full'


canvas = appuifw.Canvas()
appuifw.app.body = canvas

while running:
do stuff here
Use the Canvas 3
import appuifw running = 1
import e32
import graphics while running:
import sysinfo x1 = random.randrange(res_x)
import random x2 = random.randrange(x1, res_x)
y1 = random.randrange(res_y)
def quit(): y2 = random.randrange(y1, res_y)
global running color = random.randrange(0xffffff)
running = 0 canvas.rectangle((x1, y1, x2, y2),
color, fill=color)
res_x, res_y = e32.ao_yield()
sysinfo.display_pixels()

appuifw.app.exit_key_handler =
quit

appuifw.app.screen = 'large'
canvas = appuifw.Canvas()
appuifw.app.body = canvas
Canvas + Camera 1
import appuifw while running:
import e32 image = camera.take_photo(size =
import graphics (160, 120))
import camera canvas.blit(image)
e32.ao_yield()
def quit():
global running
running = 0

appuifw.app.exit_key_handler =
quit

appuifw.app.screen = 'large'
canvas = appuifw.Canvas()
appuifw.app.body = 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"] == appuifw.EEventKeyDown:
if event["scancode"] == key_codes.EScancodeSelect:
take_picture = 1
elif event["scancode"] == key_codes.EScancodeNo:
running = 0

kbhandle = KeyboardHandler()

appuifw.app.screen = 'large'
canvas = appuifw.Canvas(event_callback = kbhandle.handle_event)
appuifw.app.body = canvas
Canvas + Camera 2b
running = 1

while running:
if(take_picture):
im = camera.take_photo(size = (1280, 960))
im.save("E:\\Images\\image.jpg")
running = 0
else:
image = camera.take_photo(size = (160, 120))
canvas.blit(image)
e32.ao_yield()
Handy Links
● My S60 Python links
● http://del.icio.us/anjiro/python+nokia
● S60 Python tutorial pages
● http://www.mobilenin.com/pys60/menu.htm
● Nokia's official Python discussion forum
● http://discussion.forum.nokia.com/forum/forumdisplay.php?f=102

You might also like