-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Timers independent of canvases #1907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I will try this out today or tomorrow with my more "complicated" animations On Mon, Apr 15, 2013 at 6:00 PM, mdehoon [email protected] wrote:
|
I really like the concept of having a
Agreed - this sounds very desirable to me. The big problem, IMHO, is that there is no figure-less concept to be initialised in a backend module ( Interestingly the TkAgg backend's timer requires a All of this suggests to me that we are missing a backend concept (but I'm not 100% sure what that is), which is responsible for managing backend specific stuff such as Timers (and perhaps the "show" event loop). Anyone who uses the real OO interface for GUI backends care to comment (is there anybody!?!)? |
In my branch I am indeed using matplotlib.get_backend in matplotlib.events. Perhaps an alternative is to copy the _backend_selection function from matplotlib/pyplot.py (or put it in a more central place)? Because as far as I can tell, matplotlib.events and matplotlib.pyplot are facing the same problem with regards to identifying the backend.
There is a Timer class in the backend modules, which is defined independently of any figure. In my branch, in each backend a Timer can be initialized without needing a figure.
While the Timer in TkAgg did require a Tk.Canvas instance, it is possible to make a Timer in Tkinter without using a Canvas. See the Timer class in TkAgg in my branch: https://github.com/mdehoon/matplotlib/blob/Timer/lib/matplotlib/backends/backend_tkagg.py
I guess we could make importing the backend a bit easier by centralizing the backend selection code. It would be great if we could just do
|
👍 to |
I feel like the bad parent 😄, but any solution which makes use of the I think this functionality is really valuable - but I'd also like to find a solution which would allow the OO interface to continue to function (without the use of globals, such as Cheers, |
Sorry, I should have been more clear. While So I don't think what @pelson is saying is really in conflict with what I'm saying, unless I'm missing something. |
Just to note, I did not notice any adverse effects with my more complicated animations, both in displaying, and saving them. |
@pelson, @mdboom Sorry I am not sure if I understand correctly.
and
and
then what is still missing? |
backend_module = __import__(backend_name, globals(), locals(), [backend_name]) | ||
return backend_module | ||
|
||
backend = _initialize() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that this is a one-time event & bound to rcParams['backend']
. Users who create import and create their own Canvas from a backend module (which is not the rcParams backend) can therefore not use this module, and ergo cannot use animations.
@mdehoon - those options are great (in fact, all we need). The problem is that the first is relying on the I don't actually use the full OO interface, but I've put together an example of what used to work before this PR:
I'm not confident that this is the best way to use the OO interface, but it is an example which does fail as a result of HTH |
@pelson Thanks for the example. I see your point. Then, I guess the fundamental question is, how does matplotlib know which backend is to be used?
Then, in your example, we'd get
and inside animations.py, instead of
we'd have
The events module can then be removed. |
As long as
also works, I think that's fine. There is a lot of code out there written to a specific backend (for good reason), and that code doesn't even necessary call |
Yes that would also still work. |
My only concern there is that we need to watch out for dependency chaining On Thu, Apr 18, 2013 at 6:41 PM, mdehoon [email protected] wrote:
|
I'd like to move this forward for 1.3. @WeatherGod: Any thoughts on how to address your concerns and still get the meat of this done (which will allow timers to work in the osx backend)? |
@@ -16,7 +17,7 @@ def update_title(axes): | |||
|
|||
# Create a new timer object. Set the interval 500 milliseconds (1000 is default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is different from what is implemented
My big concern is with _initialize() in events.py. If we can update the code that does the backend switching to also handle switching of timer modules, that would make me feel better. But there is still something not sitting right with me here. First off, we are completely throwing out TimerGTK and eliminating functions like "new_timer()" and such without a deprecation process. Remember, it was the animation module that was labeled as "experimental" not the Timers, which have been in place for a few releases now. I am sure we can very easily have "TimerGTK" aliases and new_timer(). |
I also think that this is not quite ready yet. At least the PR will need to be updated to reflect the outcome of the discussion here. One thing that is not quite clear to me is to what degree we allow users to import specific backends directly. This can work in specific cases, but not in general even with matplotlib 1.2.1. For example, in this code snippet:
the timer is not being called because the Tkinter event loop is unaware of the GTK timer. So I think we do need some centralized way of selecting the backend (while importing specific backends directly may or may not work). |
Given what's been previously said, I'd like to move this out of the v1.3.x milestone. There is a lot of delicate code which we would not be ideal to change right before a release. @mdboom - you put it in |
Yes -- I was thinking the same thing. This is very worthwhile, but best to put it off to do it right. |
We've stalled on this PR. It is a really gnarly issue - is it worth having a hangout about this subject? @mdehoon - would you be able to make a Thursday (last one's times in your TZ: https://www.google.com/calendar/render?eid=OHRndGhhYnZnYW1wMG1iaWtvNDhuMmxlZWsgNzloazhqaHZsa3M4am44ZHM0cmkxZTZxNGdAZw&ctz=America/New_York&pli=1&t=AKUaPmaSkt5RzvGkQLNITYToz4oXol9K5S9VJLt625fiwb-JfRrrfS9-Y2lXNFrXHWqH4Z47yqhA&sf=true&output=xml). In the meantime, I don't think we can merge this and will definitely need a MEP to get a consensus on the ambition. As a result, I'm going to close the PR, if only to keep the number of PRs as low as is feasible. Cheers @mdehoon |
@pelson I can do a hangout to discuss, but it would have to be outside of working hours in the Japanese time zone (the previous one was at 10:00-12:00 in the morning here, so that wouldn't work). As it happens, this coming Monday January 13th is a holiday in Japan, so that would work. |
@mdboom, @WeatherGod - is that any good for you. Same time as normal, just this Monday instead? If so, lets put out a notice on the mailinglist today. I suggest we keep the subjects to 2: First the timer discussion; second release related business/PRs. @mdboom - can you grant me access to the matplotlib group calendar so that I can add the proposed date? Cheers, |
@pelson: Sorry to not see this until now. I suspect it's too late to have this meeting at this point, but in general, I can do most Mondays at that time. I've added you as a calendar manager -- I guess you'll get a notification of that through your gmail address...? |
The animation code in matplotlib relies on timers to update the animated figures. Currently a new timer is created by calling new_timer on a canvas, as in
This seems a bit of a wrinkle. For example, you may want to associate a timer with multiple figures, or with no figure at all; also you may want to continue using a timer after a particular figure is closed.
I am therefore proposing to make timers independent of canvases. With this pull request, the above code would become
This has the additional advantage of making the different backends more similar to each other; in the current implementation some backends rely on the canvas when making a timer, while others ignore it.
I have verified that the animation examples still work correctly with all backends.
(EDIT @pelson: added code blocks)