You Are Here:

Community: Developer Discussion Boards

#1 Old problem with non blocking call and canvas‏ - 2008-05-20, 12:14

Join Date: May 2008
Posts: 53
oyuky
Offline
Regular Contributor
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)
Reply With Quote

#2 Old Re: problem with non blocking call and canvas‏ - 2008-05-20, 21:10

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by oyuky View Post
im getting this error in the consolet(canvas never appears) :
Quote:
e=d["position"]typeError : unsuscriptable object
I would say the variable "d" is not defined, therefore it cannot be used in the way you're trying to. Some UNTESTED fix proposal guess below in blue.

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)
The bigger problem is that you just run through the script and exit. You should add "the normal" application body to stop and wait for exit. Either use a busy loop or stop to wait for exit key press.

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
Reply With Quote

#3 Old Re: problem with non blocking call and canvas‏ - 2008-05-21, 11:49

Join Date: May 2008
Posts: 53
oyuky
Offline
Regular Contributor
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)
Reply With Quote

#4 Old Re: problem with non blocking call and canvas‏ - 2008-05-21, 13:40

Join Date: May 2008
Posts: 6
shadowjk
Offline
Registered User
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia