Info: How to build an application? -> 9 steps that can be helpful

9 steps that can be helpful to build an application:

1. import all modules needed

2. set the screen size (normal, large, full)

3. create your application logic ...

4. create an application menu (if neccessary)

5. set an exit key handler

6. set the application title

7. deal with active objects if neccessary

8. set the application body (text or canvas or listbox or none)

9. create a main loop (e.g. while loop) if suitable

 

1. How to import all modules needed

import appuifw
import e32

 

2. How to set the screen size?

# screen has 3 different values:
appuifw.app.screen='normal' #(a normal screen with title pane and softkeys)
appuifw.app.screen='large' #(only softkeys visible)
appuifw.app.screen='full' #(a full screen)


Example script: app_screen.py

 

3. How to create your application logic ?

Well this whole tutorial is about that ... You certainly need some app logic to get your app running, whatever logic it may be!

 

4. How to create an application menu ?

An application menu uses the left softkey and can always be accessed while your application is running. An application menu can contain also a submenu

# create the callback functions that shall be executed when when selecting an item in
# the menu:

def item1():
    print "item one"

def subitem1():
    print "subitem one"

def subitem2():
    print "subitem two"

# create the menu using appuifw.app.menu[(title, callback1), (title, (subtitle, callback2))]

appuifw.app.menu = [(u"item 1", item1), (u"Submenu 1", ((u"sub item 1", subitem1),
                                  (u"sub item 2", subitem2)))]


Example script: app_menu.py


5. How to set an exit key handler ?


The exitkey handler gets activated when you press the right (exit) softkey. By assigning an extra function to the .exit_key_handler you can define what shall happen when it is pressed.

def quit():
    appuifw.app.set_exit()

app.exit_key_handler=quit

 

6. How set the application title?

appuifw.app.title = u"SMS sending"

 

7. How to deal with active objects if neccessary?

A facility called active object is used extensively on the Symbian OS to implement co-operative, non-preemptive scheduling within operating system threads. Preserving the responsiveness of the UI can be done with the help of active objects. This needs to be considered when designing the application logic. As a Python programmer, you typically need to take care of active objects as they relate to UI programming, and sockets. Can be tricky!

# You need to import the e32 module
import e32

# create an instance of the active object
app_lock = e32.Ao_lock()

# starts a scheduler -> the script processes events (e.g. from the UI) until lock.signal() is
# callled.
app_lock.wait()

# stops the scheduler
app_lock.signal()

-> For more detail see the API_Reference_for_Python.pdf.

 

8. How to set the application body ? (text or canvas or listbox or none)

# body as Listbox:

appuifw.app.body = appuifw.Listbox(entries,shout)

# Example script: app_body_listbox.py

# body as Text:

appuifw.app.body = appuifw.Text(u'hello')

# Example script: app_body_text.py

# body as Canvas:

appuifw.app.body=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)

# Example script: app_body_canvas.py

 

9. How to create a main loop ?

# put in the main loop the things that need to be run through again and again in your script

running = 1

while running:
    # #e.g. redraw the screen:
    handle_redraw(())

 

Here are 2 examples of application skeletons that I ususally use:

1. no main loop because the application logic works without

Example script: app_skeleton.py

 

2. with mainloop (if suitable)

Example script: app_skeleton_with_mainloop.py

 

 

 

 

 

 

 

Previous|Next | Menu         Copyright (c) 2006 Jurgen Scheible