RectangleSelector

In my configuration, when button is released out of the axes,
RectangleSelector does not catch the release-button event. The rectangle
patch is then left on the Axe. I found more convenient for my
application (oscopy, see oscopy.org) to catch the event even if out of
axes and limit to the boundaries of the axes. Maybe this can be of any
use to somebody else.

*** widgets.py 2012-01-05 07:03:23.723656417 +0100
--- widgets2.py 2012-01-05 07:04:29.351981851 +0100

···

***************
*** 1242,1247 ****
--- 1242,1262 ----
              return event.inaxes!= self.ax
  
          # If a button was pressed, check if the release-button is the
+ # same. If event is out of axis, limit the data coordinates to
axes
+ # boundaries.
+ if event.button == self.eventpress.button and event.inaxes !=
self.ax:
+ (xdata, ydata) =
self.ax.transData.inverted().transform_point((event.x, event.y))
+ xlim = self.ax.get_xlim()
+ ylim = self.ax.get_ylim()
+ if xdata < xlim[0]: xdata = xlim[0]
+ if xdata > xlim[1]: xdata = xlim[1]
+ if ydata < ylim[0]: ydata = ylim[0]
+ if ydata > ylim[1]: ydata = ylim[1]
+ event.xdata = xdata
+ event.ydata = ydata
+ return False
+
+ # If a button was pressed, check if the release-button is the
          # same.
          return (event.inaxes!=self.ax or
                   event.button != self.eventpress.button)

Arnaud.

I don’t have an opinion on this yet, but I do want to note that if this change were applied, then the lasso selector should probably also be changed in order to be consistent.

Ben Root

···

On Thursday, January 5, 2012, Arnaud Gardelein <arnaud@…1044…> wrote:

In my configuration, when button is released out of the axes,
RectangleSelector does not catch the release-button event. The rectangle

patch is then left on the Axe. I found more convenient for my
application (oscopy, see oscopy.org) to catch the event even if out of
axes and limit to the boundaries of the axes. Maybe this can be of any

use to somebody else.

*** widgets.py 2012-01-05 07:03:23.723656417 +0100
— widgets2.py 2012-01-05 07:04:29.351981851 +0100


*** 1242,1247 ****
— 1242,1262 ----

         return event.inaxes!= [self.ax](http://self.ax)

     # If a button was pressed, check if the release-button is the
  •     # same. If event is out of axis, limit the data coordinates to
    

axes

  •     # boundaries.
    
  •     if event.button == self.eventpress.button and event.inaxes !=
    

self.ax:

  •         (xdata, ydata) =
    

self.ax.transData.inverted().transform_point((event.x, event.y))

  •         xlim = self.ax.get_xlim()
    
  •         ylim = self.ax.get_ylim()
    
  •         if xdata < xlim[0]: xdata = xlim[0]
    
  •         if xdata > xlim[1]: xdata = xlim[1]
    
  •         if ydata < ylim[0]: ydata = ylim[0]
    
  •         if ydata > ylim[1]: ydata = ylim[1]
    
  •         event.xdata = xdata
    
  •         event.ydata = ydata
    
  •         return False
    
  •     # If a button was pressed, check if the release-button is the
    
     # same.
     return  (event.inaxes!=[self.ax](http://self.ax) or
              event.button != self.eventpress.button)

Arnaud.

This is a great fix. Would you mind submitting it as a github pull request so we can review it there?

Mike

···

On 01/05/2012 01:20 AM, Arnaud Gardelein wrote:

In my configuration, when button is released out of the axes,
RectangleSelector does not catch the release-button event. The rectangle
patch is then left on the Axe. I found more convenient for my
application (oscopy, see oscopy.org) to catch the event even if out of
axes and limit to the boundaries of the axes. Maybe this can be of any
use to somebody else.

*** widgets.py 2012-01-05 07:03:23.723656417 +0100
--- widgets2.py 2012-01-05 07:04:29.351981851 +0100
***************
*** 1242,1247 ****
--- 1242,1262 ----
               return event.inaxes!= self.ax

           # If a button was pressed, check if the release-button is the
+ # same. If event is out of axis, limit the data coordinates to
axes
+ # boundaries.
+ if event.button == self.eventpress.button and event.inaxes !=
self.ax:
+ (xdata, ydata) =
self.ax.transData.inverted().transform_point((event.x, event.y))
+ xlim = self.ax.get_xlim()
+ ylim = self.ax.get_ylim()
+ if xdata< xlim[0]: xdata = xlim[0]
+ if xdata> xlim[1]: xdata = xlim[1]
+ if ydata< ylim[0]: ydata = ylim[0]
+ if ydata> ylim[1]: ydata = ylim[1]
+ event.xdata = xdata
+ event.ydata = ydata
+ return False
+
+ # If a button was pressed, check if the release-button is the
           # same.
           return (event.inaxes!=self.ax or
                    event.button != self.eventpress.button)

Arnaud.

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Done.

···

Le jeudi 05 janvier 2012 à 07:46 -0500, Michael Droettboom a écrit :

This is a great fix. Would you mind submitting it as a github pull
request so we can review it there?

Mike

On 01/05/2012 01:20 AM, Arnaud Gardelein wrote:
> In my configuration, when button is released out of the axes,
> RectangleSelector does not catch the release-button event. The rectangle
> patch is then left on the Axe. I found more convenient for my
> application (oscopy, see oscopy.org) to catch the event even if out of
> axes and limit to the boundaries of the axes. Maybe this can be of any
> use to somebody else.
>
> *** widgets.py 2012-01-05 07:03:23.723656417 +0100
> --- widgets2.py 2012-01-05 07:04:29.351981851 +0100
> ***************
> *** 1242,1247 ****
> --- 1242,1262 ----
> return event.inaxes!= self.ax
>
> # If a button was pressed, check if the release-button is the
> + # same. If event is out of axis, limit the data coordinates to
> axes
> + # boundaries.
> + if event.button == self.eventpress.button and event.inaxes !=
> self.ax:
> + (xdata, ydata) =
> self.ax.transData.inverted().transform_point((event.x, event.y))
> + xlim = self.ax.get_xlim()
> + ylim = self.ax.get_ylim()
> + if xdata< xlim[0]: xdata = xlim[0]
> + if xdata> xlim[1]: xdata = xlim[1]
> + if ydata< ylim[0]: ydata = ylim[0]
> + if ydata> ylim[1]: ydata = ylim[1]
> + event.xdata = xdata
> + event.ydata = ydata
> + return False
> +
> + # If a button was pressed, check if the release-button is the
> # same.
> return (event.inaxes!=self.ax or
> event.button != self.eventpress.button)
>
> Arnaud.
>
>
>
> ------------------------------------------------------------------------------
> Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
> infrastructure or vast IT resources to deliver seamless, secure access to
> virtual desktops. With this all-in-one solution, easily deploy virtual
> desktops for less than the cost of PCs and save 60% on VDI infrastructure
> costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

I believe the lasso selector already does this (determined
experimentally at least) – this brings the RectangleSelector widget
in line with that.

Mike
···

On 01/05/2012 02:22 AM, Benjamin Root wrote:

  >

  >



  I don't have an opinion on this yet, but I do want to note that if

this change were applied, then the lasso selector should probably
also be changed in order to be consistent.