On Fri, Jan 27, 2012 at 4:54 AM, Jerzy Karczmarczuk <
jerzy.karczmarc...@unicaen.fr> wrote:
> Benjamin Root answers my query concerning user-generated events :
> > To answer your question, take a look at how pick_event() is declared
> > in backend_bases.py:
> >
> > def pick_event(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.
> Dear Ben, thank you, but this is not exactly my problem. I don't want to
> call the callback myself, since the event should be "fired" from within
> a callback. I should have been more precise. Let's distil the problem.
> [This is a part of my current teaching...] I did already what you
> suggest here...
>
> Imagine an animation, which consists in generating a trajectory, segment
> after segment (say, of a planet). Classically this is a loop, but when
> it runs, the rest of the program is blocked. So, instead, the code
> behaves as a Python generator, generates just one segment, and that's
> all. But it "yields" something, it posts an event, put it in a queue,
> and somebody else, the mainloop() or similar, pops it off the queue and
> re-launches the callback. (With generators, it calls the .next()). No
> timers, as in Timer or Funct animations...
>
> It must be "decentralized", no recursive calls. My callback from time to
> time creates another planet, or destroys an existent, and there are
> simultaneous trajectories on the screen, several concurrent events in
> the queue. And the system should remain reactive, interpret buttons,
> sliders, etc.
>
> I know how to do this by hand, how to write my own event loop, declare a
> queue, and how to add to my private "virtual" event handling also the
> callbacks of mouse events. But this is an overkill, I repeat the
> functionalities which are already there, the event queue in particular.
>
> I did it with wx. But Matplotlib protects the user from the concrete
> back-end, and I want to protect my students as well, so I look for a
> "GUI-neutral" solution.
>
> Thanks.
>
> Jerzy
>
>
Still not sure why my suggestion would not work:
http://matplotlib.sourceforge.net/api/cbook_api.html#matplotlib.cbook.CallbackRegistry
You can have things set up such that event being triggered can subsequently
trigger other events as well. An event can even connect a new event as
well. An example where I do this is when I want to hide a line while it is
clicked. In the function that I connect to a "button_press_event", I make
the artist invisible, and I also create a lambda function that sets the
visibility of that artist to True (and subsequently disconnects itself) and
connect that lambda to a "button_release_event".
Keep in mind that these "events" are merely key'ed by strings like
"button_press_event", there is nothing magical about them. So, when you
call the .process() function with a string value and an Event object, it
passes that object to every connection that was made with that same string
value. You can call the process() function from anywhere, even within an
event.
Now, I haven't tried connecting a generator function with a yield statement
before, so I don't know how well that would work, but I don't know why it
wouldn't.
Why exactly would the callback registry not work for you?
Ben Root
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
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-dev2
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users