-
Notifications
You must be signed in to change notification settings - Fork 1
Moved tooltriggerevents into the tool #6
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
Moved tooltriggerevents into the tool #6
Conversation
…, before filling it with tools. Added a nice utility API function, Navigation.addTools.
I like the idea but I am not sure in practice will be that fun to use. If I am a user (not developping the backend), and I want to listen to a specific tool, I have to get the object (tool instance) from navigation and then I will be able to connect to it. |
Obviously I can't say how users will use it, but I would have thought that at least in the vast majority of cases, the user would already have the tool class to hand, as we do in both the cases where we use it here. |
That is if you are adding the tool, in that case it is handled automatically and in practice it doesn't matter if the event comes from navigation or the tool. |
Well yes, the other case where it gets used From my own perspective as a user, I would fear typing the tool name incorrectly... and slow me down in the debugging time as I search for why something doesn't happen. I could add a helper method to navigation, that gets the tool and sets up the callback... that should eliminate all possible negatives, and leave all the positives, right? |
@@ -3543,6 +3525,7 @@ def _trigger_tool(self, name, sender=None, canvasevent=None, data=None): | |||
# Important!!! | |||
# This is where the Tool object gets triggered | |||
tool.trigger(sender, canvasevent, data) | |||
tool.state_changed_event(sender, canvasevent, data) |
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.
why is the event fired here and not from inside the tool trigger method?
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.
I would love to, as that will bring it directly to the point it gets fired, however it makes the code more cumbersome to write, with every tool needing a call to super...
def trigger(self, sender, event, data=None):
ToolBase.trigger(self. sender, event, data)
In my old code base (from the summer before my computer died), I did it like this:
def _trigger(*args, **kwargs):
self.trigger(*args, **kwargs)
tool.state_changed_event(...)
But I didn't like that because it makes trigger a private method...
I guess I could do it the other way around, reversing those methods, make the developer override _trigger
which executes the tool specific code, and have trigger() as the entry to the tool which ensures that the event gets fired.
@OceanWolf the more I think about this... |
Made NavigationBase.get_tool() more useful.
Renamed tool_trigger_event to trigger_tool now that it doesn't fire event.
…t override the _trigger method instead.
0fc184e
to
827b006
Compare
Okay, I have rebased, and it looks good to me :). I think that oddness has disappeared with the function renaming and simplification of functions. In terms of adding a convenience method to self.get_tool(tool).tool_connect(s, func)
self.add_trigger_cbk(tool, s, func) where self would obviously get replaced by |
@OceanWolf for the rebase I was talking about #4 This one, I'm not convinced yet, it makes the tools more complex |
I know you meant #4, but I wanted to get this one updated, I didn't like having my thoughts spread across PRs (and it gave me a lot of practice with rebase). While I agree it makes the tools slightly more complex, I think it just represents the complexity of the tool, it encapsulates what a tool can do by itself, and thus IMO reduces the complexity of the entire system. |
I am not convinced yet. |
Hmm, I sort of see it like that, though I prefer the And when I said "sort of" above, I meant that the |
a88dc2d
to
5eae4e1
Compare
FigureManager manages the Figure and not the Canvas, pt2
With this PR, we let the tool tell us about its state changes, i.e. it's triggering. This gets rid of a unique event type dedicated to each tool, as we now register directly with the tool.
This PR also fixes a bug in the
remove_tool
function, when a currently toggled tool gets removed fromNavigation
.