-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MEP22 Navigation toolbar coexistence TODELETE #2759
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
Changes from 1 commit
dda0cdc
10f5dc7
08a6020
c6c0ad3
1fc29fa
979875e
c5c4f0f
97dfda7
6b647ad
99667aa
6c19579
0495aac
fb46fc1
d49c431
5ba6210
7ca8626
dcc0f16
bc703e0
68dc711
bb9f1c7
2c2e649
a99367f
3d1be34
afdd34c
5b49c7a
773db88
2ca6926
661417d
90ab64f
55dd149
15ac091
8cd241c
39f5b74
b20dade
ff94301
2cb4501
9d3c977
6e0b7e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3188,41 +3188,27 @@ class NavigationBase(object): | |
|
||
Attributes | ||
---------- | ||
canvas : `FigureCanvas` instance | ||
manager : `FigureManager` instance | ||
toolbar : `Toolbar` instance that is controlled by this `Navigation` | ||
keypresslock : `LockDraw` to know if the `canvas` key_press_event is | ||
locked | ||
messagelock : `LockDraw` to know if the message is available to write | ||
""" | ||
|
||
_default_cursor = cursors.POINTER | ||
_default_tools = [tools.ToolToggleGrid, | ||
tools.ToolToggleFullScreen, | ||
tools.ToolQuit, | ||
tools.ToolEnableAllNavigation, | ||
tools.ToolEnableNavigation, | ||
tools.ToolToggleXScale, | ||
tools.ToolToggleYScale, | ||
tools.ToolHome, tools.ToolBack, | ||
tools.ToolForward, | ||
None, | ||
tools.ToolZoom, | ||
tools.ToolPan, | ||
None, | ||
'ConfigureSubplots', | ||
'SaveFigure'] | ||
|
||
def __init__(self, canvas, toolbar=None): | ||
|
||
def __init__(self, manager): | ||
""".. automethod:: _toolbar_callback""" | ||
|
||
self.canvas = canvas | ||
self.toolbar = self._get_toolbar(toolbar, canvas) | ||
self.manager = manager | ||
self.canvas = manager.canvas | ||
self.toolbar = manager.toolbar | ||
|
||
self._key_press_handler_id = self.canvas.mpl_connect('key_press_event', | ||
self._key_press) | ||
self._key_press_handler_id = self.canvas.mpl_connect( | ||
'key_press_event', self._key_press) | ||
|
||
self._idDrag = self.canvas.mpl_connect('motion_notify_event', | ||
self._mouse_move) | ||
self._idDrag = self.canvas.mpl_connect( | ||
'motion_notify_event', self._mouse_move) | ||
|
||
# a dict from axes index to a list of view limits | ||
self.views = cbook.Stack() | ||
|
@@ -3238,36 +3224,15 @@ def __init__(self, canvas, toolbar=None): | |
# to write into toolbar message | ||
self.messagelock = widgets.LockDraw() | ||
|
||
for tool in self._default_tools: | ||
for name, tool in tools.tools: | ||
if tool is None: | ||
if self.toolbar is not None: | ||
self.toolbar.add_separator(-1) | ||
else: | ||
self.add_tool(tool) | ||
self.add_tool(name, tool, None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't feel like the right place for this I propose:
I have applied point 1, looking for the best place to do 2. I shall submit a PR with just this later today. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fariza Both points applied here (as discussed in workflow, or should I send as a PR to your branch?): I still don't quite like the structure of Given that you accept this new API method tools: (tool | tool_group, tool | tool_group, ...) where
tool_group: (tool, tool, ...) and
tool: (name, class, in_toolbar) where a separator gets automatically placed between groups. Just looked back at your comments in #3232 and see that you proposed something similar wrt Shall I code these changes up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OceanWolf Send the PR to my branch, so I can merge it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OceanWolf I don't get it, why the default tools are not added by default to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fariza PR sent. The reasoning behind that change goes as follows:
If you let me know the various other use-cases/entry points, I shall come up with a different solution :D. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you don't put add_tools in pyplot where would you put it in... for example the gtk3 backend? So it gets called automatically There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have to look into the various usecases for matplotlib, to look at entry points, but your example of the gtk3 backend could work nicely if we wanted backend customised tools/toolsets added... for example your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just want to chime in (not having followed this thread super closely) that I think it is important to separate the building of the windows (currently done via the |
||
|
||
self._last_cursor = self._default_cursor | ||
|
||
@classmethod | ||
def get_default_tools(cls): | ||
"""Get the default tools""" | ||
|
||
return cls._default_tools | ||
|
||
@classmethod | ||
def set_default_tools(cls, tools): | ||
"""Set default tools""" | ||
|
||
cls._default_tools = tools | ||
|
||
def _get_toolbar(self, toolbar, canvas): | ||
# must be inited after the window, drawingArea and figure | ||
# attrs are set | ||
if rcParams['toolbar'] == 'navigation' and toolbar is not None: | ||
toolbar = toolbar(canvas.manager) | ||
else: | ||
toolbar = None | ||
return toolbar | ||
|
||
@property | ||
def active_toggle(self): | ||
"""Toggled Tool | ||
|
@@ -3339,8 +3304,7 @@ def unregister(self, name): | |
This method is used by `PersistentTools` to remove the reference kept | ||
by `Navigation`. | ||
|
||
It is usually called by the `deactivate` method or during | ||
destroy if it is a graphical Tool. | ||
It is usually called by the `unregister` method | ||
|
||
If called, next time the `Tool` is used it will be reinstantiated | ||
instead of using the existing instance. | ||
|
@@ -3369,29 +3333,27 @@ def remove_tool(self, name): | |
if self.toolbar: | ||
self.toolbar._remove_toolitem(name) | ||
|
||
def add_tool(self, tool): | ||
def add_tool(self, name, tool, position=None): | ||
"""Add tool to `Navigation` | ||
|
||
Parameters | ||
---------- | ||
name : string | ||
Name of the tool, treated as the ID, has to be unique | ||
tool : string or `Tool` class | ||
Reference to find the class of the Tool to be added | ||
position : int or None (default) | ||
Position in the toolbar, if None, is positioned at the end | ||
""" | ||
|
||
tool_cls = self._get_cls_to_instantiate(tool) | ||
if tool_cls is False: | ||
warnings.warn('Impossible to find class for %s' % str(tool)) | ||
return | ||
name = tool_cls.name | ||
|
||
if name is None: | ||
warnings.warn('tool_clss need a name to be added, it is used ' | ||
'as ID') | ||
return | ||
if name in self._tools: | ||
warnings.warn('A tool_cls with the same name already exist, ' | ||
'not added') | ||
|
||
return | ||
|
||
self._tools[name] = tool_cls | ||
|
@@ -3402,7 +3364,7 @@ def add_tool(self, tool): | |
(k, self._keys[k], name)) | ||
self._keys[k] = name | ||
|
||
if self.toolbar and tool_cls.position is not None: | ||
if self.toolbar and tool_cls.intoolbar: | ||
# TODO: better search for images, they are not always in the | ||
# datapath | ||
basedir = os.path.join(rcParams['datapath'], 'images') | ||
|
@@ -3411,10 +3373,11 @@ def add_tool(self, tool): | |
else: | ||
fname = None | ||
toggle = issubclass(tool_cls, tools.ToolToggleBase) | ||
self.toolbar._add_toolitem(name, tool_cls.description, | ||
fname, | ||
tool_cls.position, | ||
toggle) | ||
self.toolbar._add_toolitem(name, | ||
tool_cls.description, | ||
fname, | ||
position, | ||
toggle) | ||
|
||
def _get_cls_to_instantiate(self, callback_class): | ||
if isinstance(callback_class, six.string_types): | ||
|
@@ -3463,7 +3426,7 @@ def _key_press(self, event): | |
|
||
def _get_instance(self, name): | ||
if name not in self._instances: | ||
instance = self._tools[name](self.canvas.figure) | ||
instance = self._tools[name](self.canvas.figure, name) | ||
# register instance | ||
self._instances[name] = instance | ||
|
||
|
@@ -3509,26 +3472,23 @@ def _handle_toggle(self, name, event=None, from_toolbar=False): | |
for a in self.canvas.figure.get_axes(): | ||
a.set_navigate_mode(self._toggled) | ||
|
||
def list_tools(self): | ||
"""Print the list the tools controlled by `Navigation`""" | ||
def get_tools(self): | ||
"""Return the tools controlled by `Navigation`""" | ||
|
||
print ('_' * 80) | ||
print ("{0:20} {1:50} {2}".format('Name (id)', 'Tool description', | ||
'Keymap')) | ||
print ('_' * 80) | ||
d = {} | ||
for name in sorted(self._tools.keys()): | ||
tool = self._tools[name] | ||
keys = [k for k, i in six.iteritems(self._keys) if i == name] | ||
print ("{0:20} {1:50} {2}".format(tool.name, tool.description, | ||
', '.join(keys))) | ||
print ('_' * 80, '\n') | ||
d[name] = {'cls': tool, | ||
'description': tool.description, | ||
'keymap': keys} | ||
return d | ||
|
||
def update(self): | ||
"""Reset the axes stack""" | ||
|
||
self.views.clear() | ||
self.positions.clear() | ||
# self.set_history_buttons() | ||
|
||
def _mouse_move(self, event): | ||
if not event.inaxes or not self._toggled: | ||
|
@@ -3625,7 +3585,6 @@ def push_current(self): | |
a.get_position().frozen())) | ||
self.views.push(lims) | ||
self.positions.push(pos) | ||
# self.set_history_buttons() | ||
|
||
def draw_rubberband(self, event, caller, x0, y0, x1, y1): | ||
"""Draw a rectangle rubberband to indicate zoom limits | ||
|
@@ -3677,7 +3636,7 @@ def __init__(self, manager): | |
self.manager = manager | ||
|
||
def _add_toolitem(self, name, description, image_file, position, | ||
toggle): | ||
toggle): | ||
"""Add a toolitem to the toolbar | ||
|
||
The callback associated with the button click event, | ||
|
@@ -3734,7 +3693,8 @@ def _toggle(self, name, callback=False): | |
|
||
""" | ||
|
||
# carefull, callback means to perform or not the callback while toggling | ||
# carefull, callback means to perform or not the callback while | ||
# toggling | ||
raise NotImplementedError | ||
|
||
def _remove_toolitem(self, 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.
white space issue?