PyS60 using appuifw from a non UI thread

PyS60 scripts that are running in a non UI thread have the limitation that they can not use the appuifw library to do GUI task. Trying to importing appuifw will result in the following error:

ImportError: No module named _appuifw

This can be a limitation when there is a need to have a application running as a server interact with the user. I encountered this while working with the mobile web server and wanted to display a simple message to the phone user.

The solution is to create a standalone PyS60 application and let the server thread application/script execute it through e32.start_exe() call.

I have created a generic application for this purpose that I call pyLaunch and can be easily extended for this purpose.

You can download it here, pyLaunch.

Install pyLaunch.sis on your phone to the c: drive, the application should appear in the Application menu.

Copy the file pylaunchlib.py into e:\python\lib or c:\python\lib (or any other directory that you are sure is in the python path)

pylaunchlib.py can be extended as needed, just create a new function implementing what ever you want to do and then register it in the getFunctionMap function with
funcmap = {’displayMessage’ : self.displayMessage, ‘yourfunctionname’ : self.yourfunctionname}
Yes this could probably be made a little more sophisticated ;)

Now from the script running in the server thread you can successfully execute your function with
f = open( ‘c:\\commands_file.txt’,'w’ )
f.write(’yourfunctionname:param1;param2;param3\n’)
f.close()
   
e32.start_exe(u’c:\\sys\\bin\\pyLaunch_0xe8f72d57.exe’,”)

e32.star_exe will fire up pyLaunch in a separate thread (UI thread) that will read the commands_file extract the function name and parameters and make the appropriate call.

I initially tried to use e32.start_exe to pass the parameters with
e32.start_exe(u’c:\\sys\\bin\\pyLaunch_0xe8f72d57.exe’,'yourfunctionname param1 param2 param3′)
but I was not successfull in reading the parameters in pyLaunch. I therefore went for a file based approach to transfer the parameters, another possible approach could be to use sockets between the two applications.

The reason the application has to be started with the name pyLaunch_0xe8f72d57.exe is that I used ensymble to create the sis packet and it adds the UID in between the application name and ending in this case the auto-generated test UID 0xe8f72d57. When creating a new sis packet the appropriate UID will have to be used.

Since I consider my self a Python and S60 beginner all comments on improvements would be very nice.

Tags: , , , , , ,

3 Responses to “PyS60 using appuifw from a non UI thread”

  1. I love my new Nokia N96. Nokia FTW. I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Look forward to reading more from you in the future.

  2. I like my legendary N96. I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Look forward to reading more from you in the future.

  3. Cheers for all the help and tips, Symbian can be funny, imagiane if we had to do this kind of thing with Windows!

Leave a Reply