views:

577

answers:

2

I've made a python script which should modify the profile of the phone based on the phone position. Runned under ScriptShell it works great.

The problem is that it hangs, both with the "sis" script runned upon "boot up", as well as without it.

So my question is what is wrong with the code, and also whether I need to pass special parameters to ensymble?

import appuifw, e32, sensor, xprofile
from appuifw import *

old_profil = xprofile.get_ap()

def get_sensor_data(status):
    #decide profile

def exit_key_handler():
    # Disconnect from the sensor and exit
    acc_sensor.disconnect()
    app_lock.signal()

app_lock = e32.Ao_lock()

appuifw.app.exit_key_handler = exit_key_handler
appuifw.app.title = u"Acc Silent"
appuifw.app.menu = [(u'Close', app_lock.signal)]
appuifw.app.body = Canvas()
# Retrieve the acceleration sensor
sensor_type= sensor.sensors()['AccSensor']
# Create an acceleration sensor object
acc_sensor= sensor.Sensor(sensor_type['id'],sensor_type['category'])
# Connect to the sensor
acc_sensor.connect(get_sensor_data)

# Wait for sensor data and the exit event
app_lock.wait()

The script starts at boot, using ensymble and my developer certificate.

Thanks in advance

+2  A: 

xprofile is not a standard library, make sure you add path to it. My guess is that when run as SIS, it doesn't find xprofile and hangs up. When releasing your SIS, either instruct that users install that separately or include inside your SIS.

Where would you have it installed, use that path. Here's python default directory as sample:


    # PyS60 1.9.x and above
    sys.path.append('c:\\Data\\Python')
    sys.path.append('e:\\Data\\Python')
    # Pys60 1.4.x or below
    sys.path.append('c:\\Python')
    sys.path.append('e:\\Python')

Btw make clean exit, do this:


    appuifw.app.menu = [(u'Close', exit_key_handler)]
JOM
+2  A: 

I often use something like that at the top of my scripts:

import os.path, sys
PY_PATH = None
for p in ['c:\\Data\\Python', 'e:\\Data\\Python','c:\\Python','e:\\Python']:
    if os.path.exists(p): 
        PY_PATH = p
        break
if PY_PATH and PY_PATH not in sys.path: sys.path.append(PY_PATH)
Agathe