×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    11

    canvas.bind() doubt

    Hi everybody

    I wander if u guys could help me out, i have the following line of code:

    canvas.bind(key_codes.EButton1Down,Movimento.mouse_down( down_y, up_y, left_x, right_x, source_novo_x, source_novo_y,bt,canvas, pos=(0, 0)))

    where mouse_down is the function that is executed then a touch occurs but now i need for the function to return some parameters my problem now is how to access that parameters.

    I did the following:

    down= canvas.bind(key_codes.EButton1Down,Movimento.mouse_down( down_y, up_y, left_x, right_x, source_novo_x, source_novo_y,bt,canvas, pos=(0, 0)))

    and got the following error: TypeError:callable expected

    Can anybody help me out on how to acess the return parametes correctly

    Thanks for ur attention !!

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: canvas.bind() doubt

    Hi,

    One way to do it is to have global variables in which your function will store the values it's supposed to return.

    For example:
    Code:
    def f():
        return 5
    
    a = f()
    becomes
    Code:
    a = 0
    
    def f():
        global a
        a = 5

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    11

    Re: canvas.bind() doubt

    Thank you for you replay

    but my problem is that i have them in different .py files :S

    i have the main.py where i have that line of code and from there i call the mousse_down that is on Movimento.py and i need to return one value to the main.py file.

    my problem because of the nature of the bind() function i think :S


    Quote Originally Posted by bogdan.galiceanu View Post
    Hi,

    One way to do it is to have global variables in which your function will store the values it's supposed to return.

    For example:
    Code:
    def f():
        return 5
    
    a = f()
    becomes
    Code:
    a = 0
    
    def f():
        global a
        a = 5

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: canvas.bind() doubt

    Then perhaps you can do it like this: define another function in main.py that calls Movimento.mouse_down and gives the value returned by it to a global variable. Then you bind that function to the canvas.

    Code:
    #main.py
    
    down = None
    
    def my_callback():
        down = Movimento.mouse_down(down_y, up_y, left_x, right_x, source_novo_x, source_novo_y,bt,canvas, pos=(0, 0))
    #Depending on how you use it, you may want to define it as my_callback(down_y, up_y, left_x, right_x, source_novo_x, source_novo_y,bt,canvas, pos=(0, 0)) so you can pass the arguments to mouse_down
    
    canvas.bind(key_codes.EButton1Down, my_callback) #Again, you may want to use my_callback(down_y, up_y, left_x, right_x, source_novo_x, source_novo_y,bt,canvas, pos=(0, 0)), probably as a lambda function.
    I hope I understood the situation.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    11

    Re: canvas.bind() doubt

    ahh yes that a good ideia it should work thankss




    Quote Originally Posted by bogdan.galiceanu View Post
    Then perhaps you can do it like this: define another function in main.py that calls Movimento.mouse_down and gives the value returned by it to a global variable. Then you bind that function to the canvas.

    Code:
    #main.py
    
    down = None
    
    def my_callback():
        down = Movimento.mouse_down(down_y, up_y, left_x, right_x, source_novo_x, source_novo_y,bt,canvas, pos=(0, 0))
    #Depending on how you use it, you may want to define it as my_callback(down_y, up_y, left_x, right_x, source_novo_x, source_novo_y,bt,canvas, pos=(0, 0)) so you can pass the arguments to mouse_down
    
    canvas.bind(key_codes.EButton1Down, my_callback) #Again, you may want to use my_callback(down_y, up_y, left_x, right_x, source_novo_x, source_novo_y,bt,canvas, pos=(0, 0)), probably as a lambda function.
    I hope I understood the situation.

Similar Threads

  1. Bind an incoming call
    By renzogiust in forum Symbian
    Replies: 20
    Last Post: 2011-01-02, 14:13
  2. Getting -6 at iListenSock.Bind()
    By amit04.kumar in forum Symbian
    Replies: 5
    Last Post: 2010-10-25, 14:15
  3. [bug?] canvas.bind crashes my app
    By uhm57 in forum Symbian
    Replies: 2
    Last Post: 2009-12-09, 15:20
  4. How to create a partly transparent Canvas to lay on top of another Canvas?
    By mkleijer in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2007-05-22, 07:00
  5. bind() problem!
    By zwgoal in forum Symbian
    Replies: 0
    Last Post: 2005-08-26, 09:37

Posting Permissions

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