[Matplotlib-devel] Event handling callbacks call order

Raymond Osborn rayosborn at me.com
Thu Feb 14 09:49:14 EST 2019


I used the same Matplotlib examples to implement something similar in widgets.py <https://github.com/rayosborn/nexpy/blob/edit-options/src/nexpy/gui/widgets.py> (https://github.com/rayosborn/nexpy/blob/edit-options/src/nexpy/gui/widgets.py <https://github.com/rayosborn/nexpy/blob/edit-options/src/nexpy/gui/widgets.py>). There is an NXpatch class, with a variety of subclassed shapes. Once they are created and connected to the plot, they are independently draggable and resizable as promised.

>>> plotview.deactivate()
>>> r=NXrectangle(1650,2000,200,1000,color='g’)
>>> r.connect()
>>> plotview.activate()

I do have to deactivate zoom and pan modes when adding the shapes, but they can be reactivated afterwards and the shapes will still be movable provided the cursor is within them.  I don’t know if that is the problem you are encountering. In the code, ‘plotview’ is the active plotting window - you can find the activate and deactivate functions in https://github.com/rayosborn/nexpy/blob/edit-options/src/nexpy/gui/plotview.py <https://github.com/rayosborn/nexpy/blob/edit-options/src/nexpy/gui/plotview.py>.
 
Ray

> On Feb 13, 2019, at 6:46 PM, Daniele Nicolodi <daniele at grinta.net> wrote:
> 
> Hello,
> 
> I have an application where I let the user place Patches on the canvas
> via mouse events. To do so I have a "button_press_event" callback
> registered to the canvas. I now would like to allow to drag the drawn
> patches to change their position. To do so I register other callbacks on
> the canvas like in the examples at
> https://matplotlib.org/users/event_handling.html. The problem is that
> the callbacks are called in the order they are registered and I haven't
> found a way to inhibit execution of callbacks down the stack from
> previously called callback. This results in the fact that patches are
> drawn on top of the old ones when the user tries to drag those around.
> 
> I can see (quite convoluted) ways to avoid this in my code, but I would
> think that correctly handling this is a common occurrence and that there
> could be a solution built into matplotlib. However, I haven't found it.
> 
> I am missing something?
> 
> Thank you!
> 
> Cheers,
> Dan
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20190214/a3be7bda/attachment.html>


More information about the Matplotlib-devel mailing list