Python Framework for Symbian Series 60 phones

Thursday 26 October 2006

Journal

A new Python release has been published on 2006-10-24. This release offers the same functionnalities than the previous version with major bugs fixed like access to calendar and sms...

So I had to install everything again and so little testing

Thursday 19 October 2006

Journal

Today, tired of using the file explorer to run python scripts, I decided to modify the default.py file to be able to have my scripts in Options > Run script and then final be able to see proper errors outputs. default.py is the first script executed when running Python.

Then at my big surprise, I reallized at line 80

if(e32.s60_version_info >= (3,0)):
    script_dirs = [(u'c:','c:\\python'),
                   (u'e:','e:\\python')]      < ---- check this out!

Excellent isn't it? So now we just need to create a python folder in the memory card (e: drive) and use for example OBEX file transfer to push a script in this folder.

Voila!

Wednesday 18 October 2006

Journal

Yesterday and today I've installed the new Python release for both 2nd & 3rd edition emulators. I updated header and compiled the previous PyS60crypto library. So both environment are ready to use now.

I've been through long fight yesterday also with the winscw compiler for 3rd edition when compiling for emulator. Some environment variables need to be set, the SDK installer doesn't do it for us.

MWCSym2Includes = C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\MSL\MSL_C\MSL_Common\Include; C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\MSL\MSL_C\MSL_Win32\Include; C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\MSL\MSL_C\MSL_X86; C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\MSL\MSL_C++\MSL_Common\Include; C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\MSL\MSL_Extras\MSL_Common\Include; C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\MSL\MSL_Extras\MSL_Win32\Include; C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\Win32-x86 Support\Headers\Win32 SDK

MWSym2Libraries = C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\Win32-x86 Support\Libraries\Win32 SDK;C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Support\Runtime\Runtime_x86\Runtime_Win32\Libs

MWSym2LibraryFiles = MSL_All_MSE_Symbian_D.lib;gdi32.lib;user32.lib;kernel32.lib;

Insert in Path: after Perl entry: C:\Nokia\Tools\Carbide_vs\WINSCW\Symbian_Tools\Command_Line_Tools

I'm now testing the new features of the API.

Monday 16 October 2006

Journal

Today I published Pys60cypto v0.1 with source installation packages, Apache 2 license hoping that nobody will loose as much time as I did :D

I also added the download manager page to the website so there's a new menu in the side bar. That will be helpful to keep a track on the packages.

Journal

Last week we found out with Jouni how to workaround the problem of static datain dll for 1st and 2nd edition. It's quite simple... when we know how to do. Here are the big lines: If we need to have SHA224type and SHA256type as global reference (static data) for all our functions we start with

/*
=============================================================================================
This structure embeed all the static object definition we would need. That will allow use to 
use TLS
=============================================================================================
*/
struct myWrapper
{
    PyTypeObject SHA224type;
    PyTypeObject SHA256type;
};

Then we'll create constant structures for both type:

const PyTypeObject SHA224typeConst =
        {
        PyObject_HEAD_INIT(NULL)
        0,			            /*ob_size*/
        "pys60crypto.sha224",       /*tp_name*/
        ...
        };
 
const PyTypeObject SHA256typeConst =
        {
        PyObject_HEAD_INIT(NULL)
        0,			            /*ob_size*/
        "pys60crypto.sha256",       /*tp_name*/
        ...
        };

Now we are about to set those data in the Tls:

PyMODINIT_FUNC init_sha256(void)
    {
    PyObject *m;
    /* first we create a pointer to a new myWrapper structure */
    struct myWrapper* xx = new struct myWrapper;
 
    if (xx)
        {
        /* now we copy the data of SHA224typeConst & SHA256typeConst to the structure that will 
        be accessible from every functions */
        memcpy((PyTypeObject*)&xx->SHA224type, (PyTypeObject*) &SHA224typeConst, sizeof(SHA224typeConst));
        memcpy((PyTypeObject*)&xx->SHA256type, (PyTypeObject*) &SHA256typeConst, sizeof(SHA256typeConst));
 
        /* finaly we try to set the TLS with the myWrapper structure */
        TRAPD(err, Dll::SetTls(xx));
        if (err != KErrNone)
            {
            return;
            }
        ....

Quite simple isn't it? Only 3 weeks to figure that out :D

Tuesday 10 October 2006

Journal

Here is a link to the official table to allocate UID for applications: https://www.symbiansigned.com/app/page/uidfaq

Saturday 7 October 2006

c++ extensions to pys60 3rd ed platform

Example code:

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

Download the full project definition.


Building for phone:

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

bldmake bldfiles
abld build gcce urel

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


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.


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.

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



From: http://wiki.opensource.nokia.com/projects/PyS60_creating_extensions

Wednesday 4 October 2006

Journal

I spent the last 2 days trying to fix the building error for the dll. Polymophic dlls for 1st and 2nd S60 edition don't allow static data in the source. So I have to wrap everything in a class and that's where it gives me some problem since I'm not very experimented with C++.

I'm waiting for a helping hand from Jouni when he will have some time.

Monday 2 October 2006

Journal

Today we succeeded to build the SHA256 module for the phone. There has been some wrong initialisation in the source so it took me 1/2 day to find it.

I have named the module pys60crypto. It includes SHA256 and SHA224 encryption. Those two SHA object have the following methods:

  • update()
  • copy()
  • digest()
  • hexdigest()

Usage :

import pys60crypto
x = pys60crypto.sha256("blabla")
print x.hexdigest()

You'll get :

ccadd99b16cd3d200c22d6db45d8b6630ef3d936767127347ec8a76ab992c2ea

I get an error when building for the phone. I'm waiting for an answer to fix this.

LEFEVRE Damien
http://www.lfdm.net
contact@lfdm.net