def mouse_event(self, *args): """ intercept mouse event if pause """ if not self._pause: event = self.events[-1] ## bug: does not change _plt.axes(event.inaxes) ## subplot axes automatically _BlockMouse.mouse_event(self, *args) elif self.n > 0: self.n += 1
def key_event(self, *args): """ intercept key event """ intercepted = False key = self.events[-1].key if self._key_event.has_key(key): self._key_event[key](self) self.events.pop() else: _BlockMouse.key_event(self, *args)
def ginput(self, n=1, timeout=30, show_clicks=True): """ call signature:: ginput(self, n=1, timeout=30, show_clicks=True) Blocking call to interact with the figure. This will wait for *n* clicks from the user and return a list of the coordinates of each click. If *timeout* is zero or negative, does not timeout. If *n* is zero or negative, accumulate clicks until a middle click (or potentially both mouse buttons at once) terminates the input. Right clicking cancels last input. The keyboard can also be used to select points in case your mouse does not have one or more of the buttons. The delete and backspace keys act like right clicking (i.e., remove last point), the enter key terminates input and any other key (not already used by the window manager) selects a point. """ blocking_mouse_input = BlockingMouseInput(self) return blocking_mouse_input(n=n, timeout=timeout, show_clicks=show_clicks)
def __init__(self, fig, mouse_add=1, mouse_pop=3, mouse_stop=2, key_pause='p', **key_event): _BlockMouse.__init__(self, fig=fig, mouse_add=mouse_add, mouse_pop=mouse_pop, mouse_stop=mouse_stop) self._pause = False key_event[key_pause] = self.switch_pause self._key_event = key_event
def __call__(self, n=0, p=0, timeout=30, show_clicks=True): """ Blocking call to retrieve the drawn polylines. n is the number of points per polylines, and p the number of polylines 0 means no limit return the clicks as a list of (x,y) tuples (w/o polyline structure) """ self.N = n if n != 0 else _np.inf self.lines = [] _BlockMouse.__call__(self, n=n * p, timeout=timeout, show_clicks=show_clicks) return self.clicks
def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1, mouse_pop=3, mouse_stop=2): """ call signature:: ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1, mouse_pop=3, mouse_stop=2) Blocking call to interact with the figure. This will wait for *n* clicks from the user and return a list of the coordinates of each click. If *timeout* is zero or negative, does not timeout. If *n* is zero or negative, accumulate clicks until a middle click (or potentially both mouse buttons at once) terminates the input. Right clicking cancels last input. The buttons used for the various actions (adding points, removing points, terminating the inputs) can be overriden via the arguments *mouse_add*, *mouse_pop* and *mouse_stop*, that give the associated mouse button: 1 for left, 2 for middle, 3 for right. The keyboard can also be used to select points in case your mouse does not have one or more of the buttons. The delete and backspace keys act like right clicking (i.e., remove last point), the enter key terminates input and any other key (not already used by the window manager) selects a point. """ blocking_mouse_input = BlockingMouseInput(self, mouse_add=mouse_add, mouse_pop=mouse_pop, mouse_stop=mouse_stop) return blocking_mouse_input(n=n, timeout=timeout, show_clicks=show_clicks)
def ginput(self, n=1, timeout=30, show_clicks=True): """ call signature:: ginput(self, n=1, timeout=30, show_clicks=True) Blocking call to interact with the figure. This will wait for *n* clicks from the user and return a list of the coordinates of each click. If *timeout* is negative, does not timeout. If *n* is negative, accumulate clicks until a middle click terminates the input. Right clicking cancels last input. """ blocking_mouse_input = BlockingMouseInput(self) return blocking_mouse_input(n=n, timeout=timeout, show_clicks=show_clicks)