s60 python 编程指南—— 如何创建一个应用程序

S60 Python 编程指南—— 如何创建一个应用程序


1,插入所有需要的模块
2,设定屏幕大小 (normal, large, full)
3,编写你程序的逻辑代码
4,创建一个程序菜单(如果有必要)
5,设定一个离开的按键
6,设定程序标题
7,如果有必要,分配活动的对象
8,设定程序主题(文字,背景,列表或什么都没有)
9,创建一个恰当的主循环体


1,如何装如所需要的所有模块?

Python代码
  1. import appuifw   
  2. import e32  
Python代码
  1. import appuifw   
  2. import e32  
import appuifw
import e32


2,如何设定屏幕大小?

Python代码 
  1.   
  2. # screen has 3 different values:   
  3. appuifw.app.screen='normal' #(a normal screen with title pane and softkeys)   
  4. appuifw.app.screen='large' #(only softkeys visible)   
  5. appuifw.app.screen='full' #(a full screen)  
Python代码
  1. # screen has 3 different values:   
  2. appuifw.app.screen='normal' #(a normal screen with title pane and softkeys)   
  3. appuifw.app.screen='large' #(only softkeys visible)   
  4. appuifw.app.screen='full' #(a full screen)  
# 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)


示例代码:
---------------------------------
Python代码
import appuifw   
  1. import e32   
  2. def exit_key_handler():   
  3.     app_lock.signal()   
  4. round = appuifw.Text()   
  5. round.set(u'hello')   
  6. # put the application screen size to full screen   
  7. appuifw.app.screen='full' #(a full screen)   
  8. # other options:   
  9. #appuifw.app.screen='normal' #(a normal screen with title pane and softkeys)   
  10. #appuifw.app.screen='large' #(only softkeys visible)   
  11. app_lock = e32.Ao_lock()   
  12. appuifw.app.body = round   
  13. appuifw.app.exit_key_handler = exit_key_handler   
  14. app_lock.wait()  
Python代码
  1. import appuifw   
  2. import e32   
  3. def exit_key_handler():   
  4.     app_lock.signal()   
  5. round = appuifw.Text()   
  6. round.set(u'hello')   
  7. # put the application screen size to full screen   
  8. appuifw.app.screen='full' #(a full screen)   
  9. # other options:   
  10. #appuifw.app.screen='normal' #(a normal screen with title pane and softkeys)   
  11. #appuifw.app.screen='large' #(only softkeys visible)   
  12. app_lock = e32.Ao_lock()   
  13. appuifw.app.body = round   
  14. appuifw.app.exit_key_handler = exit_key_handler   
  15. app_lock.wait()  
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()


3,如何创建你程序的逻辑结构?
这个完整的指南就是关于这个问题的…… 你必须确定一些逻辑结构使你的程序运行起来,任何逻辑结构都有可能!

4,如何创建一个应用程序菜单?
一个应用程序菜单使用左边的软按键并使得在你的应用程序运行时总是更够被使用。一个应用程序菜单也能包含子菜单。


Python代码
  1. # create the callback functions that shall be executed when when selecting an item in   
  2. # the menu:   
  3. def item1():   
  4.    print "item one"  
  5. def subitem1():   
  6.    print "subitem one"  
  7. def subitem2():   
  8.    print "subitem two"  
  9. # create the menu using appuifw.app.menu[(title, callback1), (title, (subtitle, callback2))]   
  10. appuifw.app.menu = [(u"item 1", item1), (u"Submenu 1", ((u"sub item 1"  
  11. , subitem1),(u"sub item 2", subitem2)))]  
Python代码 复制代码  收藏代码
  1. # create the callback functions that shall be executed when when selecting an item in   
  2. # the menu:   
  3. def item1():   
  4.    print "item one"  
  5. def subitem1():   
  6.    print "subitem one"  
  7. def subitem2():   
  8.    print "subitem two"  
  9. # create the menu using appuifw.app.menu[(title, callback1), (title, (subtitle, callback2))]   
  10. appuifw.app.menu = [(u"item 1", item1), (u"Submenu 1", ((u"sub item 1"  
  11. , subitem1),(u"sub item 2", subitem2)))]  
# 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)))]


示例代码:
---------------------------------
Python代码
  1. import appuifw   
  2. import e32   
  3. def exit_key_handler():   
  4.     app_lock.signal()   
  5. # create the callback functions for the application menu and its submenus   
  6. def item1():   
  7.     print ""   
  8.     round.set(u'item one was selected')   
  9. def subitem1():   
  10.     print ""   
  11.     round.set(u'subitem one was selected')   
  12. def subitem2():   
  13.     round.set(u'subitem two was selected')   
  14. app_lock = e32.Ao_lock()   
  15. round = appuifw.Text()   
  16. round.set(u'press options')   
  17. appuifw.app.screen='large'  
  18. appuifw.app.body = round   
  19. # create the application menu including submenus   
  20. appuifw.app.menu = [(u"item 1", item1),   
  21.                     (u"Submenu 1", ((u"sub item 1", subitem1),   
  22.                                     (u"sub item 2", subitem2)))]   
  23. appuifw.app.exit_key_handler = exit_key_handler   
  24. app_lock.wait()  
Python代码
  1. import appuifw   
  2. import e32   
  3. def exit_key_handler():   
  4.     app_lock.signal()   
  5. # create the callback functions for the application menu and its submenus   
  6. def item1():   
  7.     print ""   
  8.     round.set(u'item one was selected')   
  9. def subitem1():   
  10.     print ""   
  11.     round.set(u'subitem one was selected')   
  12. def subitem2():   
  13.     round.set(u'subitem two was selected')   
  14. app_lock = e32.Ao_lock()   
  15. round = appuifw.Text()   
  16. round.set(u'press options')   
  17. appuifw.app.screen='large'  
  18. appuifw.app.body = round   
  19. # create the application menu including submenus   
  20. appuifw.app.menu = [(u"item 1", item1),   
  21.                     (u"Submenu 1", ((u"sub item 1", subitem1),   
  22.                                     (u"sub item 2", subitem2)))]   
  23. appuifw.app.exit_key_handler = exit_key_handler   
  24. app_lock.wait()  
import appuifw
import e32
def exit_key_handler():
    app_lock.signal()
# create the callback functions for the application menu and its submenus
def item1():
    print ""
    round.set(u'item one was selected')
def subitem1():
    print ""
    round.set(u'subitem one was selected')
def subitem2():
    round.set(u'subitem two 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()


5,如何设定一个离开程序的键盘操作?
当你按下右键(即离开)时,离开的操作就会被执行。使用特别定义的一个函数,你就能定义在按下键时要做什么。

Python代码
  1. def quit():   
  2.         appuifw.app.set_exit()   
  3. app.exit_key_handler=quit  
Python代码
  1. def quit():   
  2.         appuifw.app.set_exit()   
  3. app.exit_key_handler=quit  
def quit():
        appuifw.app.set_exit()
app.exit_key_handler=quit


6,如何设定程序名称(标题)?
Python代码
  1. appuifw.app.title = u"SMS sending"  
Python代码
  1. appuifw.app.title = u"SMS sending"  
appuifw.app.title = u"SMS sending"


7,如果有必要,如何来分配有效的对象?
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!

Python代码
  1. # You need to import the e32 module   
  2. import e32   
  3. # create an instance of the active object   
  4. app_lock = e32.Ao_lock()   
  5. # starts a scheduler -> the script processes events (e.g. from the UI) until lock.signal() is   
  6. # callled.   
  7. app_lock.wait()   
  8. # stops the scheduler   
  9. app_lock.signal()  
Python代码
  1. # You need to import the e32 module   
  2. import e32   
  3. # create an instance of the active object   
  4. app_lock = e32.Ao_lock()   
  5. # starts a scheduler -> the script processes events (e.g. from the UI) until lock.signal() is   
  6. # callled.   
  7. app_lock.wait()   
  8. # stops the scheduler   
  9. app_lock.signal()  
# 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()



8,如何设置程序主体?
Python代码
  1. # body as Listbox:   
  2. appuifw.app.body = appuifw.Listbox(entries,shout)  
Python代码
  1. # body as Listbox:   
  2. appuifw.app.body = appuifw.Listbox(entries,shout)  
# body as Listbox:
appuifw.app.body = appuifw.Listbox(entries,shout)


示例代码:
------------------------------------------------
Python代码
  1. import appuifw   
  2. import e32   
  3. def exit_key_handler():   
  4.     app_lock.signal()   
  5. # define a callback function   
  6. def shout():   
  7.     index = lb.current()   
  8.     print index   
  9.     print entries[index]   
  10. # create your content list of your listbox including the icons to be used for each entry   
  11. entries = [u"Signal",u"Battery"]   
  12. lb = appuifw.Listbox(entries,shout)   
  13. # create an Active Object   
  14. app_lock = e32.Ao_lock()   
  15. # create an instance of appuifw.Listbox(), include the content list "entries" and the callback function "shout"   
  16. # and set the instance of Listbox now as the application body   
  17. appuifw.app.body = lb   
  18. appuifw.app.exit_key_handler = exit_key_handler   
  19. app_lock.wait()  
Python代码
  1. import appuifw   
  2. import e32   
  3. def exit_key_handler():   
  4.     app_lock.signal()   
  5. # define a callback function   
  6. def shout():   
  7.     index = lb.current()   
  8.     print index   
  9.     print entries[index]   
  10. # create your content list of your listbox including the icons to be used for each entry   
  11. entries = [u"Signal",u"Battery"]   
  12. lb = appuifw.Listbox(entries,shout)   
  13. # create an Active Object   
  14. app_lock = e32.Ao_lock()   
  15. # create an instance of appuifw.Listbox(), include the content list "entries" and the callback function "shout"   
  16. # and set the instance of Listbox now as the application body   
  17. appuifw.app.body = lb   
  18. appuifw.app.exit_key_handler = exit_key_handler   
  19. app_lock.wait()  
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()



Python代码
  1. # body as Text:   
  2. appuifw.app.body = appuifw.Text(u'hello')  
Python代码
  1. # body as Text:   
  2. appuifw.app.body = appuifw.Text(u'hello')  
# body as Text:
appuifw.app.body = appuifw.Text(u'hello')

示例代码:
------------------------------------------------

Python代码
  1. import appuifw   
  2. import e32   
  3. def exit_key_handler():   
  4.     app_lock.signal()   
  5. # create an instance of appuifw.Text()   
  6. round = appuifw.Text()   
  7. # change the style of the text   
  8. round.style = appuifw.STYLE_UNDERLINE   
  9. # set the text to 'hello'   
  10. round.set(u'hello')   
  11. # put the screen size to full screen   
  12. appuifw.app.screen='full'    
  13. # create an Active Object   
  14. app_lock = e32.Ao_lock()   
  15. # set the application body to Text   
  16. # by handing over "round" which is an instance of appuifw.Text() as definded above   
  17. appuifw.app.body = round   
  18. appuifw.app.exit_key_handler = exit_key_handler   
  19. app_lock.wait()  
Python代码
  1. import appuifw   
  2. import e32   
  3. def exit_key_handler():   
  4.     app_lock.signal()   
  5. # create an instance of appuifw.Text()   
  6. round = appuifw.Text()   
  7. # change the style of the text   
  8. round.style = appuifw.STYLE_UNDERLINE   
  9. # set the text to 'hello'   
  10. round.set(u'hello')   
  11. # put the screen size to full screen   
  12. appuifw.app.screen='full'    
  13. # create an Active Object   
  14. app_lock = e32.Ao_lock()   
  15. # set the application body to Text   
  16. # by handing over "round" which is an instance of appuifw.Text() as definded above   
  17. appuifw.app.body = round   
  18. appuifw.app.exit_key_handler = exit_key_handler   
  19. app_lock.wait()  
import appuifw
import e32
def exit_key_handler():
    app_lock.signal()
# create an instance of appuifw.Text()
round = appuifw.Text()
# change the style of the text
round.style = appuifw.STYLE_UNDERLINE
# set the text to 'hello'
round.set(u'hello')
# put the screen size to full screen
appuifw.app.screen='full' 
# create an Active Object
app_lock = e32.Ao_lock()
# set the application body to Text
# by handing over "round" which is an instance of appuifw.Text() as definded above
appuifw.app.body = round
appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()



Python代码 
  1. # body as Canvas:   
  2. appuifw.app.body=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)  
Python代码    # body as Canvas:   
  1. appuifw.app.body=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)  
# body as Canvas:
appuifw.app.body=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)


示例代码:
---------------------------------------------
Python代码 
  1. # Copyright (c) 2005 Jurgen Scheible   
  2. # This script draws different shapes and text to the canvas   
  3. import appuifw   
  4. from appuifw import *   
  5. import e32   
  6. # import graphics   
  7. from graphics import *   
  8. # create an exit handler   
  9. def quit():   
  10.     global running   
  11.     running=0  
  12.     appuifw.app.set_exit()   
  13. # set the screen size to large   
  14. appuifw.app.screen='large'  
  15. # define an initial image (white)   
  16. img=Image.new((176,208))   
  17. # add different shapes and text to the image   
  18. # coord. sequence x1,x2,y1,y2   
  19. img.line((20,20,20,120),0xff00ee)   
  20. img.rectangle((40,60,50,80),0xff0000)   
  21. img.point((50.,150.),0xff0000,width=40)   
  22. img.ellipse((100,150,150,180),0x0000ff)   
  23. img.text((100,80), u'hello')   
  24. # define your redraw function (that redraws the picture on and on)   
  25. # in this case we redraw the image named img using the blit function   
  26. def handle_redraw(rect):   
  27.     canvas.blit(img)   
  28. running=1  
  29. # define the canvas, include the redraw callback function   
  30. canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)   
  31. # set the app.body to canvas   
  32. appuifw.app.body=canvas   
  33. app.exit_key_handler=quit   
  34. # create a loop to redraw the the screen again and again until the exit button is pressed   
  35. while running:   
  36.     # redraw the screen   
  37.     handle_redraw(())   
  38.     # yield needs to be here in order that key pressings can be noticed   
  39.     e32.ao_yield()  
Python代码   
  1. # Copyright (c) 2005 Jurgen Scheible   
  2. # This script draws different shapes and text to the canvas   
  3. import appuifw   
  4. from appuifw import *   
  5. import e32   
  6. # import graphics   
  7. from graphics import *   
  8. # create an exit handler   
  9. def quit():   
  10.     global running   
  11.     running=0  
  12.     appuifw.app.set_exit()   
  13. # set the screen size to large   
  14. appuifw.app.screen='large'  
  15. # define an initial image (white)   
  16. img=Image.new((176,208))   
  17. # add different shapes and text to the image   
  18. # coord. sequence x1,x2,y1,y2   
  19. img.line((20,20,20,120),0xff00ee)   
  20. img.rectangle((40,60,50,80),0xff0000)   
  21. img.point((50.,150.),0xff0000,width=40)   
  22. img.ellipse((100,150,150,180),0x0000ff)   
  23. img.text((100,80), u'hello')   
  24. # define your redraw function (that redraws the picture on and on)   
  25. # in this case we redraw the image named img using the blit function   
  26. def handle_redraw(rect):   
  27.     canvas.blit(img)   
  28. running=1  
  29. # define the canvas, include the redraw callback function   
  30. canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)   
  31. # set the app.body to canvas   
  32. appuifw.app.body=canvas   
  33. app.exit_key_handler=quit   
  34. # create a loop to redraw the the screen again and again until the exit button is pressed   
  35. while running:   
  36.     # redraw the screen   
  37.     handle_redraw(())   
  38.     # yield needs to be here in order that key pressings can be noticed   
  39.     e32.ao_yield()  
# Copyright (c) 2005 Jurgen Scheible
# This script draws different shapes and text to the canvas
import appuifw
from appuifw import *
import e32
# import graphics
from graphics import *
# create an exit handler
def quit():
    global running
    running=0
    appuifw.app.set_exit()
# set the screen size to large
appuifw.app.screen='large'
# define an initial image (white)
img=Image.new((176,208))
# add different shapes and text to the image
# coord. sequence x1,x2,y1,y2
img.line((20,20,20,120),0xff00ee)
img.rectangle((40,60,50,80),0xff0000)
img.point((50.,150.),0xff0000,width=40)
img.ellipse((100,150,150,180),0x0000ff)
img.text((100,80), u'hello')
# define your redraw function (that redraws the picture on and on)
# in this case we redraw the image named img using the blit function
def handle_redraw(rect):
    canvas.blit(img)
running=1
# define the canvas, include the redraw callback function
canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
# set the app.body to canvas
appuifw.app.body=canvas
app.exit_key_handler=quit
# create a loop to redraw the the screen again and again until the exit button is pressed
while running:
    # redraw the screen
    handle_redraw(())
    # yield needs to be here in order that key pressings can be noticed
    e32.ao_yield()


9,如何创建一个主循环?

把主循环放置在需要反复运行的代码位置
Python代码 
  1. 1.   running = 1    
  2. 2.   while running:   
  3. 3.        # #e.g. redraw the screen:   
  4. 4.        handle_redraw(())  
Python代码   
  1. 1.   running = 1    
  2. 2.   while running:   
  3. 3.        # #e.g. redraw the screen:   
  4. 4.        handle_redraw(())  
1.   running = 1 
2.   while running:
3.        # #e.g. redraw the screen:
4.        handle_redraw(())



示例代码:
---------------------------------
Python代码  # Copyright (c) 2006 Jurgen Scheible   
  1. # Application skeleton (no main loop)   
  2. import appuifw   
  3. import e32   
  4. appuifw.app.screen='large'  
  5. # create your application logic ...   
  6. def item1():   
  7.     print "hello"  
  8. def subitem1():   
  9.     print "aha"  
  10. def subitem2():   
  11.     print "good"  
  12. appuifw.app.menu = [(u"item 1", item1),   
  13.                     (u"Submenu 1", ((u"sub item 1", subitem1),   
  14.                                     (u"sub item 2", subitem2)))]       
  15. def exit_key_handler():   
  16.     app_lock.signal()   
  17. appuifw.app.title = u"drawing"       
  18. app_lock = e32.Ao_lock()   
  19. appuifw.app.body = ...    
  20. appuifw.app.exit_key_handler = exit_key_handler   
  21. app_lock.wait()   
  22. """ description:  
  23. # 1. import all modules needed  
  24. import appuifw  
  25. import e32  
  26. # 2. set the screen size to large  
  27. appuifw.app.screen='large'  
  28. # 3. create your application logic ...  
  29. # e.g. create all your definitions (functions) or classes and build instances of them or call them etc.  
  30. # ...... application logic ....  
  31. # 4. create the application menu including submenus  
  32. # create the callback functions for the application menu and its submenus  
  33. def item1():  
  34.     print ""  
  35.     round.set(u'item one was selected')  
  36. def item1():  
  37.     print "hello"  
  38. def subitem1():  
  39.     print "aha"  
  40. def subitem2():  
  41.     print "good"  
  42. appuifw.app.menu = [(u"item 1", item1),  
  43.                     (u"Submenu 1", ((u"sub item 1", subitem1),  
  44.                                     (u"sub item 2", subitem2)))]  
  45.     # 5. create and set an exit key handler  
  46. def exit_key_handler():  
  47.     app_lock.signal()  
  48. # 6. set the application title  
  49. appuifw.app.title = u"drawing"      
  50. # 7. crate an active objects   
  51. app_lock = e32.Ao_lock()  
  52. # 8. set the application body   
  53. appuifw.app.body = ...   
  54. # no main loop  
  55. appuifw.app.exit_key_handler = exit_key_handler  
  56. app_lock.wait()  
  57. """  
Python代码   
  1. # Copyright (c) 2006 Jurgen Scheible   
  2. # Application skeleton (no main loop)   
  3. import appuifw   
  4. import e32   
  5. appuifw.app.screen='large'  
  6. # create your application logic ...   
  7. def item1():   
  8.     print "hello"  
  9. def subitem1():   
  10.     print "aha"  
  11. def subitem2():   
  12.     print "good"  
  13. appuifw.app.menu = [(u"item 1", item1),   
  14.                     (u"Submenu 1", ((u"sub item 1", subitem1),   
  15.                                     (u"sub item 2", subitem2)))]       
  16. def exit_key_handler():   
  17.     app_lock.signal()   
  18. appuifw.app.title = u"drawing"       
  19. app_lock = e32.Ao_lock()   
  20. appuifw.app.body = ...    
  21. appuifw.app.exit_key_handler = exit_key_handler   
  22. app_lock.wait()   
  23. """ description:  
  24. # 1. import all modules needed  
  25. import appuifw  
  26. import e32  
  27. # 2. set the screen size to large  
  28. appuifw.app.screen='large'  
  29. # 3. create your application logic ...  
  30. # e.g. create all your definitions (functions) or classes and build instances of them or call them etc.  
  31. # ...... application logic ....  
  32. # 4. create the application menu including submenus  
  33. # create the callback functions for the application menu and its submenus  
  34. def item1():  
  35.     print ""  
  36.     round.set(u'item one was selected')  
  37. def item1():  
  38.     print "hello"  
  39. def subitem1():  
  40.     print "aha"  
  41. def subitem2():  
  42.     print "good"  
  43. appuifw.app.menu = [(u"item 1", item1),  
  44.                     (u"Submenu 1", ((u"sub item 1", subitem1),  
  45.                                     (u"sub item 2", subitem2)))]  
  46.     # 5. create and set an exit key handler  
  47. def exit_key_handler():  
  48.     app_lock.signal()  
  49. # 6. set the application title  
  50. appuifw.app.title = u"drawing"      
  51. # 7. crate an active objects   
  52. app_lock = e32.Ao_lock()  
  53. # 8. set the application body   
  54. appuifw.app.body = ...   
  55. # no main loop  
  56. appuifw.app.exit_key_handler = exit_key_handler  
  57. app_lock.wait()  
  58. """  
# Copyright (c) 2006 Jurgen Scheible
# Application skeleton (no main loop)
import appuifw
import e32
appuifw.app.screen='large'
# create your application logic ...
def item1():
    print "hello"
def subitem1():
    print "aha"
def subitem2():
    print "good"
appuifw.app.menu = [(u"item 1", item1),
                    (u"Submenu 1", ((u"sub item 1", subitem1),
                                    (u"sub item 2", subitem2)))]    
def exit_key_handler():
    app_lock.signal()
appuifw.app.title = u"drawing"    
app_lock = e32.Ao_lock()
appuifw.app.body = ... 
appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()
""" description:
# 1. import all modules needed
import appuifw
import e32
# 2. set the screen size to large
appuifw.app.screen='large'
# 3. create your application logic ...
# e.g. create all your definitions (functions) or classes and build instances of them or call them etc.
# ...... application logic ....
# 4. create the application menu including submenus
# create the callback functions for the application menu and its submenus
def item1():
    print ""
    round.set(u'item one was selected')
def item1():
    print "hello"
def subitem1():
    print "aha"
def subitem2():
    print "good"
appuifw.app.menu = [(u"item 1", item1),
                    (u"Submenu 1", ((u"sub item 1", subitem1),
                                    (u"sub item 2", subitem2)))]
    # 5. create and set an exit key handler
def exit_key_handler():
    app_lock.signal()
# 6. set the application title
appuifw.app.title = u"drawing"    
# 7. crate an active objects 
app_lock = e32.Ao_lock()
# 8. set the application body 
appuifw.app.body = ... 
# no main loop
appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()
"""


2.    with mainloop (if suitable)

Python代码 
  1. # Copyright (c) 2006 Jurgen Scheible   
  2. # Application skeleton with main loop (while loop)   
  3.   
  4.   
  5. import appuifw   
  6. import e32   
  7.   
  8.   
  9. appuifw.app.screen='large'  
  10.   
  11.   
  12. # create your application logic ...   
  13.   
  14.   
  15. running=1  
  16.   
  17. def quit():   
  18.     global running   
  19.     running=0  
  20.        
  21. app.exit_key_handler=quit   
  22.   
  23. appuifw.app.title = u"drawing"  
  24.   
  25. appuifw.app.body= ...   
  26.   
  27.   
  28. while running:   
  29.     # handle_redraw(())   
  30.     e32.ao_sleep(0.5)   
  31.   
  32.   
  33.   
  34.   
  35.   
  36. """ description:  
  37.  
  38. # 1. import all modules needed  
  39. import appuifw  
  40. import e32  
  41.  
  42. # 2. set the screen size to large  
  43. appuifw.app.screen='large'  
  44.  
  45.  
  46.  
  47. # 3. create your application logic ...  
  48. # e.g. create all your definitions (functions) or classes and build instances of them or call them etc.  
  49. # ...... application logic ....  
  50.  
  51. running=1  
  52.  
  53.  
  54.  
  55. # 4. no application menu here neccessary  
  56.  
  57. # 5. create and set an exit key handler: when exit ley is pressed, the main loop stops going (because the variable running will be put to 0=  
  58. def quit():  
  59.     global running  
  60.     running=0  
  61.       
  62. app.exit_key_handler=quit  
  63.  
  64. # 6. set the application title  
  65. appuifw.app.title = u"drawing"  
  66.  
  67. # 7. no active objects needed  
  68.  
  69. # 8. set the application body   
  70. appuifw.app.body= ...  
  71.  
  72. # 9. create a main loop (e.g. redraw the the screen again and again)  
  73. while running:  
  74.     # #put here things that need to be run through again and again  
  75.     # #e.g. redraw the screen:  
  76.     # handle_redraw(())  
  77.     # yield needs to be here e.g. in order that key pressings can be noticed  
  78.     e32.ao_yield()  
  79.  
  80.  
  81. """
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值