`
crazier9527
  • 浏览: 1014362 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

阅读更多

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

 

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

     

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

       

      1. def quit():
      2.         appuifw.app.set_exit()
      3. app.exit_key_handler=quit
    13. 如何设定程序名称(标题)?
      1. appuifw.app.title = u"SMS sending"
    14. 如果有必要,如何来分配有效的对象?
      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!

       

      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()

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

    15. 如何设置程序主体?
      1. # body as Listbox:
      2. appuifw.app.body = appuifw
      3. .Listbox(entries,shout)
        示例代码:
        ------------------------------------------------
        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()
        --------------------------------------
        1. # body as Text:
        2. appuifw.app.body = appuifw.Text(u'hello')
        示例代码:
        ------------------------------------
        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()
        ---------------------------------------------
        1. # body as Canvas:
        2. appuifw.app.body=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
        示例代码:
        ---------------------------------------------
        # 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.   如何创建一个主循环?
        把主循环放置在需要反复运行的代码位置
        1.   running = 1
        2.   while running:
        3.        # #e.g. redraw the screen:
        4.        handle_redraw(())

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

        1. no main loop because the application logic works without
          示例代码:
          ---------------------------------
          # 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编程之PyS60编程课程

    Python编程之PyS60是针对S60平台的Python应用开发课程,旨在教会开发者如何利用Python语言在诺基亚S60智能手机上构建应用程序。PyS60是由Python for S60(简称Pys60)项目提供的,它是一个移植版的Python解释器,...

    pys60例子程序_丰富而全面的例子_新手入门宝典

    Python for S60,简称PYS60,是诺基亚公司推出的一种在S60智能手机平台上运行Python编程语言的环境。这个平台允许开发者使用Python语言编写应用程序,为S60手机用户提供了丰富的功能和便捷的开发体验。"pys60例子...

    pys60-1.4.5_src.zip_PYS60_pys60-1.4.5_python for s60_python 源_s6

    PYS60,全称为Python for Series 60,是一个专为诺基亚S60平台设计的Python解释器,允许用户在S60智能手机上运行Python脚本,极大地扩展了设备的应用潜力。本次分享的是PYS60的1.4.5版本源代码,这个版本在社区中...

    PyS60库参考中文手册V1.4.1基于Python2.2.2最终版

    此外,还有`s60appuifw`模块用于创建应用程序框架,`s60symbianos`模块则提供了访问操作系统级别的功能,如电话、短信、蓝牙等。 手册中详细解释了这些模块的使用方法,包括每个函数的参数、返回值和可能的异常。...

    pys60百例pys60百例

    总的来说,“pys60百例”是Pys60学习者的宝典,它通过实例化教学,帮助用户快速上手,深入理解Pys60的编程实践,为S60平台的Python应用开发打开了一扇窗。无论你是初学者还是资深开发者,都应该充分利用这个资源,...

    python s60 手机编程

    1. **环境设置**:安装Python for S60的SDK,通常包括Python解释器、集成开发环境(IDE)如PyS60 Editor,以及必要的开发工具和文档。开发者需要在模拟器或实际设备上配置Python环境,以便进行测试和调试。 2. **...

    Python_API.tar.gz_Python A_pys60 a_python_python api中文_symbian a

    pys60 是一个 Python 的移植版本,专为塞班(Symbian)操作系统设计,使得开发者能够使用 Python 语言在智能手机上创建应用程序。 Python API 在这里指的是 pys60 的 API 文档或库,这可能包括类、函数、模块和接口...

    PyS60 1.9.7

    PyS60,全称为Python for Series 60,是一个为Symbian OS平台量身定制的Python解释器,使得开发者能够利用Python的强大功能来构建S60设备的应用程序。在1.9.7这个版本中,我们看到了对Symbian OS 9的支持,涵盖了S60...

    PyS60 1.4.5

    在PyS60 1.4.5中,开发者可以利用Python的面向对象编程特性,创建复杂的程序结构,同时享受S60设备的硬件特性,如摄像头、GPS、蓝牙等。此外,通过Python的网络库,开发者还可以构建网络应用,实现数据交换和远程...

    Python S60 百例

    1. **环境搭建**:首先,你需要了解如何在S60设备上安装Python for S60的环境,包括Python解释器、编译器和相关的开发工具,如PyS60 SDK。 2. **基本语法**:Python的基础语法,如变量声明、数据类型(整型、浮点型...

    python for s60

    PyS60允许开发者利用Python语言的强大功能来创建高效且易用的应用程序,这为那些熟悉Python但不熟悉传统移动开发语言(如Symbian C++或Java ME)的开发者提供了一个便捷的入口。 #### 移动应用开发面临的挑战 尽管...

    Getting_Started_with_Python

    运行Python脚本是Pys60的核心功能之一,无论是简单的测试脚本还是复杂的应用程序,都可以通过Pys60在S60设备上执行。 #### 4.3 使用交互式控制台 交互式控制台允许用户实时输入Python代码并立即查看结果,非常适合...

    python for s60 document

    它允许开发者利用Python编写应用程序,并在S60智能手机上运行。该文档介绍了如何安装Python运行时及其依赖项,以及如何打包示例应用。同时,文档详细地介绍了各个模块的功能和服务,涵盖了系统服务、用户界面与图形...

    如何将S60上的py文件打包成SIS安装文件

    3. **创建项目文件**: 使用Python for S60的打包工具,如PyS60 Installer或者OpenSignedOnline,创建一个描述你应用的XML配置文件(.sisxinfo或.app文件),这个文件会定义应用的元数据,如名称、版本和图标。...

    pys60的环境部署

    Pys60是一个为Symbian S60平台设计的Python开发环境,它使得开发者能够利用Python语言开发Symbian S60系统的应用程序。本文档主要介绍了如何搭建Pys60的开发环境以及如何通过特定工具链来构建S60平台上的Python应用...

    PyS60 Library Reference

    **PyS60**是专门为Symbian操作系统设计的一个Python实现版本,它极大地简化了应用程序开发过程,并为Symbian C++ API提供了一个脚本解决方案。此文档是针对**Python for S60** 1.4.1最终版编写的,该版本基于Python ...

    python for s60 socket实例

    pys60 实例 import time,socket,thread,sys,copy import appuifw,e32 ......

    py60开发资料

    PyS60,作为Python在诺基亚S60平台上的实现,为移动设备带来了强大的编程能力。它结合了Python的灵活性和S60的广泛应用场景,使得开发者能够轻松创建功能丰富的应用程序,包括GUI界面的交互式应用。以下是对PyS60...

Global site tag (gtag.js) - Google Analytics