-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
MEP22: Navigation by events #3652
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
8cceed4
3118a5a
b4d5fcf
1e8af47
622cb95
d1a9de4
3f89d52
4f3c10b
6065daa
f6a2f19
05db3b6
c08fe56
b207a72
9266447
a53419a
704c717
5056729
e6a4e1e
8942c47
022de6f
2c9a195
cafe668
224f745
94c711e
67257e7
ffa65d6
6739ee0
d18206f
34a52c8
c2da483
44a9b0e
a2ed47f
0665890
411e6e2
d484ebd
75bf97b
6cc040b
0ff5997
af6734f
78513d2
377ff54
7dbbf58
dd66b57
67a414f
e415d8d
1213086
ba61dec
9f2ee2b
9da2b13
110253f
e2804ea
9a64b7e
64f947f
e8cd5d5
4bbcf4e
73a2661
1b83628
e4edd23
d4ac2fb
a7640ef
48a6971
8dafe09
a0695d0
328b169
aac4744
f09b9ef
def3a52
9ee7e25
5eae4e1
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 |
|---|---|---|
|
|
@@ -2586,6 +2586,8 @@ def __init__(self, canvas, num): | |
| self.key_press_handler_id = self.canvas.mpl_connect( | ||
| 'key_press_event', | ||
| self.key_press) | ||
|
Member
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. Should
Member
Author
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. Eventually
Member
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 am torn on this one, I see @fariza point that this is on it's way out, but I also don't like variable attributes on objects (just because you can doesn't mean you should). On the other hand, this is the only place in our code base that we reference This would only be used to deregister a call back, does that code cope well with
Member
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 was added to make it possible for users to disable the default keymap
Member
Author
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. done, I added the |
||
| else: | ||
| self.key_press_handler_id = None | ||
| """ | ||
| The returned id from connecting the default key handler via | ||
| :meth:`FigureCanvasBase.mpl_connnect`. | ||
|
|
@@ -3331,11 +3333,7 @@ def message_event(self, message, sender=None): | |
|
|
||
| @property | ||
| def active_toggle(self): | ||
| """ | ||
| Toggled Tool | ||
|
|
||
| **dict** : Currently toggled tools | ||
| """ | ||
| """Currently toggled tools""" | ||
|
|
||
| return self._toggled | ||
|
|
||
|
|
@@ -3360,7 +3358,7 @@ def _remove_keys(self, name): | |
| for k in self.get_tool_keymap(name): | ||
| del self._keys[k] | ||
|
|
||
| def set_tool_keymap(self, name, *keys): | ||
| def update_keymap(self, name, *keys): | ||
| """ | ||
| Set the keymap to associate with the specified tool | ||
|
Member
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. Can you clarify this a bit. This is setting a property of
Member
Author
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. What do you think of renaming to
Member
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. How about It might also be worth adding a
Member
Author
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. rename done, not sure about
Member
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. is this done and not pushed? I am not seeing the code change....
Member
Author
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 am finishing all the current comments and push the commit, give me 5 😉 |
||
|
|
||
|
|
@@ -3449,30 +3447,31 @@ def add_tool(self, name, tool, *args, **kwargs): | |
| """ | ||
|
|
||
| tool_cls = self._get_cls_to_instantiate(tool) | ||
| if tool_cls is False: | ||
| if not tool_cls: | ||
| raise ValueError('Impossible to find class for %s' % str(tool)) | ||
|
|
||
| if name in self._tools: | ||
|
Member
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. Should this be done first in this function? Do we want to check to make sure that they are the same type? Again, why warn rather than raise?
Member
Author
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 used warn because i don't think that adding twice the same tool represents a major fault and your program will keep working as expected (you already have the tool) |
||
| warnings.warn('A "Tool class" with the same name already exists, ' | ||
| 'not added') | ||
| return self._tools[name] | ||
|
|
||
| self._tools[name] = tool_cls(self, name, *args, **kwargs) | ||
| tool_obj = tool_cls(self, name, *args, **kwargs) | ||
| self._tools[name] = tool_obj | ||
|
|
||
| if tool_cls.keymap is not None: | ||
| self.set_tool_keymap(name, tool_cls.keymap) | ||
| if tool_cls.default_keymap is not None: | ||
| self.update_keymap(name, tool_cls.default_keymap) | ||
|
|
||
| # For toggle tools init the radio_group in self._toggled | ||
| if isinstance(self._tools[name], tools.ToolToggleBase): | ||
| if isinstance(tool_obj, tools.ToolToggleBase): | ||
| # None group is not mutually exclusive, a set is used to keep track | ||
| # of all toggled tools in this group | ||
| if tool_cls.radio_group is None: | ||
| if tool_obj.radio_group is None: | ||
| self._toggled.setdefault(None, set()) | ||
| else: | ||
| self._toggled.setdefault(tool_cls.radio_group, None) | ||
| self._toggled.setdefault(tool_obj.radio_group, None) | ||
|
|
||
| self._tool_added_event(self._tools[name]) | ||
| return self._tools[name] | ||
| self._tool_added_event(tool_obj) | ||
| return tool_obj | ||
|
|
||
| def _tool_added_event(self, tool): | ||
| s = 'tool_added_event' | ||
|
|
@@ -3483,6 +3482,16 @@ def _handle_toggle(self, tool, sender, canvasevent, data): | |
| """ | ||
|
Member
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. Can you put docstrings on these with the expected types?
Member
Author
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. done |
||
| Toggle tools, need to untoggle prior to using other Toggle tool | ||
| Called from tool_trigger_event | ||
|
|
||
| Parameters | ||
| ---------- | ||
| tool: Tool object | ||
| sender: object | ||
| Object that wishes to trigger the tool | ||
| canvasevent : Event | ||
| Original Canvas event or None | ||
| data : Object | ||
| Extra data to pass to the tool when triggering | ||
| """ | ||
|
|
||
| radio_group = tool.radio_group | ||
|
|
@@ -3500,7 +3509,7 @@ def _handle_toggle(self, tool, sender, canvasevent, data): | |
| toggled = None | ||
| # If no tool was toggled in the radio_group | ||
| # toggle it | ||
| elif self._toggled.get(radio_group, None) is None: | ||
| elif self._toggled[radio_group] is None: | ||
| toggled = tool.name | ||
| # Other tool in the radio_group is toggled | ||
| else: | ||
|
|
@@ -3521,15 +3530,18 @@ def _get_cls_to_instantiate(self, callback_class): | |
| if isinstance(callback_class, six.string_types): | ||
| # FIXME: make more complete searching structure | ||
| if callback_class in globals(): | ||
| return globals()[callback_class] | ||
|
|
||
| mod = self.__class__.__module__ | ||
| current_module = __import__(mod, | ||
| globals(), locals(), [mod], 0) | ||
| callback_class = globals()[callback_class] | ||
| else: | ||
| mod = self.__class__.__module__ | ||
| current_module = __import__(mod, | ||
| globals(), locals(), [mod], 0) | ||
|
|
||
| return getattr(current_module, callback_class, False) | ||
| callback_class = getattr(current_module, callback_class, False) | ||
|
|
||
| return callback_class | ||
| if callable(callback_class): | ||
| return callback_class | ||
| else: | ||
| return None | ||
|
|
||
| def tool_trigger_event(self, name, sender=None, canvasevent=None, | ||
|
Member
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 name is a bit too ambiguous, can it be
Member
Author
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. Agree, what do you think of just
Member
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. 👍 to 'trigger_tool'
Member
Author
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. done |
||
| data=None): | ||
|
|
@@ -3598,7 +3610,7 @@ def get_tool(self, name, warn=True): | |
| ----------- | ||
| name : str, ToolBase | ||
| Name of the tool, or the tool itself | ||
| warn : bool | ||
| warn : bool, optional | ||
| If this method should give warnings. | ||
| """ | ||
| if isinstance(name, tools.ToolBase) and name.name in self._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.
same here, should be a class docstring