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

Barra de status adicionada, ROI nao recursivo implementado

Auto incremento no save implementado
Novo load NAO implementado
parent 0d687cc9
......@@ -8,7 +8,6 @@ import Tkinter as tk
import tkMessageBox
import matplotlib.pyplot as plt
from pylab import *
from ROI import *
import time
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
......@@ -27,9 +26,10 @@ paused = False
##############################################################################
# Histrogram
t = 2000 #Refresh rate
t = 1500 #Refresh rate
bmin = 0
bmax = 8192
j = 0
Data=list()
for a in range(8192):
Data.insert(a, 0)
......@@ -54,11 +54,64 @@ def grid(a, n):
a.xaxis.grid(True,'minor')
a.xaxis.grid(True,'major',linewidth=2)
##############################################################################
##############################################################################
# Regiao de interesse
class InterestRegion:
def __init__(self, labfrm):
self.Area = 0
self.xmin = 0
self.xmax = 0
self.xmine = tk.Entry(labfrm)
self.xmine.pack(side='left')
self.label = tk.Label(labfrm, text='to')
self.label.pack(side='left')
self.xmaxe = tk.Entry(labfrm)
self.xmaxe.pack(side='left')
self.button = tk.Button(labfrm, text='Start', command = lambda i=i: self.ROIme())
self.button.pack(side='left')
self.label2 = tk.Label(labfrm, text='Total counts: %d' %self.Area)
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
for n in range(self.xmin, (self.xmax)):
self.Area = self.Area + Data[n]
self.label2['text']='Total counts: %d' %self.Area
#root.after(2000, self.ROIme())
else:
tkMessageBox.showinfo("Error", "Invalid values")
def roiroi():
global bmin, bmax, j
j=0
Labelsf=list()
ROIs =list()
roiwin = tk.Tk()
roiwin.title('ROI')
def addROI():
global j
Labelsf.insert(j, tk.LabelFrame(roiwin, text='ROI %d' %j))
Labelsf[j].pack(side='top')
ROIs.insert(j, InterestRegion(Labelsf[j]))
j = j + 1
roibut = tk.Button(roiwin, text = 'Add', command = lambda i=i: addROI(), bd=2, width=7, height=1)
roibut.pack(side='top')
roiwin.mainloop()
##############################################################################
##############################################################################
Interface = dict(frames=list(), buttons=list(), labels=list(), spinboxes=list(), entries=list(), labelframes=list())
Livetime = dict(ADC_Conversion='0' , Time='0' , LiveTime='0' )
filename = 'temp'
count = 0
def set_fator(): # Define o fator para conversao do numero de canais
global Interface, child, bmax
......@@ -95,17 +148,16 @@ def settime():
Interface['labels'][1].configure(text='Total Time: %s' %Livetime['Time'])
Interface['labels'][2].configure(text='Live Time: %s' %Livetime['LiveTime'])
def graphic2(Data):
def graphic2(Data): #Plot
global Interface, bmin, bmax
temp.set_xdata(range(int(Interface['spinboxes'][0].get())))
temp.set_ydata(Data)
#plt.fill_between(range(8192),Data,0,color='0.8')
plt.xlim(bmin, bmax)
plt.ylim(0, max(Data[bmin:bmax])*1.2)
grid(a, int(Interface['spinboxes'][0].get()))
f.canvas.draw()
def graphic(): # Le os dados e plota o grafico
def graphic(): # Le os dados
global child, Data
Data = eval(child.readline().strip("\r\n"))
graphic2(Data)
......@@ -115,7 +167,7 @@ def dump(): # Sinal para programa coletor enviar os dados
global child
child.send('i')
def realtimeplot(): # Funcao recursiva pra plot em tempo real
def realtimeplot(): # Funcao recursiva para plot em tempo real
global t, paused
if not paused:
dump()
......@@ -137,6 +189,13 @@ def pause(): # Para/Continua a aquisicao de dados
global child, paused
paused = not paused
child.send('p')
if paused:
Interface['buttons'][1]['text'] = 'Resume'
Interface['labels'][3]['text'] = 'Paused'
else:
Interface['buttons'][1]['text'] = 'Pause'
Interface['labels'][3]['text'] = 'Acquiring'
realtimeplot()
def restart(): # Reinicia o programa de aquisicao
global child
......@@ -147,36 +206,50 @@ def restart(): # Reinicia o programa de aquisicao
child.send('s')
def save(): # Salva os dados no arquivo selecionado
global child, Data
fname = tkFileDialog.asksaveasfile(mode='w')
global child, Data, count, filename
fname = open(filename+'.'+str(count), mode = 'w')
for n in range(int(Interface['spinboxes'][0].get())):
fname.write(str(n+1)+' '+str(Data[n])+'\n')
fname.close()
Interface['labels'][5]['text'] = '%s.%d' %(filename, count)
count = count + 1
def saveas(): # Salva os dados no arquivo selecionado
global child, Data, count, filename
filename = tkFileDialog.asksaveasfilename()
count=0
fname = open(filename+'.'+str(count), mode = 'w')
for n in range(int(Interface['spinboxes'][0].get())):
fname.write(str(n+1)+' '+str(Data[n])+'\n')
fname.close()
Interface['labels'][5]['text'] = '%s.%d' %(filename, count)
count = count + 1
#child.send('z')
def load(): # Manda os dados carregados para leitura
global child
child.send('y')
def plotting():
global bmin, bmax
if Interface['entries'][0].get().isdigit() and int(Interface['entries'][0].get()) >= 0 and Interface['entries'][1].get().isdigit() and int(Interface['entries'][1].get()) <= int(Interface['spinboxes'][0].get()) and int(Interface['entries'][1].get()) > int(Interface['entries'][0].get()):
bmin = int(Interface['entries'][0].get())
bmax = int(Interface['entries'][1].get())
Interface['labelframes'][0].configure(text = 'Region of interest - %i to %i' %(bmin, bmax))
else:
tkMessageBox.showinfo("Error", "Invalid values: Must be from 0 to 8192")
def refreshrate(): # Define a frequencia de atualizacao do grafico
global t
if Interface['entries'][2].get().isdigit():
if int(Interface['entries'][2].get()) > 499: # Valores muito baixos causam stack overflow
t = int(Interface['entries'][2].get())
Interface['labelframes'][1].configure(text = 'Refresh Rate - %ims' %t)
rrwin = tk.Tk()
rrwin.title('Set Refresh Rate(ms)')
rrent = tk.Entry(rrwin)
rrent.pack(side='left')
def setrr():
global t
if rrent.get().isdigit():
if int(rrent.get()) > 499: # Valores muito baixos causam stack overflow
t = int(rrent.get())
Interface['labels'][4].configure(text = ' Refresh Rate %dms' %t)
else:
tkMessageBox.showinfo("Error", "This refresh rate is likely to reach maximum recursion depht!")
else:
tkMessageBox.showinfo("Error", "This refresh rate is likely to reach maximum recursion depht!")
else:
tkMessageBox.showinfo("Error", "Invalid value")
tkMessageBox.showinfo("Error", "Invalid value")
rrbut = tk.Button(rrwin, text = 'Set', command = lambda i=i: setrr(), bd=2, width=7, height=1)
rrbut.pack(side='left')
rrwin.mainloop()
##############################################################################
##############################################################################
......@@ -189,60 +262,76 @@ def shutdown():
##############################################################################
# Interface elements
for i in range(2):
for i in range(4):
Interface['frames'].insert(i, tk.Frame(root))
Interface['frames'][i].pack()
Interface['frames'][i].pack(side='top')
Interface['labelframes'].insert(0,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Region of interest - 0 to 8192', bd=2))
Interface['labelframes'].insert(1,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Refresh Rate - 2000ms', bd=2))
Interface['labelframes'].insert(2,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Bins', bd=2))
Interface['labelframes'].insert(3,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Last Data', bd=2))
Interface['frames'][2].pack(side='top',fill='both', expand=1)
Interface['labels'].insert(0,tk.Label(Interface['labelframes'][3], text='ADC Conversions: %s' %Livetime['ADC_Conversion']))
Interface['labels'].insert(1,tk.Label(Interface['labelframes'][3], text='Total Time: %s' %Livetime['Time']))
Interface['labels'].insert(2,tk.Label(Interface['labelframes'][3], text='Live Time: %s' %Livetime['LiveTime']))
Interface['labelframes'].insert(0,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Bins', bd=2))
Interface['labelframes'].insert(1,tk.LabelFrame(Interface['frames'][1], relief='raised', text='Time', bd=2))
for i in range(3):
for i in range(2):
Interface['labelframes'][i].pack(side='left')
Interface['frames'].insert((i+2), tk.Frame(Interface['labelframes'][0]))
Interface['frames'][(i+2)].pack(side='left')
Interface['labels'][i].pack()
Interface['labelframes'][3].pack()
Interface['labels'].insert(3,tk.Label(Interface['frames'][3], text='to'))
Interface['labels'][3].pack()
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['spinboxes'].insert(0, tk.Spinbox(Interface['labelframes'][2], command = set_fator, values=[64,128,256,512,1024,2048,4096,8192]))
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 = set_fator, values=[64,128,256,512,1024,2048,4096,8192]))
Interface['spinboxes'][0].pack()
Interface['spinboxes'][0].delete(0,len(Interface['spinboxes'][0].get()))
Interface['spinboxes'][0].insert(0,8192)
Interface['spinboxes'][0].insert(0,512)
##############################################################################
# Menu
menubar = tk.Menu(root, bg='grey', relief='flat', bd=0)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command = lambda i=i:load())
filemenu.add_command(label="Exit", command = sys.exit)
Interface['entries'].insert(0, tk.Entry(Interface['frames'][2], width=7))
Interface['entries'].insert(1, tk.Entry(Interface['frames'][4], width=7))
Interface['entries'].insert(2, tk.Entry(Interface['labelframes'][1], width=16))
settings = tk.Menu(menubar, tearoff=0)
settings.add_command(label="Refresh Rate", command = lambda i=i:refreshrate())
settings.add_command(label="Regions of Interest", command = lambda i=i: roiroi())
for i in range(3):
Interface['entries'][i].pack()
menubar.add_cascade(label="File", menu=filemenu)
menubar.add_cascade(label="Settings", menu=settings)
root.config(menu=menubar)
##############################################################################
Interface['buttons'].insert(0, tk.Button(Interface['frames'][0], text = 'Plot', 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 = 'Reset', 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 = 'Load', command = lambda i=i: load(), bd=2, width=11, height=1))
Interface['buttons'].insert(6, tk.Button(Interface['labelframes'][0], text = 'Change', command = lambda i=i: plotting(), bd=2, width=7, height=1))
Interface['buttons'].insert(7, tk.Button(Interface['labelframes'][1], text = 'Change', command = lambda i=i: refreshrate(), bd=2, width=13, 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))
for i in range(8):
for i in range(6):
Interface['buttons'][i].pack(side = 'left')
for i in range(3):
Interface['frames'].insert(i+7, tk.Frame(Interface['frames'][3]))
Interface['frames'][i+7].pack(side = 'left', fill='x', expand=1)
Interface['labels'].insert(3,tk.Label(Interface['frames'][7], text='Acquiring', anchor='w'))
Interface['labels'].insert(4,tk.Label(Interface['frames'][8], text=' Refresh Rate %dms' %t))
Interface['labels'].insert(5,tk.Label(Interface['frames'][9], text=' %s.%d' %(filename, count), anchor='e'))
for n in arange(3,6):
Interface['labels'][n].pack(fill='x')
##############################################################################
##############################################################################
# Plotting embedded
f = plt.figure()
a = f.add_subplot(111)
dataPlot = FigureCanvasTkAgg(f, master=root)
dataPlot = FigureCanvasTkAgg(f, master=Interface['frames'][2])
dataPlot.get_tk_widget().pack(side='top', fill='both', expand=1)
xx = arange(0, 8192)
......@@ -250,20 +339,11 @@ temp, = a.plot(xx, xx*0, 'red', lw=0.9)
xlabel('Channel')
ylabel('Counts')
##############################################################################
##############################################################################
# Menu
menubar = tk.Menu(root, bg='grey', relief='flat', bd=0)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Exit", command = sys.exit)
menubar.add_cascade(label="File", menu=filemenu)
root.config(menu=menubar)
##############################################################################
##############################################################################
# Paralel processing
set_fator()
root.mainloop()
##############################################################################
......
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