質問

I am trying to subclass Leap.Listener and register it with the controller:

class myLeapMotion(Leap.Listener):
    def __init__(self) :
        controller = Leap.Controller()
        controller.add_listener(self)

This raises an exception:

TypeError: in method 'Controller_add_listener', argument 2 of type 'Leap::Listener &'

How can I pass my subclass as a reference to the controller?

I've thought that self would be the listener here but I don't know the right Python syntax to write it.

役に立ちましたか?

解決

All the objects in Python are passed by reference, so no special syntax is required. Your code should work. In fact, there is NO way to pass it not by reference.

UPD: As your question has been changed, it becomes clear that your program fails not because of passing self in a wrong way. It is a problem with the library you are using. Try to perform correct initialization for your base class, call super(myLeapMotion, self).__init__() before adding a listener. At least here it is done this way.

UPD2: Looks like I am right. Here the code author does almost exactly the same as you do. The only difference is that he calls __init__ from the base class.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top