PyS60 creating extensions

From OpenSource

Jump to: navigation, search

Contents

[edit] How to build c++ extensions to pys60 for all platforms

[edit] c++ extensions to pys60 1st and 2nd ed platform

This part describes how you can build binaries and create installation package for pys60 c++ extensions on 1st and 2nd ed platform.

[edit] Requirements

* S60 1st or 2rd ed C++ SDK. Download the maintenance release here.
* Pys60 1.3.1 or better SDK. Download here.
* Optionally, install Carbide.c++ express for building for the emulator

Install the C++ SDK typical installation. The pys60 sdk is simply extracted from the .zip file over the C++ SDK directory structure. You can verify that the installation worked by starting the epoc.exe. The python should be in Installation subfolder on the emulator menu.

[edit] Building example extension

In this example, we are using module named uikludges to demostrate how to create and build extension. The uikludges provides functionality to rename the Exit-key label on pys60. For example, it could be renamed to "Back" to support different kind of navigation structure.

[edit] Getting the sources for example

First, we are going to check out the example extension source code. uikludges.zip

[edit] Example code

There are just one interesting file on the example package. The rest of the files are just stuff for building and installing.

* uikludges.cpp: the c++ extension

[edit] Building for phone

To build, simply do following:

% cd symbian\src
% bldmake bldfiles
% abld build armi urel

This will build the binary to <SDK path>\epoc32\release\armi\urel\UIKLUDGES.pyd.

[edit] Verifying extension

After that you can install the UIKLUDGES.pyd on the phone. Use Bluetooth to send it to phone. You can also use Nokia PC Suite to copy it to \system\libs\ directory manually. You can verify that it works by typing this to interactive interpreter:

>>> import uikludges 
>>> uikludges.set_right_softkey_text(u"Back")

[edit] Debugging extensions

Debugging on target is possible using file logging. Use the macros in logger.h to do that. To enable logging, define the __DO_LOGGING__ macro on uikludges.mmp, and create a folder c:\logs\debug to phone.

[edit] c++ extensions to pys60 3rd ed platform

This part describes how you can build binaries and create installation package for pys60 c++ extensions on 3rd ed platform.

[edit] Requirements

* S60 3rd ed C++ SDK. Download the maintenance release here.
* Pys60 1.3.8 or better SDK. Download here.
* Optionally, install Carbide.c++ express for building for the emulator

Install the C++ SDK typical installation. The pys60 sdk is simply extracted from the .zip file over the C++ SDK directory structure. You can verify that the installation worked by starting the epoc.exe. The python should be in Installat. subfolder on the emulator menu.

[edit] Building example extension

In this example, we are using module named uikludges to demostrate how to create and build extension. The uikludges provides functionality to rename the Exit-key label on pys60. For example, it could be renamed to "Back" to support different kind of navigation structure.

[edit] Getting the sources for example

First, we are going to check out the example extension source code. Go ahead and install subversion client if you don't have that already from http://subversion.tigris.org. Then start the command line and type:

% cd <your_work_folder>
% svn export https://pymbian.svn.sourceforge.net/svnroot/pymbian/uikludges/trunk/ uikludges

[edit] Example code

There are two interesting files on the example package. The rest of the files are just stuff for building and installing.

* uikludges.cpp: actual c++ extension
* uikludges.py: extension loader required for 3rd ed


[edit] Building for phone

The C++ SDK shipped with GCCE compiler that is used to build the extensions. To build, simply do following:

% cd symbian\src
% bldmake bldfiles
% abld build gcce urel

This will build the binary to <SDK path>\epoc32\release\gcce\urel\_uikludges.pyd.

Note: If you don't have WINS (Windows Emulator) tool chain installed, you must remove wins from PRJ_PLATFORMS sections in bld.inf. Otherwise you'll get error

% bldmake bldfiles
LINK: missing operand
Try `LINK --help' for more information.
BLDMAKE ERROR: ERROR: failed to find version information for LINK.EXE

[edit] Making installation package

Next we need to make installation package that is used to distribute the files to phone. Take a look at uikludges.pkg. This file defines the files to be installed. Run following commands to build the installation file:

% mkdir _build
% copy <SDK path>\epoc32\release\gcce\urel\_uikludges.pyd _build\
% makesis uikludges.pkg

This will create uikludges.sis file.

[edit] Signing the package

Before we can send the installation package to phone, we need to sign it. In this example, we use self-signing. You can read more about signing from http://symbiansigned.com and http://forum.nokia.com.

In order to use self-signing, we need to generate certificate and private key:

% makekeys -cert -password yourpassword -len 2048 -dname "CN=uikludges OU=Development" mykey.key mycert.cer

Then press keyboard to generate randomness.

Next, we use these keys to sign the package:

% signsis uikludges.sis uikludges.sisx mycert.cer mykey.key yourpassword

Note that the .pkg uses UID which is used to identify the installation package. You can get your own UIDs by logging to http://symbiansigned.com and ordering UIDs. Order them from un-protected range if you plan to use self-signing. Please don't reuse the UIDs, otherwise there will be conflict, and that case the conflicting package cannot be installed.

[edit] Verifying installation package

After that you should have file uikludges.sisx which can be installed on the phone. Use Bluetooth or Nokia PC Suite to install it. You can verify that it works by typing this to interactive interpreter:

>>> import uikludges 
>>> uikludges.set_right_softkey_text(u"Back")

You can use the script build_phone.bat to run these all steps at once. Remember to edit and run init_envs.bat before using that script.

[edit] Building for emulator

Running the example on emulator requires that you install carbide.c++ express. After installation, edit and run the init_envs.bat, then run build_emulator.bat.

[edit] Debugging extensions

Debugging the extensions is quite hard sometimes. For best results, I suggest that you setup debugging in emulator and use carbide.c++. In order to import the extension to carbide, you might need edit file uikludges.mmp and change the line TARGET _uikludges.pyd to _uikludges.dll (otherwise carbide.c++ import fails because it does not know what .pyd extension means). After building, copy the _uikludges.dll to _uikludges.pyd and start debugging.

Debugging on target is possible using file logging. Use the macros in logger.h to do that. To enable logging, define the _DO_LOGGING macro on uikludges.mmp, and create a folder c:\logs\debug to phone.

Personal tools
MediaWiki Resources