Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User ddaemen's Avatar
    Join Date
    Oct 2008
    Posts
    4
    Hello, i have following code:

    Code:
    import e32
    import key_codes
    import appuifw
    import graphics
    import sysinfo
    
    def cb_quit():
    	app_lock.signal()
    
    def key_handler(i):
    	print("Key: EKey" + unicode(i))
    
    appuifw.app.screen = 'full'
    appuifw.app.exit_key_handler = cb_quit
    
    canvas = appuifw.Canvas()
    appuifw.app.body = canvas
    
    if appuifw.touch_enabled():
    	res_x, res_y = sysinfo.display_pixels()
    	res_x = res_x / 3
    	res_y = res_y / 3
    	canvas.rectangle((0, 0, res_x-1, res_y-1), 0x000000, fill = 0x000000)
    	canvas.bind(key_codes.EButton1Down, lambda: key_handler(1), ((0,0), (res_x-1,res_y-1)))
    
    canvas.bind(key_codes.EKey1, lambda: key_handler(1))
    
    app_lock = e32.Ao_lock()
    app_lock.wait()
    When i press key 1, it does print "Key: EKey1".
    When i touch the screen, i get following error:

    TypeError: <lambda>() takes no arguments (1 given)

    do i something wrong?

  2. #2
    Super Contributor JOM's Avatar
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976
    Quote Originally Posted by ddaemen View Post
    Hello, i have following code:

    Code:
    	canvas.bind(key_codes.EButton1Down, lambda: key_handler(1), ((0,0), (res_x-1,res_y-1)))
    When i press key 1, it does print "Key: EKey1".
    When i touch the screen, i get following error:

    TypeError: <lambda>() takes no arguments (1 given)

    do i something wrong?
    Your code is wrong, just like error note said. Check parentheses and try to fix it... Sorry cannot propose any fix, since I don't quite understand what you're doing (late evening here)

    Cheers,

    --jouni

  3. #3
    Registered User ddaemen's Avatar
    Join Date
    Oct 2008
    Posts
    4
    Quote Originally Posted by JOM View Post
    Your code is wrong, just like error note said. Check parentheses and try to fix it... Sorry cannot propose any fix, since I don't quite understand what you're doing (late evening here)

    Cheers,

    --jouni
    is the code wrong? i have this piece of code from this site:

    http://wiki.forum.nokia.com/index.ph...nts_with_PyS60

    and i just looked @ it again. and it seems that my code is correct?

  4. #4
    Regular Contributor ashwinurao's Avatar
    Join Date
    Oct 2007
    Posts
    114
    Quote Originally Posted by ddaemen View Post
    Hello, i have following code:

    Code:
    def key_handler(i):
    	print("Key: EKey" + unicode(i))
    
    
    canvas.bind(key_codes.EButton1Down, lambda: key_handler(1), ((0,0), (res_x-1,res_y-1)))
    
    canvas.bind(key_codes.EKey1, lambda: key_handler(1))
    When i press key 1, it does print "Key: EKey1".
    When i touch the screen, i get following error:

    TypeError: <lambda>() takes no arguments (1 given)

    do i something wrong?
    For Pointer events the callback function will receive a tuple of x, y co-ordinates indicating where the touch event occurred. This is not the case with Key events, so it is better not to handle the two types of events in a single callback function.

    Passing arguments to the callback functions registered for touch events is not possible right now because the callback function receives the co-ordinates.
    import antigravity

  5. #5
    Registered User ddaemen's Avatar
    Join Date
    Oct 2008
    Posts
    4
    well i solved my problem with following code:

    Code:
    import e32
    import key_codes
    import appuifw
    import graphics
    import sysinfo
    
    def cb_quit():
    	app_lock.signal()
    
    def key_handler1(pos=(0,0)):
    	print("Key: EKey1")
    
    def key_handler2(pos=(0,0)):
    	print("Key: EKey2")
    
    def key_handler3(pos=(0,0)):
    	print("Key: EKey3")
    #and more till 8 buttons
    
    appuifw.app.screen = 'full'
    appuifw.app.exit_key_handler = cb_quit
    
    canvas = appuifw.Canvas()
    appuifw.app.body = canvas
    
    if appuifw.touch_enabled():
    	res_x, res_y = sysinfo.display_pixels()
    	res_x = res_x / 3
    	res_y = res_y / 3
    	canvas.rectangle((0, 0, res_x-1, res_y-1), 0x000000, fill = 0x000000)
    	canvas.bind(key_codes.EButton1Down, key_handler1, ((0,0), (res_x-1,res_y-1)))
    	canvas.bind(key_codes.EButton1Down, key_handler2, ((res_x,0), (res_x*2-1,res_y-1)))
    	canvas.bind(key_codes.EButton1Down, key_handler3, ((res_x*2,0), (res_x*3,res_y-1)))
    	#and more till 8 buttons
    
    canvas.bind(key_codes.EKey1, lambda: key_handler1)
    canvas.bind(key_codes.EKey2, lambda: key_handler2)
    canvas.bind(key_codes.EKey3, lambda: key_handler3)
    #and more till 8 buttons
    
    app_lock = e32.Ao_lock()
    app_lock.wait()

  6. #6
    Nokia Developer Champion marcelobarrosalmeida's Avatar
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    752
    Hi

    A little bit later but ... How about to use a parameter in lambda function to put your first version to work (if you still want, course):

    Code:
    def handler(pos=(0,0),id=-1):
        if id == 0:
            print "event 0"
        elif id == 1:
            print "event 1"
        ...
        else:
            pass # invalid id here, treat it
    
    # change id below
    # id = 1
    canvas.bind(key_codes.EButton1Down, lambda x: key_handler(x,1), ((0,0), (res_x-1,res_y-1)))
    But, take care, "it is better not to handle the two types of events in a single callback function." (ashwinurao)

Similar Threads

  1. Problem while detecting long key press...
    By rohanwaugh in forum Symbian C++
    Replies: 1
    Last Post: 2009-03-31, 09:39
  2. how to port application on different devices
    By rmks in forum Mobile Java General
    Replies: 7
    Last Post: 2008-11-10, 17:03
  3. problem related to certificate key
    By deepakk in forum Symbian C++
    Replies: 0
    Last Post: 2008-04-04, 10:48
  4. problem facing with capture key on standby screen
    By mayudada in forum Symbian C++
    Replies: 2
    Last Post: 2008-01-15, 11:53
  5. Problem with BT devices search on mobile phone
    By atiqkamran in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-07-24, 06:05

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