Commit 13f6bbcd authored by Matheus Müller's avatar Matheus Müller
Browse files

Ajustes na interface e ROI

Menos situcoes encadeiam mensagem de erro e mais sao contornadas (ROI)
Interface ajustada para monitor widescreen.
parent 99ea628c
......@@ -28,12 +28,14 @@ sys.setrecursionlimit(5000)
##############################################################################
# Histrogram
f = plt.figure()
a = f.add_subplot(111)
Control = dict(t=1200, bmin=0, bmax=8192, bmaxold=512, j=0, filename='temp', count=0, paused=False, ROIctrl=list())
PlotLimControl = dict(limupdt=True, limctrl=False, x0=0, y0=0, x1=512, y1=0, pressx=0., pressy=0., limtrans=False, dx=0., dy=0.)
PlotLimControl = dict(limupdt=True, limctrl=False, x0=0, y0=0, x1=512, y1=0, pressx=0., pressy=0., limtrans=False, dx=0., dy=0., area=f.canvas.get_tk_widget().create_rectangle(0,0,0,0))
Data=list()
ROIs=list()
for a in range(8192):
Data.insert(a, 0)
for j in range(8192):
Data.insert(j, 0)
##############################################################################
##############################################################################
......@@ -61,10 +63,11 @@ def beep():
def grid(a, n):
a.xaxis.set_major_locator(MultipleLocator(n/8))
a.xaxis.set_minor_locator(MultipleLocator(n/64))
if n > 64:
a.xaxis.set_minor_locator(MultipleLocator(n/64))
a.xaxis.grid(True,'major',linewidth=2)
a.grid(True)
a.xaxis.grid(True,'minor')
a.xaxis.grid(True,'major',linewidth=2)
##############################################################################
##############################################################################
......@@ -97,10 +100,15 @@ class InterestRegion:
self.label2.pack(side='bottom')
def ROIme(self):
if self.xmine.get().isdigit() and int(self.xmine.get()) >= 0 and self.xmaxe.get().isdigit() and int(self.xmaxe.get()) <= int(Interface['spinboxes'][0].get()) and int(self.xmaxe.get()) > int(self.xmine.get()):
self.xmin = int(self.xmine.get())
self.xmax = int(self.xmaxe.get())
self.Area = 0
if self.xmine.get().isdigit() and self.xmaxe.get().isdigit() and int(self.xmine.get()) >= 0 and int(self.xmaxe.get()) >= 0:
if int(self.xmaxe.get()) >= int(self.xmine.get()) and int(self.xmaxe.get()) <= int(Interface['spinboxes'][0].get()):
self.xmin = int(self.xmine.get())
self.xmax = int(self.xmaxe.get())
self.Area = 0
elif int(self.xmaxe.get()) < int(self.xmine.get()) and int(self.xmine.get()) <= int(Interface['spinboxes'][0].get()):
self.xmin = int(self.xmaxe.get())
self.xmax = int(self.xmine.get())
self.Area = 0
for n in range(self.xmin, (self.xmax)):
self.Area = self.Area + Data[n]
self.label2['text']='Total counts: %d' %self.Area
......@@ -183,7 +191,8 @@ def graphic2(Data): #Plot
if PlotLimControl['limupdt']:
plt.xlim(Control['bmin'], Control['bmax'])
plt.ylim(0, max(Data[int(Control['bmin']):int(Control['bmax'])])*1.2)
grid(a, int(Interface['spinboxes'][0].get()))
if PlotLimControl['limupdt'] == True:
grid(a, int(Interface['spinboxes'][0].get()))
f.canvas.draw()
def graphic(): # Le os dados
......@@ -232,14 +241,16 @@ def pause(): # Para/Continua a aquisicao de dados
Interface['labels'][3]['text'] = 'Acquiring'
realtimeplot()
def restart(): # Reinicia o programa de aquisicao
def restart(): # Reinicia o programa de aquisicao (não funciona)
global child
Control['paused'] = True
child.send('j')
time.sleep(0.5)
time.sleep(1)
child = pexpect.spawn('./N957Run')
time.sleep(3.3)
child.send('s')
Interface['buttons'][0].invoke()
Control['paused'] = False
def save(): # Salva os dados no arquivo selecionado
global child, Data
......@@ -284,11 +295,11 @@ def refreshrate(): # Define a frequencia de atualizacao do grafico
def setrr():
if rrent.get().isdigit():
if int(rrent.get()) > 499: # Valores muito baixos causam stack overflow
if int(rrent.get()) > 99: # Valores muito baixos causam stack overflow
Control['t'] = int(rrent.get())
Interface['labels'][4].configure(text = ' Refresh Rate %dms' %Control['t'])
else:
tkMessageBox.showinfo("Error", "This refresh rate is likely to reach maximum recursion depht!")
tkMessageBox.showinfo("Warning", "This refresh rate is likely to reach maximum recursion depht!")
else:
tkMessageBox.showinfo("Error", "Invalid value")
......@@ -314,29 +325,30 @@ for i in range(4):
else:
Interface['frames'][i].pack(side='top',fill='x', expand=0)
Interface['labelframes'].insert(0,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Bins', bd=2, pady=3))
Interface['labelframes'].insert(1,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Time', bd=2, pady=3))
Interface['labelframes'].insert(0,tk.LabelFrame(Interface['frames'][0], relief='raised', text='Bins', bd=2, pady=2, bg='grey'))
Interface['labelframes'].insert(1,tk.LabelFrame(Interface['frames'][0], relief='raised', text='Time', bd=1, height=5, pady=2, bg='grey'))
for i in range(2):
Interface['labelframes'][i].pack(side='left')
Interface['labelframes'][i].pack(side='right')
Interface['labels'].insert(0,tk.Label(Interface['labelframes'][1], text='ADC Conversions: %s' %Livetime['ADC_Conversion']))
Interface['labels'].insert(1,tk.Label(Interface['labelframes'][1], text='Total Time: %s' %Livetime['Time']))
Interface['labels'].insert(2,tk.Label(Interface['labelframes'][1], text='Live Time: %s' %Livetime['LiveTime']))
Interface['labels'].insert(0,tk.Label(Interface['labelframes'][1], text='ADC Conversions: %s' %Livetime['ADC_Conversion'], width=25, height=1, bg='grey'))
Interface['labels'].insert(1,tk.Label(Interface['labelframes'][1], text='Total Time: %s' %Livetime['Time'], width=22, height=1, bg='grey'))
Interface['labels'].insert(2,tk.Label(Interface['labelframes'][1], text='Live Time: %s' %Livetime['LiveTime'], width=22, height=1, bg='grey'))
for i in range(3):
Interface['frames'].insert((i+4), tk.Frame(Interface['labelframes'][0]))
Interface['frames'][(i+4)].pack(side='left')
Interface['labels'][i].pack(side='left')
Interface['spinboxes'].insert(0, tk.Spinbox(Interface['labelframes'][0], command = lambda i=i: set_fator(Interface['spinboxes'][0].get()), values=[64,128,256,512,1024,2048,4096,8192], state = 'readonly'))
Interface['spinboxes'].insert(0, tk.Spinbox(Interface['labelframes'][0], command = lambda i=i: set_fator(Interface['spinboxes'][0].get()), values=[64,128,256,512,1024,2048,4096,8192], state = 'readonly', bg='grey'))
Interface['spinboxes'][0].pack()
##############################################################################
# Menu
menubar = tk.Menu(root, bg='grey', relief='flat', bd=0)
menubar = tk.Menu(root, relief='raised', bd=2)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command = lambda i=i:load())
#filemenu.add_command(label="Restart Program", command = lambda i=i:restart())
filemenu.add_command(label="Exit", command = sys.exit)
settings = tk.Menu(menubar, tearoff=0)
......@@ -348,15 +360,14 @@ menubar.add_cascade(label="Settings", menu=settings)
root.config(menu=menubar)
##############################################################################
Interface['buttons'].insert(0, tk.Button(Interface['frames'][0], text = 'Start', command = lambda i=i: realtimeplot(), bd=2, width=11, height=1))
Interface['buttons'].insert(1, tk.Button(Interface['frames'][0], text = 'Pause', command = lambda i=i: pause(), bd=2, width=11, height=1))
Interface['buttons'].insert(2, tk.Button(Interface['frames'][0], text = 'Clear', command = lambda i=i: reset(), bd=2, width=11, height=1))
Interface['buttons'].insert(3, tk.Button(Interface['frames'][0], text = 'Restart', command = lambda i=i: restart(), bd=2, width=11, height=1))
Interface['buttons'].insert(4, tk.Button(Interface['frames'][0], text = 'Save', command = lambda i=i: save(), bd=2, width=11, height=1))
Interface['buttons'].insert(5, tk.Button(Interface['frames'][0], text = 'Save As', command = lambda i=i: saveas(), bd=2, width=11, height=1))
Interface['buttons'].insert(0, tk.Button(Interface['frames'][0], text = 'Start', command = lambda i=i: realtimeplot(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(1, tk.Button(Interface['frames'][0], text = 'Pause', command = lambda i=i: pause(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(2, tk.Button(Interface['frames'][0], text = 'Clear', command = lambda i=i: reset(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(3, tk.Button(Interface['frames'][0], text = 'Save', command = lambda i=i: save(), bd=2, width=11, height=2, bg='grey'))
Interface['buttons'].insert(4, tk.Button(Interface['frames'][0], text = 'Save As', command = lambda i=i: saveas(), bd=2, width=11, height=2, bg='grey'))
for i in range(5):
Interface['buttons'][i+1].pack(side = 'left')
for i in range(4):
Interface['buttons'][i+1].pack(side = 'left', fill='both', expand=1)
for i in range(3):
Interface['frames'].insert(i+7, tk.Frame(Interface['frames'][3]))
......@@ -375,7 +386,6 @@ for n in arange(3,6):
def key_1(event):
Interface['buttons'][1].invoke()
root.bell()
def key_2(event):
Interface['buttons'][2].invoke()
def key_3(event):
......@@ -409,8 +419,26 @@ def key_5(event):
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']+PlotLimControl['dy']), float(PlotLimControl['y1'])-PlotLimControl['dy'])
plt.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_6(event):
if event.button is not 2:
......@@ -419,6 +447,7 @@ def key_6(event):
if event.button == 3:
PlotLimControl['limctrl'] = False
if event.button == 1:
f.canvas.get_tk_widget().delete("lines")
if PlotLimControl['limtrans'] == True:
if PlotLimControl['pressx'] >= event.xdata:
xx = event.xdata
......@@ -437,11 +466,13 @@ def key_6(event):
elif (yy2-yy) > 0.01*(PlotLimControl['y1']-PlotLimControl['y0']):
plt.ylim(yy,yy2)
f.canvas.draw()
grid(a, int(xx2-xx))
(PlotLimControl['x0'] , PlotLimControl['x1']) = plt.xlim()
(PlotLimControl['y0'] , PlotLimControl['y1']) = plt.ylim()
PlotLimControl['limtrans'] = False
if int(PlotLimControl['x1']-PlotLimControl['x0'])>8:
grid(a, int(PlotLimControl['x1']-PlotLimControl['x0']))
else:
grid(a, 8)
root.bind_all("<Alt-KeyPress-1>", key_1)
root.bind_all("<Alt-KeyPress-2>", key_1)
......@@ -452,8 +483,6 @@ root.bind_all("<Alt-KeyPress-6>", key_3)
##############################################################################
# Plotting embedded
f = plt.figure()
a = f.add_subplot(111)
dataPlot = FigureCanvasTkAgg(f, master=Interface['frames'][2])
dataPlot.get_tk_widget().pack(side='top', fill='both', expand=1)
......
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