如何创建pys60应用程序

信息: 如何创建一个应用程序? 9个步骤

  1. 插入所有需要的模块
  2. 设定屏幕大小 (normal, large, full)
  3. 编写你程序的逻辑代码
  4. 创建一个程序菜单(如果有必要)
  5. 设定一个离开的按键
  6. 设定程序标题
  7. 如果有必要,分配活动的对象
  8. 设定程序主题(文字,背景,列表或什么都没有)
  9. 创建一个恰当的主循环体
  1. 如何装如所需要的所有模块?
    1
    2
    import appuifw
    import e32
  2. 如何设定屏幕大小?
    1
    2
    3
    4
    # 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)
    示例代码: app_screen.py
  3. 如何创建你程序的逻辑结构?
    这个完整的指南就是关于这个问题的…… 你必须确定一些逻辑结构使你的程序运行起来,任何逻辑结构都有可能!
  4. 如何创建一个应用程序菜单?
    一个应用程序菜单使用左边的软按键并使得在你的应用程序运行时总是更够被使用。一个应用程序菜单也能包含子菜单。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # 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)))]
    示例代码: app_menu.py
  5. 如何设定一个离开程序的键盘操作?
    当你按下右键(即离开)时,离开的操作就会被执行。使用特别定义的一个函数,你就能定义在按下键时要做什么。

    1
    2
    3
    def quit():
         appuifw.app.set_exit()
    app.exit_key_handler=quit
  6. 如何设定程序名称(标题)?
    1
    appuifw.app.title = u"SMS sending"
  7. 如果有必要,如何来分配有效的对象?
    A facility called active object is used extensively on the Symbian OS to implement co-operative, non-codeemptive 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!

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 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()

    更详细的内容请查阅 API_Reference_for_Python.pdf 文档。

  8. 如何设置程序主体?
    1
    2
    # body as Listbox:
     appuifw.app.body = appuifw.Listbox(entries,shout)
    示例代码: app_body_listbox.py
    1
    2
    # body as Text:
    appuifw.app.body = appuifw.Text(u'hello')
    示例代码:app_body_text.py
    1
    2
    # body as Canvas:
    appuifw.app.body=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
    示例代码: app_body_canvas.py
  9. 如何创建一个主循环?
    把主循环放置在需要反复运行的代码位置

    1
    2
    3
    4
    running = 1
    while running:
         # #e.g. redraw the screen:
         handle_redraw(())

这里有2个我常用的程序骨架示例

  1. no main loop because the application logic works without
    示例代码: app_skeleton.py
  2. with mainloop (if suitable)
Share

0 Responses to “如何创建pys60应用程序”


  • No Comments

Leave a Reply