On Thu, Jan 26, 2012 at 3:24 PM, Jerzy Karczmarczuk <jerzy.karczmarczuk@unicaen.fr> wrote:
Does anybody know how to generate and process my "private" events? I can
subclass the Event() class, say, MyEvent,
with a name "my_event", and I can -
   canvas.mpl_connect('my_event', aCallback)

but then, how to fire one? (I don't want to call the callback directly).


Suppose that the interface, when show() is active launches a
simulation/visualisation program which animates many things in its
figure. From time to time something "special" appears, and its behaviour
should be steered by those private events.

(Yes, I know that I can do it in several other ways, or write my own
event-processing loop, or use directly wxPython or PyGTK instead of
Matplotlib. So, I don't need the replacement solution, but just a way to
fire events within Matplotlib...)

Thank you.

Jerzy Karczmarczuk
Caen, France


It is smart to simply re-use mpl's event callback system.  Luckily, in the latest release, we allowed for arbitary events to be added.  To answer your question, take a look at how pick_event() is declared in backend_bases.py:

    def pick_event(self, mouseevent, artist, **kwargs):
        """
        This method will be called by artists who are picked and will
        fire off :class:`PickEvent` callbacks registered listeners
        """
        s = 'pick_event'
        event = PickEvent(s, self, mouseevent, artist, **kwargs)
        self.callbacks.process(s, event)

The function that "fires" the event is "self.callbacks.process(s, event)", where "self" is the figure canvas.

I hope this helps!
Ben Root