I'm running a sequence of functions (that I defined myself) in a script:
generate(file)
cut(file)
norm(file)
All these functions are manipulating the data from file. For instance:
import numpy as np
import matplotlib.pyplot as plt
def generate(file):
data=np.genfromtxt(file+'.txt')
np.save(file+'_coord',data)
print len(data)
class cutGUI(object):
def __init__(self,ax,data,file):
self.file=file
self.data=data
self.ax = ax
self.x0 = 0
self.y0 = 0
self.r = 0
self.circ=plt.Circle((self.x0,self.y0),radius=self.r,color='red',
fill=False)
self.ax.add_patch(self.circ)
self.ax.figure.canvas.mpl_connect('button_press_event',self.on_press)
self.ax.figure.canvas.mpl_connect('button_release_event',self.on_release)
def on_press(self,event):
if event.button==1:
self.x0 = event.xdata
self.y0 = event.ydata
def on_release(self,event):
if event.button==1:
self.r = np.sqrt((self.x0-event.xdata)**2+(self.y0-event.ydata)**2)
self.circ.center=self.x0,self.y0
self.circ.set_radius(self.r)
self.ax.figure.canvas.draw()
elif event.button==3:
indizes=np.where((self.data[::1,0]-self.x0)**2+(self.data[::1,1]
-self.y0)**2>self.r**2)
self.data=np.delete(self.data,indizes,axis=0)
np.save(self.file+'_coord',self.data)
plt.close('all')
def cut(file):
data=np.load(file+'_coord.npy')
x,y,z=data[::1,0],data[::1,1],data[::1,2]
fig=plt.figure(figsize=(10,10))
ax=fig.add_subplot(111,aspect='equal')
ax.scatter(x,y,s=0.5,c=z,cmap='gray',marker='.')
GUI=cutGUI(ax,data,file)
plt.show()
The point is that the cut function opens a GUI in which the data in File is manipulated graphically by hand. So the script must wait for the user to finish by pressing the right mouse button. Currently, the script is not waiting. How can I implement this?