On Thu, Jan 26, 2012 at 3:24 PM, Jerzy Karczmarczuk <
jerzy.karczmarc...@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
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to