MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / _set_active_handle

Method _set_active_handle

site-packages/matplotlib/widgets.py:2332–2361  ·  view source on GitHub ↗

Set active handle based on the location of the mouse event

(self, event)

Source from the content-addressed store, hash-verified

2330 self.to_draw.set_data([xmin, xmax], [ymin, ymax])
2331
2332 def _set_active_handle(self, event):
2333 """Set active handle based on the location of the mouse event"""
2334 # Note: event.xdata/ydata in data coordinates, event.x/y in pixels
2335 c_idx, c_dist = self._corner_handles.closest(event.x, event.y)
2336 e_idx, e_dist = self._edge_handles.closest(event.x, event.y)
2337 m_idx, m_dist = self._center_handle.closest(event.x, event.y)
2338
2339 if 'move' in self.state:
2340 self.active_handle = 'C'
2341 self._extents_on_press = self.extents
2342
2343 # Set active handle as closest handle, if mouse click is close enough.
2344 elif m_dist < self.maxdist * 2:
2345 self.active_handle = 'C'
2346 elif c_dist > self.maxdist and e_dist > self.maxdist:
2347 self.active_handle = None
2348 return
2349 elif c_dist < e_dist:
2350 self.active_handle = self._corner_order[c_idx]
2351 else:
2352 self.active_handle = self._edge_order[e_idx]
2353
2354 # Save coordinates of rectangle at the start of handle movement.
2355 x1, x2, y1, y2 = self.extents
2356 # Switch variables so that only x2 and/or y2 are updated on move.
2357 if self.active_handle in ['W', 'SW', 'NW']:
2358 x1, x2 = x2, event.xdata
2359 if self.active_handle in ['N', 'NW', 'NE']:
2360 y1, y2 = y2, event.ydata
2361 self._extents_on_press = x1, x2, y1, y2
2362
2363 @property
2364 def geometry(self):

Callers 1

_pressMethod · 0.95

Calls 1

closestMethod · 0.80

Tested by

no test coverage detected