Nokia N95与PyS60的传感器和xprofile模块
我写了一个Python脚本,目的是根据手机的位置来修改手机的配置。这个脚本在ScriptShell下运行得很好。
但问题是,它在启动时运行的“sis”脚本和不运行时都会卡住。
所以我想问问,代码哪里出问题了?还有,我是否需要传递特殊的参数给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()
这个脚本在开机时启动,使用ensymble和我的开发者证书。
提前谢谢大家!
2 个回答
2
xprofile 不是一个标准库,所以你需要确保把它的路径加上。我的猜测是,当以 SIS 方式运行时,它找不到 xprofile,就会卡住。发布你的 SIS 时,要么告诉用户单独安装这个库,要么把它包含在你的 SIS 里。
你打算把它安装在哪里,就用那个路径。这里有一个 Python 默认目录的例子:
# 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')
顺便说一下,要确保干净退出,可以这样做:
appuifw.app.menu = [(u'Close', exit_key_handler)]
3
我在我的脚本开头经常会用类似这样的东西:
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)