Symbian developer community

wiki

Python Quick Start

From Symbian Developer Community

Jump to: navigation, search

This Quick Start document provides information on how to begin developing Python applications for the Symbian platform. At the end of the tutorial you will have installed Python (PyS60 v1.9.7 beta release) on your phone or Emulator, written a basic helloworld application and run it on the phone both from the interactive shell script and as a stand-alone application.

If you are completely new to Python we recommend you start your development on the desktop - by taking the short course Dive Into Python or working through the tutorial: Python Programming for the Non Programmer.

Comes with Code: File:PythonHelloWorld.zip

Contents

Setting Up Your Development Environment

Python applications ("scripts") are simply text files containing code written in the Python programming language and named with the file extension ".py". The scripts can be written in any text editor and can be run either from within the Python Interactive Shell application on a device or the emulator, or as standalone applications on your mobile device.

Getting PyS60

The Python files are stored on the Maemo Garage - descriptions are provided for all files in the Python Technical Overview.

Windows developers need the following files for this tutorial:

  • PythonForS60_1.9.7_Setup.exe - Windows Installer
  • Python_1.9.7_3rdFP2_SDK_with_OpenC.zip - Patch over SDK to support Python development

Mac and Linux developers need the following file instead:

  • PythonForS60_1.9.7.tar.gz - Mac/Linux archive

Setting up your Computer

The development environment consists of the Python reference documentation, the Application packager for making your scripts into stand-alone applications and the phone SIS files. Run the following setup file to install on windows, or unzip the archive to install on Mac/Linux:

  • (Windows) PythonForS60_1.9.7_Setup.exe
  • (Mac/Linux) PythonForS60_1.9.7.tar.gz

On Windows the tools/documentation are accessible from a start menu option: Start | Programs | PythonForS60 1.9.7. Mac/Linux users will need to execute files directly (ie run the Application Packager by executing ensymble_gui.py).

You will need to install the Python for your desktop in order to use the Application Packager. This can be obtained from here: Python 2.5.4.

A text editor is used for writing scripts. You can use any one you like, including Windows Notepad. We recommend a syntax-aware editor like Notepad ++.


Note
While you can write code in the classic Python python.org/idle IDLE IDE, it is not possible to run code that depends on PyS60-specific libraries from this or other IDEs. They must be run in the S60 emulator or on the target device.


Installing Python on your Phone

The easiest way to test your Python application is to run it on a real phone. PyS60 v1.9.7 is compatible with any Symbian device (based on Symbian^1 or earlier S60 3rd Edition devices). If you don't have a compatible phone, don't worry - the following section explains how you can run your scripts on the Windows-hosted Symbian platform emulator.

The SIS you need are available in the directory \PythonForS60\PyS60Dependencies\ of your Python installation (Windows users can open the directory from the start menu).

Using your PC Suite software, install the following files to your Symbian device (based on Symbian^1 or S60 3rd Edition):

  • Python_1.9.7.sis - The PyS60 runtime
  • PythonScriptShell_1.9.7_3_2.sis - Python Interactive Shell application for Symbian^1 and S60 3rd Edition FP2 (and later). PythonScriptShell_1.9.7_3_0.sis should be used for earlier S60 3rd Edition devices.

You can verify the installation by launching the Python icon from the device Installations folder. If you do menu Options | Run Script, you can select some pre installed scripts to demonstrate the power of python! The icon and list of applications are shown below:

    Installing Python on your Symbian Emulator

    Install the following files (in order):

    • S60_5th_Edition_SDK_v1_0_en.zip (Symbian^1 Application Development Kit)
    • Python_1.9.7_3rdFP2_SDK_with_OpenC.zip (Python patch, including C/C++ compatibility layers.)

    Note that you'll first need to unzip the SDK to a temporary directory, and then run setup.exe. The patch will then need to be unzipped over the SDK, so that it overwrites the SDK's \epoc32\ directory. Accept all prompts during unzipping to allow this to happen.

    On first use, the SDK will prompt you to register it. The process is straight forward, but you will need to sign up with Forum Nokia if you haven't already.

    You can launch the Emulator by clicking on the file [SDK]/epoc32/release/winscw/udeb/epoc.exe. You then navigate to the Python icon in the Emulator in the same way as you did on the device.

    Your first script

    The very simple script below asks the user for their name, then displays a dialog with the text: "Hello Name, welcome to Python World."

     
    # import the app user interface framework module
    import appuifw
     
    # create a single-field dialog (text input field): appuifw.query(label, type)
    data = appuifw.query(u"Type your name", "text")
     
    # create an information note: appuifw.note(label, type)
    appuifw.note(u"Hello "+str(data)+", welcome to Python World", "info")
     

    Copy this text into your preferred text editor and then save the file as Helloworld.py (the ".py" extension is used for uncompiled python scripts).

    If you're using the interactive shell for testing, you need to copy the file to \Data\Python\ on any drive. For the device you can copy the file directly into the correct folder using PC Suite, or send it as a message with Bluetooth and then move it to the correct folder, using a file manager application (YBrowser - recommended). If you're using the emulator you can copy it direct into the appropriate folder - [SDK]/epoc32/winscw/c/data/python.

    You can then test your script in the same way you verified the Python installation - by launching the "Python1.9.7" icon for the interactive shell, then doing "Options | Run Script" and selecting it from the list.

    That's it. You now have Python on your device and/or your Emulator, and know how to launch scripts. The next section shows how you can package your script as an application.

    Making a Standalone Application

    Scripts are ideal for testing because they can be quickly and easily modified. However, an application should be distributed in the form of an installable SIS file. This applies even more when the application has external resource files that have to be distributed with it.

    For PyS60 1.9.7 you can use the Application Packager to create your Symbian installation (.sis) file. Note that the Application Packager is itself a Python application, so you will first need to install Python on your Windows PC from here.

    Once Python is installed, you can launch the Packager by double clicking the icon in your Python for S60 directory: \PythonForS60\ensymble_gui.py or by selecting the Windows Start menu option: Start | PythonForS60 1.9.7 | PyS60 Application Packager.

      The application initially opens in a minimal view (Figure 3), in which you can specify either a single file or a folder that you want to package as an application, and whether you want the package to be created if the packager can't find a dependency. Brows to the Helloworld.py script we created earlier, then Press Create to make the SIS file.

      The Helloworld_v1_0_0.sis installation file is created in the same directory as your script file. The packager will then give you the option to install the application or to open the folder in which it is located. If you have PC Suite running you can then install the file directly.


      Note
      The file is created with a version number of 1.0.0, a UID in the development range, and will be self-signed. This is suitable for testing, but if you wanted to distribute the file you would need to make some changes. There are detailed instructions on how to do so in the wiki book Python on Symbian.


      Summary

      This Quick Start tutorial has shown you how to get set up with Python on the Symbian platform, from getting the developer environment through to making standalone applications.

      Related Information

      There are plenty of public domain resources to help you get started on learning generic Python, and the PyS60 flavour in particular:

      Sign in to comment…

      Contents

      Stichbury said...

      This page is really nice - the adjustment to separate out the Getting Started material from the technology background has worked well. Thanks!

      However, should it perhaps be "Comes with Code" as well? Then you can distribute the example script (however simplistic it is). I've done that for the Flash Lite example.

      --Stichbury 14:09, 31 July 2009 (BST)

      Hamishwillee said...

      Thank you. Done. Also updated to v1.9.7 (just came out) and made less windows-centric

      --Hamishwillee 02:18, 10 August 2009 (BST)

      Sreenathkg said...

      Hi, Need help please.

      I am using windows OS in my system and NOKIA 5800 handset. I have installed the apps as specified above.

      In system: PythonForS60_1.9.7_Setup Python 3.1

      In mobile: PythonScriptShell_1.9.7

      In mobile it is working perfectly.

      But in my system, I am not able to open Start -> PythonForS60 1.9.7 -> PyS60 Application Packager. I clicked on this. But no windows opened.

      I uninstalled python 3.1 from system. And tried to open Application Packager. Then it is throwing error "windows could not find application to open this type of files".

      What should I do now? Please help.

      Thanks Sreenath

      --Sreenathkg 12:13, 20 August 2009 (BST)

      Stichbury said...

      Hi Sreenathkg

      It would probably be better if you posted your question in the discussion forum related to Python development. More people view that and are able to help you. You can find the forum here.


      --Stichbury 15:03, 20 August 2009 (BST)

      Hamishwillee said...

      @Sreenathkg As Jo says, try the forums in future please. I suspect your problem is that the application packager is a Python 2.5.4 applications, which you need installed on your windows PC (installing will automatically set up correct paths). This is covered above

      --Hamishwillee 00:52, 21 August 2009 (BST)

      Sreenathkg said...

      I think as this is beta "Forum is just getting filled"...

      --Sreenathkg 22:20, 21 August 2009 (BST)

      Stichbury said...

      You're right, it is a bit quiet on the forums, but Pankaj (aka "Croozeus") does check them and we're hoping others do too. If you post, you'll be one of the first on the forum, and will be helping us to start the ball rolling. Thanks!

      --Stichbury 08:31, 22 August 2009 (BST)