def on_mouse_press(self, event):
if event.inaxes == self.electrode_ax:
if self.ui.btn_lasso.isChecked():
# Select multiple points
self.start_lasso_select(event)
elif self.ui.btn_rectangle.isChecked():
pass # handled already by rect selector
elif self.ui.btn_picker.isChecked():
# Select a single point for display
# Transform data coordinates to display coordinates
x = self.x_position
y = self.y_position
data = event.inaxes.transData.transform(zip(x, y))
# Find the closest point
distances = ((data[:, 0] - event.x)**2 +
(data[:, 1] - event.y)**2)
min_idx, min_value = np.argmin(distances), np.min(distances)
if min_value > 50:
# Don't select anything if the mouse cursor is more than
# 50 pixels away from a point
selection = {}
else:
selection = {min_idx}
add_or_remove = None
if event.key == 'shift':
add_or_remove = 'add'
elif event.key == 'control':
add_or_remove = 'remove'
self.update_inspect(selection, add_or_remove)
else:
raise AssertionError('No tool active')
else:
return
评论列表
文章目录