Getting Started With Python S60
Phase 1
Send Sms Example
import appuifw
import messaging
data = appuifw.query(u"Type your name:", "text")
nbr = "123456"
txt = u"Hi!" +data
messaging.sms_send(nbr, txt)
#sends sms to number=nbr and as text = txt
#Be careful nbr and txt both must be string literals only
MultiQuery Input Example
import appuifw
data1,data2 = appuifw.multi_query(u"Type your name:",u"Type your number:")
print data1
print data2
Selectionlist Example
import appuifw
# define the list of items (items must written in unicode! -> put a u in front)
L = [u'Table', u'Chair', u'computer', u'Mobile', u'pen', u'screen', u'camera', u'Homekeys']
# create the selection list
index = appuifw.selection_list(choices=L , search_field=1)
if index == 0:
print "Table was selected"
else:
print "Better Luck next time"
Multiselection Example
import appuifw
L = [u'Table', u'Chair', u'computer', u'Mobile', u'pen', u'screen', u'camera', u'Homekeys']
index = appuifw.multi_selection_list(L , style='checkbox', search_field=1)
Lnew = index
print Lnew
Define Function Example
import appuifw
def function():
data = appuifw.query(u"Type a word:", "text")
appuifw.note(u"The typed word was: " +data, "info")
function()
Screen Examples
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)
app_lock = e32.Ao_lock()
appuifw.app.body = round
appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()
Create Menu Example
import appuifw
import e32
def exit_key_handler():
app_lock.signal()
def item1():
print ""
round.set(u'1st item was selected')
def subitem1():
print ""
round.set(u'Now first subitem was selected')
def subitem2():
round.set(u'Second subitem was selected')
app_lock = e32.Ao_lock()
round = appuifw.Text()
round.set(u'press options')
appuifw.app.screen='large'
appuifw.app.body = round
###### create the application menu including submenus###
appuifw.app.menu = [(u"item 1", item1),
(u"Submenu 1", ((u"sub item 1", subitem1),
(u"sub item 2", subitem2)))]
appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()
Create Listbox Example
import appuifw
import e32
def exit_key_handler():
app_lock.signal()
# define a callback function
def shout():
index = lb.current()
print index
print entries[index]
# create your content list of your listbox including the icons to be used for each entry
entries = [u"Signal",u"Battery"]
lb = appuifw.Listbox(entries,shout)
# create an Active Object
app_lock = e32.Ao_lock()
# create an instance of appuifw.Listbox(), include the content list "entries" and the callback function "shout"
# and set the instance of Listbox now as the application body
appuifw.app.body = lb
appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()
Form Example
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'6680', u'6670', u'7610', u'N95', u'N73']
# 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()