Here is the documentation for the ginput() function. https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.ginput.html
I know that the number of clicks is kept track of internally, because the first parameter for the function is n: int, default: 1, Number of mouse clicks to accumulate. If negative, accumulate clicks until the input is terminated manually.
Is there a way to have this number saved in a variable? Here is my current working code:
# enable the user to click to add labels, store the clicks as a list of tuples called pts
tellme('You will define target labels, click to begin')
plt.waitforbuttonpress()
while True:
pts = []
tellme('Select target locations with mouse. Right click to remove most recently added point. When finished, use middle button to terminate input.')
pts = np.asarray(plt.ginput(-1, timeout=-1)) #ginput returns a list of the clicked (x, y) coordinates (a list of tuples)
print(f'Selected points: {pts}')
# is there a way to track direct middle click vs middle click after right click? that would be a solution to the one edge case
tellme('Happy? Press Enter for yes, mouse click for no')
if plt.waitforbuttonpress():
# if pts is empty, then use the raw labels as the clean label
if len(pts) == 0 & len(scan.raw_labels_polar) > 1:
pts = scan.raw_labels_polar
#if pts is empty, but not because user wants to use original labels, but rather just generate an empty csv
if len(pts) == 0 & len(scan.raw_labels_polar) == 1 & **num_clicks** > 0:
pts = []
labels.list_to_csv(pts, scan.scan_number, save_to) # save the new list of tuples as a csv in path
break
With matplotlib.backend_bases.MouseEvent you could try to count click events in a dedicated handler, for example like this: