Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
ToolManager/Tools adding methods to set figure after initialization #6405
Conversation
mdboom
added the
needs_review
label
May 11, 2016
|
Test fail is not related |
fariza
changed the title from
adding methods to set figure after initialization to ToolManager/Tools adding methods to set figure after initialization
May 12, 2016
|
@OceanWolf can you take a look at this? |
|
I will do my best to find time to look at these two PRs soon |
|
@OceanWolf just in case you're going to rebase #4143 please take a look at this one first. Just to prevent you having to do two rebases |
|
@tacaswell I would like to have this to have reviewed by I really don't know who else to ask, maybe you or @efiring? |
OceanWolf
and 1 other
commented on an outdated diff
May 20, 2016
| + @property | ||
| + def manager(self): | ||
| + """FigureManager that owns this ToolManager""" | ||
| + return self._manager | ||
| + | ||
| + @property | ||
| + def canvas(self): | ||
| + """Canvas managed by FigureManager""" | ||
| + return self._figure.canvas | ||
| + | ||
| + @property | ||
| + def figure(self): | ||
| + """Figure that holds the canvas""" | ||
| + return self._figure | ||
| + | ||
| + def set_figure(self, figure): |
fariza
Member
|
OceanWolf
and 1 other
commented on an outdated diff
May 20, 2016
| @@ -56,14 +56,13 @@ class ToolManager(object): | ||
| `LockDraw` object to know if the message is available to write | ||
| """ | ||
| - def __init__(self, canvas): | ||
| + def __init__(self, manager): |
OceanWolf
Contributor
|
tacaswell
added this to the
2.1 (next point release)
milestone
May 21, 2016
|
@OceanWolf i got rid of the manager reference for toolmanager and added the setters for for the figures. |
|
Looks much better. One idea I had, but again perhaps too complicated (and can easily get added later), making it ToolManager.set_figure(self, figure, update_tools=False):
# snip
if update_tools:
for tool in self.tools:
tool.figure = figurethe most complicated part here comes from deciding whether the kw should default to |
|
With the second argument the property setter stops working. |
|
It doesn't stop working, because it gets passed as kwarg. |
|
What I mean is that it is impossible to change the value by calling the property setter |
|
Sure, but you have declared |
|
Done, I tried and it looks better than I thought. |
|
Yay, fabulous! I have no further comments. Anyone else? |
efiring
commented on an outdated diff
May 24, 2016
| @@ -74,6 +73,43 @@ def __init__(self, canvas): | ||
| self.keypresslock = widgets.LockDraw() | ||
| self.messagelock = widgets.LockDraw() | ||
| + if figure: | ||
| + self.figure = figure |
efiring
Owner
|
efiring
and 2 others
commented on an outdated diff
May 24, 2016
| + def canvas(self): | ||
| + """Canvas managed by FigureManager""" | ||
| + return self._figure.canvas | ||
| + | ||
| + @property | ||
| + def figure(self): | ||
| + """Figure that holds the canvas""" | ||
| + return self._figure | ||
| + | ||
| + @figure.setter | ||
| + def figure(self, figure): | ||
| + self.set_figure(figure) | ||
| + | ||
| + def set_figure(self, figure, update_tools=True): | ||
| + """ | ||
| + Set the figure that interact with tools |
efiring
Owner
|
efiring
commented on an outdated diff
May 24, 2016
| @property | ||
| def figure(self): | ||
| return self._figure | ||
| + @figure.setter | ||
| + def figure(self, figure): | ||
| + self.set_figure(figure) | ||
| + | ||
| + @property | ||
| + def canvas(self): | ||
| + return self.figure.canvas | ||
| + | ||
| + @property | ||
| + def toolmanager(self): | ||
| + return self._toolmanager | ||
| + | ||
| + def set_figure(self, figure): | ||
| + """ | ||
| + Called when the figure is setted |
efiring
Owner
|
efiring
and 1 other
commented on an outdated diff
May 24, 2016
| + self.set_figure(figure) | ||
| + | ||
| + @property | ||
| + def canvas(self): | ||
| + return self.figure.canvas | ||
| + | ||
| + @property | ||
| + def toolmanager(self): | ||
| + return self._toolmanager | ||
| + | ||
| + def set_figure(self, figure): | ||
| + """ | ||
| + Called when the figure is setted | ||
| + | ||
| + This method allows to perform special settings for tools with special | ||
| + needs |
OceanWolf
Contributor
|
|
@efiring I updated the docstrings |
|
@QuLogic the interaction is bidirectional |
|
@efiring @OceanWolf can we merge? |
|
Fine by me! |
efiring
commented on an outdated diff
Jun 2, 2016
| @property | ||
| def figure(self): | ||
| return self._figure | ||
| + @figure.setter | ||
| + def figure(self, figure): | ||
| + self.set_figure(figure) | ||
| + | ||
| + @property | ||
| + def canvas(self): | ||
| + return self.figure.canvas |
efiring
Owner
|
efiring
and 2 others
commented on an outdated diff
Jun 2, 2016
| @@ -74,6 +72,44 @@ def __init__(self, canvas): | ||
| self.keypresslock = widgets.LockDraw() | ||
| self.messagelock = widgets.LockDraw() | ||
| + self._figure = None | ||
| + if figure: | ||
| + self.set_figure(figure) | ||
| + | ||
| + @property | ||
| + def canvas(self): | ||
| + """Canvas managed by FigureManager""" | ||
| + return self._figure.canvas |
efiring
Owner
|
OceanWolf
commented on the diff
Jun 2, 2016
| + | ||
| + @property | ||
| + def canvas(self): | ||
| + """Canvas managed by FigureManager""" | ||
| + return self._figure.canvas | ||
| + | ||
| + @property | ||
| + def figure(self): | ||
| + """Figure that holds the canvas""" | ||
| + return self._figure | ||
| + | ||
| + @figure.setter | ||
| + def figure(self, figure): | ||
| + self.set_figure(figure) | ||
| + | ||
| + def set_figure(self, figure, update_tools=True): |
OceanWolf
Contributor
|
OceanWolf
commented on an outdated diff
Jun 2, 2016
| + def set_figure(self, figure, update_tools=True): | ||
| + """ | ||
| + Sets the figure to interact with the tools | ||
| + | ||
| + Parameters | ||
| + ========== | ||
| + figure: `Figure` | ||
| + update_tools: bool | ||
| + Force tools to update figure | ||
| + """ | ||
| + | ||
| + if self._key_press_handler_id: | ||
| + self.canvas.mpl_disconnect(self._key_press_handler_id) | ||
| + self._figure = figure | ||
| + self._key_press_handler_id = self.canvas.mpl_connect( | ||
| + 'key_press_event', self._key_press) |
OceanWolf
Contributor
|
|
@efiring that was a good catch, I modified the code so, it returns |
OceanWolf
and 1 other
commented on an outdated diff
Jun 3, 2016
| @@ -245,6 +283,8 @@ def add_tool(self, name, tool, *args, **kwargs): | ||
| else: | ||
| self._toggled.setdefault(tool_obj.radio_group, None) | ||
| + if self.figure: | ||
| + tool_obj.set_figure(self.figure) |
OceanWolf
Contributor
|
|
I just removed the last check for figure that I forgot in the |
|
I think this is ready to merge |
efiring
merged commit e69e565
into matplotlib:master
Jun 9, 2016
efiring
removed the
needs_review
label
Jun 9, 2016
|
Ahh, I was going to say squash the commits first, but okay. @fariza which other PR did you want me to look at? |
fariza commentedMay 11, 2016
Wanting to cross control figures (tool from one FigureManger affects a figure from other FigureManager) the setting of the figure is separated from the initialization
The changes are :
ToolManager.__init__andToolBase.__init__set_figureis called explicitly on the ToolManager and ToolBase objects