Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor oyuky's Avatar
    Join Date
    May 2008
    Posts
    53
    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)

  2. #2
    Super Contributor JOM's Avatar
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976
    Quote Originally Posted by oyuky View Post
    im getting this error in the consolet(canvas never appears) :
    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

  3. #3
    Regular Contributor oyuky's Avatar
    Join Date
    May 2008
    Posts
    53
    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)

  4. #4
    Registered User shadowjk's Avatar
    Join Date
    May 2008
    Posts
    6
    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()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved