Commit d3bcae7a authored by Julio Tambara's avatar Julio Tambara
Browse files

Add hotkeys(up,Down,left,Right)

parent 3d2d810d
......@@ -10,15 +10,18 @@ import tkMessageBox
import tkFileDialog
import matplotlib.pyplot as plt
import time
import subprocess
from pylab import *
from clsbeep import *
#from clsbeep import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
##############################################################################
##############################################################################
# Subprocess variable
#def start()
child = pexpect.spawn('./N957Run')
time.sleep(3.3)
......@@ -50,12 +53,14 @@ f = plt.figure()
f2 = plt.figure()
a = f.add_subplot(111)
a2 = f2.add_subplot(111)
Control = dict(t=1200, bmin=0, bmax=8192, bmaxold=512, j=0, filename='temp', count=0, paused=True, ROIctrl=list(), start=False)
PlotLimControl = dict(limupdt=True, limctrl=False, x0=0, y0=0, x1=512, y1=0, pressx=0., pressy=0., limtrans=False, dx=0., dy=0.)
Control = dict(t=600, bmin=0, bmax=8192, bmaxold=512, j=0, filename='temp', count=0, paused=True, ROIctrl=list(),CALIctrl=list(), start=False)
PlotLimControl = dict(limupdtx=True,limupdty=True,limupdt=True, limctrl=False, x0=0, y0=0, x1=512, y1=0, pressx=0., pressy=0., limtrans=False, dx=0., dy=0., limupdt_b=True, limupdt_bx=True, limupdt_by=True, limctrl_b=False, x0_b=0, y0_b=0, x1_b=512, y1_b=0, pressx_b=0., pressy_b=0., limtrans_b=False, dx_b=0., dy_b=0.)
FocusControl = dict( graphic1= True, graphic2=False)
Data=list()
ROIs=list()
for j in range(8192):
Data.insert(j, 0)
Data.insert(j, 0)
##############################################################################
##############################################################################
......@@ -64,6 +69,7 @@ for j in range(8192):
root = tk.Tk()
root.minsize(825,640)
root.title('Modulo Multicanal')
root.protocol('WM_DELETE_WINDOW', sys.exit)
##############################################################################
##############################################################################
......@@ -81,10 +87,10 @@ def beep():
##############################################################################
# Atualiza grade do plot de acordo com regiao escolhida
def grid(a, n , major,minor):
a.xaxis.set_major_locator(major)
def grid(a, n):
a.xaxis.set_major_locator(MultipleLocator(n/8))
if n > 64:
a.xaxis.set_minor_locator(minor)
a.xaxis.set_minor_locator(MultipleLocator(n/64))
a.xaxis.grid(True,'major',linewidth=2)
a.grid(True)
a.xaxis.grid(True,'minor')
......@@ -250,19 +256,16 @@ def graphic2(Data): #Plot
temp.set_ydata(Data)
temp2.set_xdata(range(int(Interface['spinboxes'][0].get())))
temp2.set_ydata(Data)
#if PlotLimControl['limupdt']:
# plt.xlim(Control['bmin'], Control['bmax'])
# plt.ylim(0, max(Data[int(Control['bmin']):int(Control['bmax'])])*1.2)
a.relim()
a2.relim()
a.autoscale_view()
a2.autoscale_view()
major = MultipleLocator(int(Interface['spinboxes'][0].get())/8)
minor = MultipleLocator( int(Interface['spinboxes'][0].get())/64)
if PlotLimControl['limupdt'] == True:
grid(a, int(Interface['spinboxes'][0].get()),major,minor)
if PlotLimControl['limupdt'] == True:
grid(a2, int(Interface['spinboxes'][0].get()),major,minor)
if PlotLimControl['limupdtx'] or PlotLimControl['limupdty']:
a.relim()
a.autoscale_view(scaley=PlotLimControl['limupdty'],scalex=PlotLimControl['limupdtx'])
if PlotLimControl['limupdt_bx'] or PlotLimControl['limupdt_by'] :
a2.relim()
a2.autoscale_view(scaley=PlotLimControl['limupdt_by'],scalex=PlotLimControl['limupdt_bx'])
if PlotLimControl['limupdtx'] == True:
grid(a, int(Interface['spinboxes'][0].get()))
if PlotLimControl['limupdt_bx'] == True:
grid(a2, int(Interface['spinboxes'][0].get()))
f.canvas.draw()
f2.canvas.draw()
......@@ -378,6 +381,34 @@ def refreshrate(): # Define a frequencia de atualizacao do grafico
rrbut.pack(side='left')
rrwin.mainloop()
def str_cali():
caliwin = tk.Tk()
caliwin.title('Straight Calibration')
calient = tk.Entry(caliwin)
calient.pack(side='right')
Control['j'] = 0
def addpoint():
Labelsf.insert(Control['j'], tk.LabelFrame(caliwin, text='Point %d' %Control['j']))
Labelsf[Control['j']].pack(side='top')
#ROIs.insert(Control['j'], InterestRegion(Labelsf[Control['j']], Control['j']))
Control['CALIctrl'].insert(Control['j'], 0)
Control['CALIctrl'][int(Control['j'])] = 1
Control['j'] = Control['j'] + 1
def least_squares(x,y):
A = np.vstack([x, np.ones(len(x))]).T
a, b = np.linalg.lstsq(A, y)[0]
return a ,b
calibut = tk.Button(caliwin, text = 'Add', command = lambda i=i: addpoint(), bd=2, width=7, height=1)
calibut.pack(side='top')
addpoint()
caliwin.mainloop()
def lldt():
Interface['buttons'][1].invoke()
lldtwin = tk.Tk()
......@@ -402,12 +433,6 @@ def lldt():
lldtbut.pack(side='left')
lldtwin.mainloop()
##############################################################################
##############################################################################
# Safe Exit
def shutdown():
sys.exit
##############################################################################
##############################################################################
......@@ -415,7 +440,7 @@ def shutdown():
for i in range(4):
if i == 2:
Interface['frames'].insert(i, tk.Frame(root, width=40))
Interface['frames'].insert(i, tk.Frame(root))
Interface['frames'][i].pack(side='top',fill='both', expand=1)
else:
Interface['frames'].insert(i, tk.Frame(root))
......@@ -450,6 +475,7 @@ settings = tk.Menu(menubar, tearoff=0)
settings.add_command(label="Low level detect treshold", command = lambda i=i:lldt())
settings.add_command(label="Plot Refresh Rate", command = lambda i=i:refreshrate())
settings.add_command(label="Regions of Interest", command = lambda i=i: roiroi())
settings.add_command(label="Straight Calibration", command = lambda i=i:str_cali())
menubar.add_cascade(label="File", menu=filemenu)
menubar.add_cascade(label="Settings", menu=settings)
......@@ -479,10 +505,10 @@ Interface['labels'].insert(5,tk.Label(Interface['frames'][9], text='%s.%d' %(Con
for n in arange(3,6):
Interface['labels'][n].pack(fill='x')
Interface['frames'].insert(10, tk.Frame(Interface['frames'][2], width=20)) #Plot Esquerdo
Interface['frames'].insert(11, tk.Frame(Interface['frames'][2], width=20)) #Plot Direito
Interface['frames'][10].pack(side='left',fill='both', expand=1)
Interface['frames'][11].pack(side='right',fill='both', expand=1)
Interface['frames'].insert(10, tk.Frame(Interface['frames'][2]))
Interface['frames'][10].place(anchor='nw',relheight=0.99, relwidth=0.5)
Interface['frames'].insert(11, tk.Frame(Interface['frames'][2]))
Interface['frames'][11].place(anchor='nw',relheight=0.99, relwidth=0.5, relx = 0.5)
##############################################################################
##############################################################################
......@@ -498,14 +524,15 @@ def key_4(event):
if event.inaxes != a.axes: return
PlotLimControl['pressx'] = float(event.xdata)
PlotLimControl['pressy'] = float(event.ydata)
if event.button == 3:
if PlotLimControl['limupdt'] == True:
if event.button == 3:#dir
if PlotLimControl['limupdtx'] == True:
PlotLimControl['x1'] = int(Control['bmax'])
PlotLimControl['y1'] = max(Data)*1.2
PlotLimControl['limupdt'] = False
PlotLimControl['limupdtx'] = False
PlotLimControl['limupdty'] = False
PlotLimControl['limctrl'] = True
elif event.button == 2:
PlotLimControl['limupdt'] = True
elif event.button == 2:#mid
PlotLimControl['limupdtx'] = True
PlotLimControl['limctrl'] = False
PlotLimControl['limtrans'] = False
PlotLimControl['x0'] = 0
......@@ -513,43 +540,59 @@ def key_4(event):
PlotLimControl['y0'] = 0
PlotLimControl['y1'] = max(Data)*1.2
f.canvas.draw()
elif event.button == 1:
PlotLimControl['limupdt'] = False
elif event.button == 1:#esq
PlotLimControl['limupdtx'] = False
PlotLimControl['limtrans'] = True
def key_4_b(event):
if event.inaxes != a2.axes: return
PlotLimControl['pressx_b'] = float(event.xdata)
PlotLimControl['pressy_b'] = float(event.ydata)
if event.button == 3: #Dir
if PlotLimControl['limupdt_bx'] == True:
PlotLimControl['x1_b'] = int(Control['bmax'])
PlotLimControl['y1_b'] = max(Data)*1.2
PlotLimControl['limupdt_bx'] = False
PlotLimControl['limupdt_by'] = False
PlotLimControl['limctrl_b'] = True
elif event.button == 2: # Mid
PlotLimControl['limupdt_bx'] = True
PlotLimControl['limctrl_b'] = False
PlotLimControl['limtrans_b'] = False
PlotLimControl['x0_b'] = 0
PlotLimControl['x1_b'] = int(Interface['spinboxes'][0].get())
PlotLimControl['y0_b'] = 0
PlotLimControl['y1_b'] = max(Data)*1.2
f2.canvas.draw()
elif event.button == 1: #Esq
PlotLimControl['limupdt_bx'] = False
PlotLimControl['limtrans_b'] = True
def key_5(event):
if event.inaxes != a.axes: return
if PlotLimControl['limctrl'] == True:
PlotLimControl['dx'] = float(event.xdata) - PlotLimControl['pressx']
PlotLimControl['dy'] = float(event.ydata) - PlotLimControl['pressy']
plt.xlim(float(PlotLimControl['x0']+PlotLimControl['dx']), float(PlotLimControl['x1'])-PlotLimControl['dx'])
plt.ylim(float(PlotLimControl['y0']), float(PlotLimControl['y1'])-2*PlotLimControl['dy'])
a.set_xlim(float(PlotLimControl['x0']+PlotLimControl['dx']), float(PlotLimControl['x1'])-PlotLimControl['dx'])
a.set_ylim(float(PlotLimControl['y0']), float(PlotLimControl['y1'])-2*PlotLimControl['dy'])
f.canvas.draw()
# if PlotLimControl['limtrans'] == True:
# if PlotLimControl['pressx'] >= event.xdata:
# xx = event.xdata
# xx2 = PlotLimControl['pressx']
# else:
# xx2 = event.xdata
# xx = PlotLimControl['pressx']
# if PlotLimControl['pressy'] >= event.ydata:
# yy = event.ydata
# yy2 = PlotLimControl['pressy']
# else:
# yy2 = event.ydata
# yy = PlotLimControl['pressy']
# if (xx2-xx)/(PlotLimControl['x1']-PlotLimControl['x0']) >= (yy2-yy)/(PlotLimControl['y1']-PlotLimControl['y0']) and (xx2-xx) > 0.01*(PlotLimControl#['x1']-PlotLimControl['x0']):
#fill_betweenx(PlotLimControl['y1']*np.ones(xx, xx2), xx, xx2)
#elif (yy2-yy) > 0.01*(PlotLimControl['y1']-PlotLimControl['y0']):
#fill_between(PlotLimControl['x1']*np.ones(yy, yy2), yy, yy2)
#f.canvas.draw()
def key_5_b(event):
if event.inaxes != a2.axes: return
if PlotLimControl['limctrl_b'] == True:
PlotLimControl['dx_b'] = float(event.xdata) - PlotLimControl['pressx_b']
PlotLimControl['dy_b'] = float(event.ydata) - PlotLimControl['pressy_b']
a2.set_xlim(float(PlotLimControl['x0_b']+PlotLimControl['dx_b']), float(PlotLimControl['x1_b'])-PlotLimControl['dx_b'])
a2.set_ylim(float(PlotLimControl['y0_b']), float(PlotLimControl['y1_b'])-2*PlotLimControl['dy_b'])
f2.canvas.draw()
def key_6(event):
if event.button is not 2:
(PlotLimControl['x0'] , PlotLimControl['x1']) = plt.xlim()
(PlotLimControl['y0'] , PlotLimControl['y1']) = plt.ylim()
(PlotLimControl['x0'] , PlotLimControl['x1']) = a.get_xlim()
(PlotLimControl['y0'] , PlotLimControl['y1']) = a.get_ylim()
if event.button == 3:
PlotLimControl['limctrl'] = False
if event.button == 1:
f.canvas.get_tk_widget().delete("lines")
if PlotLimControl['limtrans'] == True:
......@@ -565,19 +608,78 @@ def key_6(event):
else:
yy2 = event.ydata
yy = PlotLimControl['pressy']
if (xx2-xx)/(PlotLimControl['x1']-PlotLimControl['x0']) >= (yy2-yy)/(PlotLimControl['y1']-PlotLimControl['y0']) and (xx2-xx) > 0.01*(PlotLimControl['x1']-PlotLimControl['x0']):
plt.xlim(xx,xx2)
elif (yy2-yy) > 0.01*(PlotLimControl['y1']-PlotLimControl['y0']):
plt.ylim(yy,yy2)
if (xx2-xx)/(PlotLimControl['x1']-PlotLimControl['x0']) >= (yy2-yy)/(PlotLimControl['y1']-PlotLimControl['y0']) and (xx2-xx) > 0.03*(PlotLimControl['x1']-PlotLimControl['x0']):
a.set_xlim(xx,xx2)
elif (yy2-yy) > 0.03*(PlotLimControl['y1']-PlotLimControl['y0']):
a.set_ylim(yy,yy2)
f.canvas.draw()
(PlotLimControl['x0'] , PlotLimControl['x1']) = plt.xlim()
(PlotLimControl['y0'] , PlotLimControl['y1']) = plt.ylim()
(PlotLimControl['x0'] , PlotLimControl['x1']) = a.get_xlim()
(PlotLimControl['y0'] , PlotLimControl['y1']) = a.get_ylim()
PlotLimControl['limtrans'] = False
if int(PlotLimControl['x1']-PlotLimControl['x0'])>8:
grid(a, int(PlotLimControl['x1']-PlotLimControl['x0']))
else:
grid(a, 8)
def key_6_b(event):
if event.button is not 2:
(PlotLimControl['x0_b'] , PlotLimControl['x1_b']) = a2.get_xlim()
(PlotLimControl['y0_b'] , PlotLimControl['y1_b']) = a2.get_ylim()
if event.button == 3:
PlotLimControl['limctrl_b'] = False
if event.button == 1:
f2.canvas.get_tk_widget().delete("lines")
if PlotLimControl['limtrans_b'] == True:
if PlotLimControl['pressx_b'] >= event.xdata:
xx = event.xdata
xx2 = PlotLimControl['pressx_b']
else:
xx2 = event.xdata
xx = PlotLimControl['pressx_b']
if PlotLimControl['pressy_b'] >= event.ydata:
yy = event.ydata
yy2 = PlotLimControl['pressy_b']
else:
yy2 = event.ydata
yy = PlotLimControl['pressy_b']
if (xx2-xx)/(PlotLimControl['x1_b']-PlotLimControl['x0_b']) >= (yy2-yy)/(PlotLimControl['y1_b']-PlotLimControl['y0_b']) and (xx2-xx) > 0.03*(PlotLimControl['x1_b']-PlotLimControl['x0_b']):
a2.set_xlim(xx,xx2)
elif (yy2-yy) > 0.03*(PlotLimControl['y1_b']-PlotLimControl['y0_b']):
a2.set_ylim(yy,yy2)
f2.canvas.draw()
(PlotLimControl['x0_b'] , PlotLimControl['x1_b']) = a2.get_xlim()
(PlotLimControl['y0_b'] , PlotLimControl['y1_b']) = a2.get_ylim()
PlotLimControl['limtrans_b'] = False
if int(PlotLimControl['x1_b']-PlotLimControl['x0_b'])>8:
grid(a2, int(PlotLimControl['x1_b']-PlotLimControl['x0_b']))
else:
grid(a2, 8)
def shifts_zoom (valor):
if FocusControl['graphic1']:
PlotLimControl['limupdtx']=False
xmin, xmax = a.get_xlim()
a.set_xlim(xmin+valor,xmax+valor)
f.canvas.draw()
if FocusControl['graphic2']:
PlotLimControl['limupdtx']=False
xmin, xmax = a.get_xlim()
a2.set_xlim(xmin+valor,xmax+valor)
f2.canvas.draw()
def mult_zoom(valor):
if FocusControl['graphic1']:
PlotLimControl['limupdty']=False
ymin, ymax = a.get_ylim()
a.set_ylim(ymin,ymax*valor)
f.canvas.draw()
if FocusControl['graphic2']:
PlotLimControl['limupdt_by']=False
ymin, ymax = a.get_ylim()
a2.set_ylim(ymin,ymax*valor)
f2.canvas.draw()
root.bind_all("<Alt-KeyPress-1>", key_1)
root.bind_all("<Alt-KeyPress-2>", key_1)
root.bind_all("<Alt-KeyPress-3>", key_2)
......@@ -585,6 +687,15 @@ root.bind_all("<Alt-KeyPress-6>", key_3)
root.bind_all("<Alt-KeyPress-4>", save)
root.bind_all("<Alt-KeyPress-5>", saveas)
root.bind_all("<Up>", lambda i=i:mult_zoom(1.25))
root.bind_all("<Down>",lambda i=i:mult_zoom(0.8))
root.bind_all("<Left>",lambda i=i: shifts_zoom(-1))
root.bind_all("<Right>",lambda i=i: shifts_zoom(1))
#root.bind_all("<Tab>" change_focus)
##############################################################################
##############################################################################
# Plotting embedded
......@@ -599,10 +710,13 @@ temp, = a.plot(xx, xx*0, 'red', lw=0.9)
temp2, = a2.plot(xx, xx*0, 'red', lw=0.9)
xlabel('Channel')
ylabel('Counts')
cidclick = f.canvas.mpl_connect('button_press_event', key_4)
cidmotion = f.canvas.mpl_connect('motion_notify_event', key_5)
cidrelease = f.canvas.mpl_connect('button_release_event', key_6)
f.canvas.mpl_connect('button_press_event', key_4)
f.canvas.mpl_connect('motion_notify_event', key_5)
f.canvas.mpl_connect('button_release_event', key_6)
f2.canvas.mpl_connect('button_press_event', key_4_b)
f2.canvas.mpl_connect('motion_notify_event', key_5_b)
f2.canvas.mpl_connect('button_release_event', key_6_b)
##############################################################################
##############################################################################
# Paralel mainloop and initiations
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment