-
-
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 |
|---|---|---|
|
|
@@ -1140,11 +1140,11 @@ def __init__(self, ax, onselect, useblit=False, button=None): | |
|
|
||
| self.visible = True | ||
| self.onselect = onselect | ||
| self.useblit = useblit and self.canvas.supports_blit | ||
| self.connect_default_events() | ||
|
|
||
| self.background = None | ||
| self.artists = [] | ||
| self.useblit = useblit and self.canvas.supports_blit | ||
|
|
||
| if isinstance(button, int): | ||
| self.validButtons = [button] | ||
|
|
@@ -1172,13 +1172,13 @@ def update_background(self, event): | |
|
|
||
| def connect_default_events(self): | ||
| """Connect the major canvas events to methods.""" | ||
| self.connect_event('motion_notify_event', self._onmove) | ||
| self.connect_event('button_press_event', self._press) | ||
| self.connect_event('button_release_event', self._release) | ||
| self.connect_event('motion_notify_event', self.onmove) | ||
| self.connect_event('button_press_event', self.press) | ||
| self.connect_event('button_release_event', self.release) | ||
| self.connect_event('draw_event', self.update_background) | ||
| self.connect_event('key_press_event', self._on_key_press) | ||
| self.connect_event('key_release_event', self._on_key_release) | ||
| self.connect_event('scroll_event', self._on_scroll) | ||
| self.connect_event('key_press_event', self.on_key_press) | ||
| self.connect_event('key_release_event', self.on_key_release) | ||
| self.connect_event('scroll_event', self.on_scroll) | ||
|
|
||
| def ignore(self, event): | ||
| """return *True* if *event* should be ignored""" | ||
|
|
@@ -1258,7 +1258,7 @@ def _clean_event(self, event): | |
| self._prev_event = event | ||
| return event | ||
|
|
||
| def _press(self, event): | ||
| def press(self, event): | ||
| """Button press handler and validator""" | ||
| if not self.ignore(event): | ||
| event = self._clean_event(event) | ||
|
|
@@ -1267,68 +1267,68 @@ def _press(self, event): | |
| key = event.key or '' | ||
| if 'alt' in key or key == ' ': | ||
| self.state.add('move') | ||
| self.press(event) | ||
| self._press(event) | ||
|
|
||
| def press(self, event): | ||
| def _press(self, event): | ||
| """Button press handler""" | ||
| pass | ||
|
|
||
| def _release(self, event): | ||
| def release(self, event): | ||
| """Button release event handler and validator""" | ||
| if not self.ignore(event) and self.eventpress: | ||
| event = self._clean_event(event) | ||
| self.eventrelease = event | ||
| self.release(event) | ||
| self._release(event) | ||
| self.state.discard('move') | ||
|
|
||
| def release(self, event): | ||
| def _release(self, event): | ||
| """Button release event handler""" | ||
| pass | ||
|
|
||
| def _onmove(self, event): | ||
| def onmove(self, event): | ||
| """Cursor move event handler and validator""" | ||
| if not self.ignore(event) and self.eventpress: | ||
| event = self._clean_event(event) | ||
| self.onmove(event) | ||
| self._onmove(event) | ||
|
|
||
| def onmove(self, event): | ||
| def _onmove(self, event): | ||
| """Cursor move event handler""" | ||
| pass | ||
|
|
||
| def _on_scroll(self, event): | ||
| def on_scroll(self, event): | ||
| """Mouse scroll event handler and validator""" | ||
| if not self.ignore(event): | ||
| self.on_scroll(event) | ||
| self._on_scroll(event) | ||
|
|
||
| def on_scroll(self, event): | ||
| def _on_scroll(self, event): | ||
| """Mouse scroll event handler""" | ||
| pass | ||
|
|
||
| def _on_key_press(self, event): | ||
| def on_key_press(self, event): | ||
| """Key press event handler and validator""" | ||
| if self.active: | ||
| key = event.key or '' | ||
| if 'shift' in key: | ||
| self.state.add('square') | ||
| if 'ctrl' in key or 'control' in key: | ||
| self.state.add('center') | ||
| self.on_key_press(event) | ||
| 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): | ||
| def _on_key_press(self, event): | ||
| """Key press event handler""" | ||
| pass | ||
|
|
||
| def _on_key_release(self, event): | ||
| def on_key_release(self, event): | ||
| """Key release event handler and validator""" | ||
| if self.active: | ||
| key = event.key or '' | ||
| if 'shift' in key: | ||
| self.state.discard('square') | ||
| if 'ctrl' in key or 'control' in key: | ||
| self.state.discard('center') | ||
|
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. These if-statements should be using the state_modifiier_keys dictionary. |
||
| self.on_key_release(event) | ||
| self._on_key_release(event) | ||
|
|
||
| def on_key_release(self, event): | ||
| def _on_key_release(self, event): | ||
| """Key release event handler""" | ||
| pass | ||
|
|
||
|
|
@@ -1458,7 +1458,7 @@ def ignore(self, event): | |
| """return *True* if *event* should be ignored""" | ||
| return _SelectorWidget.ignore(self, event) or not self.visible | ||
|
|
||
| def press(self, event): | ||
| def _press(self, 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. What's the reason for this API change? While I doubt anyone is directly using these, could it mess up people would might be subclassing this Widget?
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. They are welcome to override
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. Ah, I missed that this class already has those methods inherited already. Yeah, this is probably the better design. |
||
| """on button press event""" | ||
| self.rect.set_visible(self.visible) | ||
| if self.span_stays: | ||
|
|
@@ -1471,7 +1471,7 @@ def press(self, event): | |
| self.pressv = ydata | ||
| return False | ||
|
|
||
| def release(self, event): | ||
| def _release(self, event): | ||
| """on button release event""" | ||
| if self.pressv is None: | ||
| return | ||
|
|
@@ -1503,7 +1503,7 @@ def release(self, event): | |
| self.pressv = None | ||
| return False | ||
|
|
||
| def onmove(self, event): | ||
| def _onmove(self, event): | ||
| """on motion notify event""" | ||
| if self.pressv is None: | ||
| return | ||
|
|
@@ -1752,7 +1752,7 @@ def __init__(self, ax, onselect, drawtype='patch', | |
| self._corner_handles.artist, | ||
| self._edge_handles.artist] | ||
|
|
||
| def press(self, event): | ||
| def _press(self, event): | ||
| """on button press event""" | ||
| # make the drawed box/line visible get the click-coordinates, | ||
| # button, ... | ||
|
|
@@ -1765,7 +1765,7 @@ def press(self, event): | |
|
|
||
| self.set_visible(self.visible) | ||
|
|
||
| def release(self, event): | ||
| def _release(self, event): | ||
| """on button release event""" | ||
| if self.spancoords == 'data': | ||
| xmin, ymin = self.eventpress.xdata, self.eventpress.ydata | ||
|
|
@@ -1812,7 +1812,7 @@ def release(self, event): | |
|
|
||
| return False | ||
|
|
||
| def onmove(self, event): | ||
| def _onmove(self, event): | ||
| """on motion notify event if box/line is wanted""" | ||
| # resize an existing shape | ||
| if self.active_handle and not self.active_handle == 'C': | ||
|
|
@@ -2084,22 +2084,22 @@ def __init__(self, ax, onselect=None, useblit=True, lineprops=None, | |
| def onpress(self, event): | ||
| self.press(event) | ||
|
|
||
| def press(self, event): | ||
| def _press(self, event): | ||
| self.verts = [self._get_data(event)] | ||
| self.line.set_visible(True) | ||
|
|
||
| def onrelease(self, event): | ||
| self.release(event) | ||
|
|
||
| def release(self, event): | ||
| def _release(self, event): | ||
| if self.verts is not None: | ||
| self.verts.append(self._get_data(event)) | ||
| self.onselect(self.verts) | ||
| self.line.set_data([[], []]) | ||
| self.line.set_visible(False) | ||
| self.verts = None | ||
|
|
||
| def onmove(self, event): | ||
| def _onmove(self, event): | ||
| if self.verts is None: | ||
| return | ||
| self.verts.append(self._get_data(event)) | ||
|
|
||
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.
Any reason for allowing two keys here? I'd just pick the space character and go with it.
Tangentially, I am not a fan of these hard-coded special keys. While they are fine as defaults, an application developer may already have these keys mapped to something and would want something different. So, it might be a good idea to have them able to be defined in the constructor.
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 had originally used
Alt, since it is used by Gimp, but it did not work on Windows IIRC. I'll add these to the constructor.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.
In my Gnome desktop, Alt and holding down the mouse button will result in moving the entire figure window.
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.
Yeah, we'll default to space.