-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Rectangle Selector Upgrade #3937
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
2ed0d49
f8eefe6
7f044cf
f450df6
79294e0
fd264a2
438715f
e560713
5025ba2
b118294
b15cf12
e96fe81
240cfa2
7915db8
f7a9222
7c04e25
cf491db
7ece2fa
59ccd81
a033e8e
2923f97
6549538
491276e
744308c
a7518b3
77dc52b
48ebf30
3ffd7c0
e802991
af6e1b4
f5666a4
545a727
feb58fe
7bd67d2
b60a84d
840a671
2a11f5f
8da7985
cfe4df1
bc225b6
59145af
d491ac9
8e8e473
2ed0419
d5b5d86
87ab199
9eaae32
819804f
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 |
|---|---|---|
|
|
@@ -1135,14 +1135,19 @@ def _update(self): | |
|
|
||
| class _SelectorWidget(AxesWidget): | ||
|
|
||
| def __init__(self, ax, onselect, useblit=False, button=None): | ||
| def __init__(self, ax, onselect, useblit=False, button=None, | ||
| state_modifier_keys=None): | ||
| AxesWidget.__init__(self, ax) | ||
|
|
||
| self.visible = True | ||
| self.onselect = onselect | ||
| self.useblit = useblit and self.canvas.supports_blit | ||
| self.connect_default_events() | ||
|
|
||
| self.state_modifier_keys = dict(move=' ', clear='escape', | ||
| square='shift', center='ctrl') | ||
| self.state_modifier_keys.update(state_modifier_keys or {}) | ||
|
|
||
| self.background = None | ||
| self.artists = [] | ||
|
|
||
|
|
@@ -1268,7 +1273,8 @@ def press(self, event): | |
| self.eventpress = event | ||
| self._prev_event = event | ||
| key = event.key or '' | ||
|
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 should maintain the return behaviour. |
||
| if key == ' ': | ||
| key = key.replace('control', 'ctrl') | ||
|
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 don't really see this translating as a good thing to do. While the fact that we do "control" when the button is by itself and "ctrl" when it is in conjunction with something else isn't great, it is what people would see if they run the simple key-press reporting examples. Now, you are making it such that users need to target a diferent name than they expect (and it isn't even documented). I think we should remove the unneeded complexity and use
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. although, reading further, I see the problem is if one is trying to do multiple things at once, isn't it?
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. Yes. — On Mon, Aug 31, 2015 at 10:23 PM, Benjamin Root [email protected]
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. We can change the default to 'control' and reverse them, if you like. — On Mon, Aug 31, 2015 at 10:25 PM, Benjamin Root [email protected]
|
||
| if key == self.state_modifier_keys['move']: | ||
| self.state.add('move') | ||
| self._press(event) | ||
| return True | ||
|
|
@@ -1319,15 +1325,15 @@ def on_key_press(self, event): | |
| """Key press event handler and validator""" | ||
| if self.active: | ||
| key = event.key or '' | ||
| if key == 'escape': | ||
| key = key.replace('control', 'ctrl') | ||
| if key == self.state_modifier_keys['clear']: | ||
| for artist in self.artists: | ||
| artist.set_visible(False) | ||
| self.update() | ||
| return | ||
| if 'shift' in key: | ||
| self.state.add('square') | ||
| if 'ctrl' in key or 'control' in key: | ||
| self.state.add('center') | ||
| for (state, modifier) in self.state_modifier_keys.items(): | ||
| if modifier in key: | ||
| self.state.add(state) | ||
| self._on_key_press(event) | ||
|
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 a bit confused here. Shouldn't the 'clear' action be in
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. At the very least, an explanation in comments should be given to explain what should go into
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 added some docs here. Essentially the |
||
|
|
||
| def _on_key_press(self, event): | ||
|
|
@@ -1664,7 +1670,7 @@ def __init__(self, ax, onselect, drawtype='box', | |
| minspanx=None, minspany=None, useblit=False, | ||
| lineprops=None, rectprops=None, spancoords='data', | ||
| button=None, maxdist=10, marker_props=None, | ||
| interactive=False): | ||
| interactive=False, state_modifier_keys=None): | ||
|
|
||
| """ | ||
| Create a selector in *ax*. When a selection is made, clear | ||
|
|
@@ -1710,14 +1716,22 @@ def __init__(self, ax, onselect, drawtype='box', | |
| *interactive* will draw a set of handles and allow you interact | ||
| with the widget after it is drawn. | ||
|
|
||
| Keyboard modifiers: | ||
| Alt or Space moves the existing shape. | ||
| Shift makes the shape square. | ||
| Ctrl makes the initial point the center of the shape. | ||
| Ctrl and shift can be combined. | ||
| *state_modifier_keys* are keyboard modifiers that affect the behavior | ||
| of the widget. | ||
|
|
||
| The defaults are: | ||
| dict(move=' ', clear='escape', square='shift', center='ctrl') | ||
|
|
||
| Keyboard modifiers, which: | ||
| 'move': Move the existing shape. | ||
| 'clear': Clear the current shape. | ||
| 'square': Makes the shape square. | ||
| 'center': Make the initial point the center of the shape. | ||
| 'square' and 'center' can be combined. | ||
| """ | ||
| _SelectorWidget.__init__(self, ax, onselect, useblit=useblit, | ||
| button=button) | ||
| button=button, | ||
| state_modifier_keys=state_modifier_keys) | ||
|
|
||
| self.to_draw = None | ||
| self.visible = True | ||
|
|
||
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 like this. It also helps to keep all the possible actions and associated keys in one place.