From: Arnaud G. <ar...@os...> - 2012-01-05 06:38:20
|
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. |