Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Explicit tool registration.#9941
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
I think I get what you mean, you see a problem with wanting the possibility of different default_tools for different backends. I agree that playing around with the default_tools dictionary seems like a bad idea, but as far as I know, other options exist for going around this. For example the backend can remove a tool and then add a different one, and also in MEP27 I effectively redesigned the quit tool to fire an MPL closing event. The whole point of MEP22 and MEP27 were to standardise the backends making things simple. I think as long as we keep to that, we give the individual backends the maximum freedom to do what they want. |
lib/matplotlib/backend_managers.py Outdated
@@ -234,7 +234,7 @@ def remove_tool(self, name): | |||
del self._tools[name] | |||
def add_tool(self,name, tool, *args, **kwargs): | |||
def add_tool(self,tool_name): |
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.
don't remove the *args, and **kwargs, those are really useful when adding custom tools.
Sometimes you need to pass initialization arguments when manually adding tools
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.
yup, restored it
lib/matplotlib/backend_managers.py Outdated
tool_obj = tool_cls(self, name, *args, **kwargs) | ||
self._tools[name] = tool_obj | ||
tool_obj = tool_cls(self, tool_name) |
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 same comment for the *args and **kwargs
Also pushed removal of sender and data kwargs. |
Uh oh!
There was an error while loading.Please reload this page.
@OceanWolf how do you see this? Pros:
Cons:
@anntzer I know it is an anti-pattern but, can we do something to eliminate the need to register the tool when adding it by hand (like in the example)? |
I agree always having to register is not super elegant; I'm totally fine with allowing passing a Tool instance to add_tool directly (and store the name of the tool as an attribute of the class, so this way thusly added tools also have a proper signal name, and there's no need to mention the name explicitly when registering the builtin tools). I'm keeping the inheritance mechanism private for now because I hope to make it work together with the I still think that if we're worried about rubberbands they should become freestanding functions, to me it's very clear they were previously shoehorned into the wrong API. |
Pushed the changes suggested above. |
why change to canvas instead of backend for tracking? |
Now there is another problem, we can not add twice the same tool, this is sometimes useful when passing arguments at initialization (*args, **kwargs of add_tool) |
Switching to registering on the canvas class allows one to rely on canvas inheritance rather than having to manually declare the inherited tools. I think the issue with having the same tool twice was already present before (in the sense that the |
The name was defined when calling A combination of both could work fine. And for the user in "manual" mode, we force him to use the name and the cls |
I guess a possibility would be to change the signature of ToolBase to |
What is the advantage of this vs forcing to pass the name? |
After a little thought, maybe is not a bad idea. |
This seems rather ugly to me. I haven't had a look at the code yet, but "name" of a tool exists as a label for identification by the I would keep |
Haven't thoughttoo much about this but I think it's fine to use@fariza's proposed signature too. |
@OceanWolf right now the tool name is given at the add_tool call. |
Just to say, that sometimes tools need to know their identifier |
Why? I don't see why a tool should ever need to know what we call it. It makes no difference to the function of a hammer whether it gets called a hammer, or a hitty thing, so long as we know what we call it. The purpose of a tool lies in doing something. That said, if we already have it that way, I don't mind changing it. Also, I think I come around now to the idea of using the canvas class to store the tools used, but I think the PR here looks way too complicated for such a simple change. Why don't you just move |
@OceanWolf right now the name it is only used by the cursor tool, it needs to know the name of the tools to connect to their trigger event, and this is done using their name. But I agree with you (the hammer convinced me) Regarding the filling of |
May be easier to do all the refactoring in a single PR I think. |
I would rather have smaller PRs, it becomes easier to see the logic, to see what gets changed and why. I have been toying with the idea of getting rid of breaking of chunks of the main MEP27 PR, but the pain of the rebasing has put me off so far given how bits of the PR have changed as time has progressed. Maybe I will just bite the bullet over the holidays or something. And yes, I see why you do it, for tool admin purposes, but that shouldn't require too much fiddling to change. Also as a tool admin thing, I see that as more the responsibility of the |
As for the I dislike having all of these methods and variables around to determine something. It spreads out the code too much to figure out what what has happening, keep code simple to read, if something happens with the Canvas class, I expect to find it in the canvas class in the code. Having tool registration in I go with KISS, easier to debug and spot mistakes. Also going back to the logic before about a tool not knowing its name, this will then mess up the register tools function. Going back to a dict of |
I am not convinced that Regarding the name argument in tool. |
I don't see any other way for this PR to accomplish want it wants to accomplish once we have moved name, but yes, lets do the name thing in a separate PR and then see what we have left with here. |
No worries, please go ahead. |
Although I guess the other question is, do tools really need to have names to start with?
|
Let's not take this out of control.We remove the name from within the tool.But it still useful.If you want to propose the complete name removal I propose to do it in aseparate PR. So we can move ahead with this one …On Dec 10, 2017 5:47 PM, "Antony Lee" ***@***.***> wrote: Although I guess the other question is, do tools really need to have names to start with? As you mentioned, this is only used to that the cursor tool can register onto trigger events for other tools. But this can be implemented in at least two different ways: - the individual tools can call themselves canvas.set_cursor or toolbar.set_cursor (or wherever we want to store this method) - or, there could be a single tool_trigger_event that passes the Tool object as one of its arguments. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#9941 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABa86dSluWgv5KfIEhsBx0wYeRk1oTHfks5s_F9wgaJpZM4Q3Lkk> . |
We need name to identify the tool, we can have multiple versions of the same tool at the moment, that makes it easy to create several tools from the same class initialised with different parameters. |
I am +1 with registering the tool inside the canvas,@OceanWolf can we move ahead with this? No matter what we do, it will never be perfect, put it is pretty good as it is. |
Superseded by#20990. |
Uh oh!
There was an error while loading.Please reload this page.
@fariza This is more or less how I would bikeshed the thing...
The advantage is that if someone wants to override someother tool for their backend (say, Quit), they don't have to go fiddle with the global dictionary. Plus other arguments listed in#8712.
Perhaps an even better way to do this would be to store the tool classes as attribiutes (subclasses) of the respective FigureManager classes, as this will make inheritance automatic (i.e. gtk3agg will know to go find the tools on the gtk3 figuremanager).
PR Summary
PR Checklist