| Reply | « Previous Thread | Next Thread » |
|
hello. I have a question, im been trying to adapt the non blocking call example from pys60 documentation that uses thelocation module but instead of printing in the console (if i print inthe console or with blocking call it works fine) i want to print it inthe canvas.The problem im having is my program stays in the console until itconnects to the gps and then im getting this error in the consolet(canvas never appears) :e=d["position"]typeError : unsuscriptable object Do anybody know what im doing wrong?
Code:
from graphics import *
import appuifw
import e32
import positioning
appuifw.app.screen='normal'
appuifw.app.title=unicode('My Test App')
canvas=appuifw.Canvas()
appuifw.app.body=canvas
positioning.select_module(positioning.default_module())
positioning.set_requestors([{"type":"service",
"format":"application",
"data":"test_app"}])
def cb(event):
e = d["position"]
canvas.clear()
canvas.text( (2,12), unicode(str(e["latitude"])))
canvas.text( (2,24), unicode(str(e["longitude"])))
e32.ao_yield()
e32.ao_sleep(1115)
d= positioning.position(course=1,satellites=1,callback=cb, interval=500000,partial=0)
|
|
Quote:
Code:
from graphics import *
import appuifw
import e32
import positioning
appuifw.app.screen='normal'
appuifw.app.title=unicode('My Test App')
canvas=appuifw.Canvas()
appuifw.app.body=canvas
positioning.select_module(positioning.default_module())
positioning.set_requestors([{"type":"service",
"format":"application",
"data":"test_app"}])
d= positioning.position(course=1,satellites=1,callback=cb, interval=500000,partial=0)
def cb(event):
global d
e = d["position"]
canvas.clear()
canvas.text( (2,12), unicode(str(e["latitude"])))
canvas.text( (2,24), unicode(str(e["longitude"])))
e32.ao_yield()
e32.ao_sleep(1115)
If you don't know how, then go and study the sample scripts provided with python SDK installation. It's well worth the trouble. Cheers, --jouni |
|
hello your example doesnt work because variable d is calling cb function before being defined .
i fixed my code, now i dont get any errors but my canvas doesnt appear. I also tried putting the "canvas.text" outside the cb function but im getting race condition problems that i dont know how to solve . I also tried the "normal" application body to stop and wait for exit, but it doesnt work because of the race condition problem. here is the code where i put the canvas.text stuff out of the db function , Do any body know why canvas doesnt appear? please also check the new thread about racing condition. many thanks Code:
import LatLongUTMconversion
from LatLongUTMconversion import LLtoUTM, UTMtoLL
from graphics import *
import appuifw
import e32
import positioning
appuifw.app.screen='normal'
appuifw.app.title=unicode('My Test App')
canvas=appuifw.Canvas()
appuifw.app.body=canvas
positioning.select_module(positioning.default_module())
positioning.set_requestors([{"type":"service",
"format":"application",
"data":"test_app"}])
def cb(event):
e = event["position"]
canvas.clear()
canvas.text( (2,12), unicode(str(e["latitude"])))
canvas.text( (2,24), unicode(str(e["longitude"])))
l=LLtoUTM(19, e["latitude"], e["longitude"])
canvas.text( (2,34), unicode(str(l[1])))
canvas.text( (2,46), unicode(str(l[2])))
e32.ao_yield()
e32.ao_sleep(1115)
d= positioning.position(course=1,satellites=1,callback=cb, interval=500000,partial=0)
|
|
I'm a newbie myself, but as far as I understand it, your script "exits" right after setting the callback, but the callback will still happen, and at that point the namespace has been blown away. At least I've seen something like that in my own experimenting. I modified your code a bit, but I didn't test it. I hope it gives you ideas.
Code:
import LatLongUTMconversion
from LatLongUTMconversion import LLtoUTM, UTMtoLL
from graphics import *
import appuifw
import e32
import positioning
appuifw.app.screen='normal'
appuifw.app.title=unicode('My Test App')
canvas=appuifw.Canvas()
appuifw.app.body=canvas
# Creates new Ao_lock, doesn't
# actually do anything at this point.
mylock = e32.Ao_lock()
# Make exithandler() get called when user
# presses exit
appuifw.exit_handler = exithandler
positioning.select_module(positioning.default_module())
positioning.set_requestors([{"type":"service",
"format":"application",
"data":"test_app"}])
# This function gets called when user
# pushes the exit button
def exithandler():
# Let's stop gps before exiting
positioning.stop_position()
# This makes the lock at the end
# of the script wake up.
mylock.signal()
def cb(event):
e = event["position"]
canvas.clear()
canvas.text( (2,12), unicode(str(e["latitude"])))
canvas.text( (2,24), unicode(str(e["longitude"])))
l=LLtoUTM(19, e["latitude"], e["longitude"])
canvas.text( (2,34), unicode(str(l[1])))
canvas.text( (2,46), unicode(str(l[2])))
e32.ao_yield()
d= positioning.position(course=1,satellites=1,callback=cb, interval=500000,partial=0)
# This makes the script wait here until
# something calls mylock.signal(), which
# should be the exithandler further up.
mylock.wait()
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |