When you have an event in the class and same event you are binding when creating an instance of it, the order of execution of events are: first instance then class.
Take a look the example:
1.Run Demo.py
2.Left down on rectangle and ‘None’ is getting printed.
It’s because first LEFT_DOWN event of instance mCanvas is getting fired and then LEFT_DOWN of class, which will set value of ‘selectedObject’ attribute. I need to switch the order of events to get the correct results or How do I solve this problem?
When you have an event in the class and same event you are binding when creating an instance of it, the order of execution of events are: first instance then class.
Take a look the example:
1.Run Demo.py
2.Left down on rectangle and 'None' is getting printed.
It's because first LEFT_DOWN event of instance mCanvas is getting fired and then LEFT_DOWN of class,
In your example there is no difference, both of the Bind()'s are being made on the instance. It's just that in one place the instance is referenced with 'self' and in the other place it is referenced with 'self.mCanvas' but they are really both referring to the same object.
which will set value of 'selectedObject' attribute. I need to switch the order of events to get the correct results or How do I solve this problem?
Reverse the order of the Bind() calls. Or write your event handlers such that they do not depend on the order of the event handlers being called. Or have your MagicCanvas.OnLeftMouseDown handler generate a custom event and then catch that one in the container rather than the canvas's EVT_LEFT_DOWN.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!