Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2ed0d49
Store prev event to handle out of bounds selections
blink1073 Dec 19, 2014
f8eefe6
Upgrade RectangleSelector with ToolHandles and add Ellipse
blink1073 Dec 19, 2014
7f044cf
Add toolhandles class
blink1073 Dec 19, 2014
f450df6
Add test using tool handles
blink1073 Dec 19, 2014
79294e0
Add a helper function to get axes
blink1073 Dec 19, 2014
fd264a2
Do not allow extents outside the image and add a path property
blink1073 Dec 19, 2014
438715f
Finish rectangle handle tests and add ellipse test with key modifiers
blink1073 Dec 19, 2014
e560713
Rename path property to geometry and return consistent results.
blink1073 Dec 20, 2014
5025ba2
Add geometry tests.
blink1073 Dec 20, 2014
b118294
Remove extra line.
blink1073 Dec 20, 2014
b15cf12
Refactor the event handling methods
blink1073 Dec 20, 2014
e96fe81
Update rectangle logic to include '_moving'
blink1073 Dec 20, 2014
240cfa2
Clean up event handling and add a state attribute
blink1073 Dec 20, 2014
7915db8
Add state handling to onmove
blink1073 Dec 20, 2014
f7a9222
More "state" refactoring
blink1073 Dec 20, 2014
7c04e25
Add key release and continue refactoring state handling
blink1073 Dec 20, 2014
cf491db
Recreate the _get_data method and more event refactoring
blink1073 Dec 20, 2014
7ece2fa
Refactor the event creator to call the private methods
blink1073 Dec 20, 2014
59ccd81
Preserve existing api for event handler functions
blink1073 Dec 21, 2014
a033e8e
Preserve event return values
blink1073 Dec 24, 2014
2923f97
Add cleanup to tests and fix default rect prop
blink1073 Dec 24, 2014
6549538
Pep8 fixes
blink1073 Dec 24, 2014
491276e
Fix bug in SpanSelector when blit=True
blink1073 Jan 17, 2015
744308c
Clear events after valid release
blink1073 Jan 18, 2015
a7518b3
Do not attempt to draw artists if ax is invisible
blink1073 Jan 18, 2015
77dc52b
Ignore events when axes are invisible
blink1073 Jan 18, 2015
48ebf30
Fix span selector onmove when we exit axes
blink1073 Feb 21, 2015
3ffd7c0
Restore previous behaviour and allow escape to clear the current sele…
blink1073 Aug 19, 2015
e802991
Fix failing tests
blink1073 Aug 19, 2015
af6e1b4
Fix handling of center handle
blink1073 Aug 20, 2015
f5666a4
Remove debug print
blink1073 Aug 20, 2015
545a727
STY: PEP8
tacaswell Aug 22, 2015
feb58fe
FIX: do not call draw_idle if blitting
tacaswell Aug 22, 2015
7bd67d2
DOC: make rectangle demo use handles
tacaswell Aug 22, 2015
b60a84d
Add docstring for EllipseSelector and use print() statements
blink1073 Aug 22, 2015
840a671
Revert to old draw types and add docs about key modifiers
blink1073 Aug 23, 2015
2a11f5f
Revert change to the example
blink1073 Aug 23, 2015
8da7985
Remove extra draw_idle trigger
blink1073 Aug 23, 2015
cfe4df1
Update the docstring
blink1073 Aug 23, 2015
bc225b6
Remove extraneous doc
blink1073 Aug 23, 2015
59145af
Fix failing test
blink1073 Aug 23, 2015
d491ac9
Update docstring, use self.useblit, use space for move
blink1073 Aug 25, 2015
8e8e473
Use new state_modifier_keys dictionary
blink1073 Aug 26, 2015
2ed0419
Clear the active handle when invisible
blink1073 Aug 26, 2015
d5b5d86
Collapse the shape on improper draw to prevent showing the previous s…
blink1073 Aug 26, 2015
87ab199
Fix test using 'alt' key
blink1073 Aug 26, 2015
9eaae32
Clean up and add more docs
blink1073 Sep 1, 2015
819804f
Make on_key_release use the state_modifier_keys
blink1073 Sep 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use new state_modifier_keys dictionary
  • Loading branch information
blink1073 committed Aug 26, 2015
commit 8e8e473259c91dab2a031dcf7e9e3957d05e9030
42 changes: 28 additions & 14 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Copy Markdown
Member

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.

self.state_modifier_keys.update(state_modifier_keys or {})

self.background = None
self.artists = []

Expand Down Expand Up @@ -1268,7 +1273,8 @@ def press(self, event):
self.eventpress = event
self._prev_event = event
key = event.key or ''
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 control up above for the default dictionary.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. 


Sent from Mailbox

On Mon, Aug 31, 2015 at 10:23 PM, Benjamin Root [email protected]
wrote:

     if not self.ignore(event):
  •        self.eventpress = copy.copy(event)
    
  •        self.eventpress.xdata, self.eventpress.ydata = (
    
  •            self._get_data(event))
    
  •        event = self._clean_event(event)
    
  •        self.eventpress = event
    
  •        self._prev_event = event
    
  •        key = event.key or ''
    
  •        key = key.replace('control', 'ctrl')
    

    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 control up above for the default dictionary.

    Reply to this email directly or view it on GitHub:
    https://github.com/matplotlib/matplotlib/pull/3937/files#r38382631

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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. 


Sent from Mailbox

On Mon, Aug 31, 2015 at 10:25 PM, Benjamin Root [email protected]
wrote:

     if not self.ignore(event):
  •        self.eventpress = copy.copy(event)
    
  •        self.eventpress.xdata, self.eventpress.ydata = (
    
  •            self._get_data(event))
    
  •        event = self._clean_event(event)
    
  •        self.eventpress = event
    
  •        self._prev_event = event
    
  •        key = event.key or ''
    
  •        key = key.replace('control', 'ctrl')
    

    although, reading further, I see the problem is if one is trying to do multiple things at once, isn't it?

    Reply to this email directly or view it on GitHub:
    https://github.com/matplotlib/matplotlib/pull/3937/files#r38382713

if key == self.state_modifier_keys['move']:
self.state.add('move')
self._press(event)
return True
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 _on_key_press? Shouldn't the 'clear' state get implemented through the state handling mechanism you set up here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 on_key_press and _on_key_press and other pairs of methods like it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some docs here. Essentially the _ methods are for Widget-specific things, and the top level is meant for all Selection widgets. Clear is not so much as state as an action - clear the current selection.


def _on_key_press(self, event):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down