PyS60 samples


PyS60 tutorial

SMS and MMS:
import appuifw
import messaging

data = appuifw.query(u"Type your name:", "text")

nbr1 = "123456" # change the mobile number here
nbr2 = "654321" # change the mobile number here
txt = u"Greetings from: " + data

if appuifw.query(u"Send message to your 2 friends","query") == True:
    messaging.sms_send(nbr1, txt)
    messaging.sms_send(nbr2, txt)
    appuifw.note(u"Messages sent", "info")
else:
    appuifw.note(u"Well, your Messages are not sent then", "info")


import inbox, appuifw, e32

def message_received(msg_id):
        box = inbox.Inbox()
        sms_text = box.content(msg_id)
        appuifw.note(u"sms content: " + sms_text , "info")
        app_lock.signal()

box = inbox.Inbox()
box.bind(message_received)

print "Waiting for new SMS messages.."
app_lock = e32.Ao_lock()
app_lock.wait()
print "Message handled!"

import inbox, appuifw, e32, time

j = 0
box = inbox.Inbox(inbox.EInbox)
for i in box.sms_messages():
    try:
        print "<sms " + str(i) + ">"
        print "from: " + box.address(i)
        print "time: " + time.ctime(box.time(i))
        print "content: " + box.content(i)
        j += 1
        if j>20:
            break
    except:
        print "<" + str(i) + ">" + " exception"
        break


audio:
import appuifw
import audio

text = appuifw.query(u"Type a word:", "text")
audio.say(text)


Camera:
import e32, camera, appuifw, key_codes

def finder_cb(im):
    canvas.blit(im)

def take_picture():
    camera.stop_finder()
    pic = camera.take_photo(size = (640,480))
    w,h = canvas.size
    canvas.blit(pic,target=(0, 0, w, 0.75 * w), scale = 1)
    pic.save(‘e:\picture1.jpg’)

def quit():
    app_lock.signal()

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

camera.start_finder(finder_cb)
canvas.bind(key_codes.EKeySelect, take_picture)

appuifw.app.title = u"My Camera"
appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()


Application basics:
import appuifw
import e32

def exit_key_handler():
    app_lock.signal()


round = appuifw.Text()
round.set(u’hello’)

# put the application screen size to full screen
appuifw.app.screen=’full’ #(a full screen)

# other options:
#appuifw.app.screen=’normal’ #(a normal screen with title pane and softkeys)
#appuifw.app.screen=’large’ #(only softkeys visible)


appuifw.app.body = round
appuifw.app.exit_key_handler = exit_key_handler

app_lock = e32.Ao_lock()
app_lock.wait()

import appuifw
import e32


# define application 1: text app
app1 = appuifw.Text(u’Appliation o-n-e is on’)

# define application 2: text app
app2 = appuifw.Text(u’Appliation t-w-o is on’)

# define application 3: text app
app3 = appuifw.Text(u’Appliation t-h-r-e-e is on’)


def exit_key_handler():
    app_lock.signal()

# create a tab handler that switches the application based on what tab is selected
def handle_tab(index):
    global lb
    if index == 0:
        appuifw.app.body = app1 # switch to application 1
    if index == 1:
        appuifw.app.body = app2 # switch to application 2
    if index == 2:
        appuifw.app.body = app3 # switch to application 3

   
# create an Active Object
app_lock = e32.Ao_lock()

# create the tabs with its names in unicode as a list, include the tab handler
appuifw.app.set_tabs([u"One", u"Two", u"Three"],handle_tab)

# set the title of the script
appuifw.app.title = u’Tabs’

# set app.body to app1 (for start of script)
appuifw.app.body = app1


appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()

import appuifw
import e32

# create an Active Object
app_lock = e32.Ao_lock()


def forming():
    # create a list to be used in ‘combo’ selection mode
    model = [u’6600’, u’6630’, u’7610’, u’N90’, u’N70’]
   
    # define the field list (consists of tuples: (label, type ,value)); label is a unicode string
    # type is one of the following strings: ‘text’, ‘number’, ‘date’, ‘time’,or ‘combo’
    data = [(u’Mobile’,’text’, u’Nokia’),(u’Model’,’combo’, (model,0)),(u’Amount’,’number’, 5),(u’Date’,’date’),(u’Time’,’time’)]

    # set the view/edit mode of the form
    flags = appuifw.FFormEditModeOnly

    # creates the form
    f = appuifw.Form(data, flags)
   
    # make the form visible on the UI
    f.execute()

def exit_key_handler():
    app_lock.signal()
   
# set the title of the script
appuifw.app.title = u’Form’

# call the function that creates the form
forming()

appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()










end