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

Escala Log implementada, Botão Grid implementado.

Foram feitas pequenas mudancas na tela inicial do programa.
Add alguns comentários.
parent cd13de8a
......@@ -19,17 +19,18 @@ from pylab import *
#from clsbeep import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import Image, ImageTk
##############################################################################
##############################################################################
# GLOBAL VARIABLES AND DEFINITIONS
Control = dict(text_cursor='Cursor:',Refresh=800, bmin=0, bmax=512, bmaxold=512, j=0, filename='temp', count=0, paused=True, ROIctrl=list(),CALIctrl=list(), Logaritmo=False, graphic1=True, graphic2=True, G_cursor=None)
Control = dict(text_cursor='Cursor:',Refresh=800, bmin=0, bmax=512, bmaxold=512, j=0, filename='temp', count=0, paused=True, ROIctrl=list(),CALIctrl=list(), Logaritmo=False, graphic1=True, graphic2=True, G_cursor=None, Grid=True)
FocusControl = dict( full_screen= False, aux_click='gg')
Grafico=list()
M=list() #lista com módulos, instancias da classe (arquivo Modulo)
......@@ -41,14 +42,14 @@ Interface = dict(frames=list(), buttons=list(), labels=list(), spinboxes=list(),
###################################################################
# Ve quantas variaveis MC_ estão criadas no arquivo User_Config.py
# Define o modo de aquisição:1 ou 2 módulos (Implementar para n?)
# Define o modo de aquisição:1 ou 2 módulos
try:
MCA
MCA # existe MCA no arquivo User_Config.py?
except NameError:
tkMessageBox.showinfo("Erro", "MCA não encontrado, nenhum módulo selecionado!")
sys.exit
else:
M.insert(0,Modulo('0'))
M.insert(0,Modulo('0')) # cria uma instancia de "Modulo"
M[0].Nmr_serial= MCA
Grafico.insert(0,Graficos(M[0].Nmr_serial))
Grafico[0].f.suptitle('# A')
......@@ -56,27 +57,29 @@ else:
try:
MCB
MCB # existe MCB no arquivo User_Config.py?
except NameError:
None
else:
M.insert(1,Modulo('1'))
M.insert(1,Modulo('1')) # cria uma instancia de "Modulo"
M[1].Nmr_serial= MCB
Grafico.insert(1,Graficos(M[1].Nmr_serial))
Grafico[1].f.suptitle('# B')
Grafico[1].title=('B')
try:
MCC
try:
MCC # existe MCB no arquivo User_Config.py?
except NameError:
None
else:
M.insert(2,Modulo('2'))
M.insert(2,Modulo('2')) # cria uma instancia de "Modulo"
M[2].Nmr_serial=MCC
Grafico.insert(2,Graficos(M[2].Nmr_serial))
Grafico[2].f.suptitle('# C')
Grafico[2].title=('C')
sys.setrecursionlimit(5000)
xx = arange(0, 8192)
xxx= arange(0,512)
......@@ -96,7 +99,7 @@ def change_conf(parametro, valor): # modifica um parametro da execução n957 (
arq.write(line)
arq.close()
def leave():
def leave(): # sai do programa
global M, sys
if not Control['paused']:
pause()
......@@ -134,9 +137,9 @@ def grid(a, n):
a.xaxis.set_major_locator(MultipleLocator(n/8))
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(Control['Grid'],'major',linewidth=2)
a.yaxis.grid(Control['Grid'],'major')
a.xaxis.grid(Control['Grid'],'minor')
##############################################################################
##############################################################################
......@@ -319,23 +322,30 @@ def testeerro(Data): # mensagens de erros
else:
return True
##############################################################################
##############################################################################
# as 2 principais funçoes graphic e graphic2
def graphic2(): #trata as informações que foram salvas em graphic1
for G in Grafico:
G.temp.set_xdata(range(int(M[Grafico.index(G)].Controle['Nmr_canais'])))
G.temp.set_ydata(M[Grafico.index(G)].Data)
G.temp.set_xdata(range(int(M[Grafico.index(G)].Controle['Nmr_canais']))) #Atualiza o range do plot
G.temp.set_ydata(M[Grafico.index(G)].Data)
for G in Grafico:
if G.limupdtx or G.limupdty:
if Control['Logaritmo']:
G.a.set_yscale('log')
G.a.grid(False)
else:
G.a.relim()
if G.limupdtx or G.limupdty: #se a flag do updat x/y estiver true...
# if Control['Logaritmo']:
# G.a.grid(False)
# G.a.set_yscale('log')
# G.a.grid(False)
# else:
G.a.relim() #vai dar update automático no tamanho do gráfico
G.a.autoscale_view(scaley=G.limupdty,scalex=G.limupdtx)
for G in Grafico:
if G.limupdtx == True and Control['Logaritmo'] == False:
if G.limupdtx == True:
grid(G.a, int(M[Grafico.index(G)].Controle['Nmr_canais']))
Control['text_cursor']='Cursor '
......@@ -343,7 +353,7 @@ def graphic2(): #trata as informações que foram salvas em graphic1
for G in Grafico:
Control['text_cursor']= Control['text_cursor'] + G.title + ':(' +str(G.Cursor['x']) + ','+str(M[Grafico.index(G)].Data[G.Cursor['x']])+ ') '
G.f.canvas.draw()
G.f.canvas.draw() #DRAW!
Interface['labels'][1+3*len(Grafico)].configure(text= Control['text_cursor'])
def graphic(): # Le os dados provenientes dos módulos
......@@ -353,6 +363,7 @@ def graphic(): # Le os dados provenientes dos módulos
aux=0;
for Mod in M:
Interface['labels'][aux].configure(text='ADC : %s' %str(Mod.Livetime['ADC_Conversion']))
Interface['labels'][aux+1].configure(text='Total Time: %ss' %str(Mod.Livetime['Time']/1000))
Interface['labels'][aux+2].configure(text='Dead Time: %.5f %%' %(Mod.Livetime['DeadTime']))
......@@ -410,13 +421,31 @@ def reset(): # Zera o vetor de aquisicao
graphic2()
def change_variable():
def Change_Log_Scale():
if Control['Logaritmo']:
Control['Logaritmo']= False
for G in Grafico:
G.f.gca().set_yscale('linear')
Control['Refresh']=800
tkMessageBox.showinfo("Attention", "Refresh time was set to 0.8 seconds")
else:
Control['Logaritmo'] = True
Control['Logaritmo'] = True
for G in Grafico:
G.f.gca().set_yscale('log')
Control['Refresh']=2000
tkMessageBox.showinfo("Attention", "Refresh time was set to 2 seconds")
def Change_Grid():
if Control['Grid']:
Control['Grid']= False
else:
Control['Grid'] = True
for G in Grafico:
grid(G.a, int(M[Grafico.index(G)].Controle['Nmr_canais']))
def pause(): # Para/Continua a aquisicao de dados
......@@ -435,16 +464,16 @@ def pause(): # Para/Continua a aquisicao de dados
def save(): # Salva os dados no arquivo selecionado (grafico= g1(salva g1) g2(salva g2) g12(salva os dois)
global Data
Interface['labels'][3*len(Grafico) +2].configure(text='%s.%d' %(Control['filename'], Control['count'])) #atualiza label da direita e embaixo
Control['count'] = Control['count'] + 1
Interface['labels'][8].configure(text='%s.%d' %(Control['filename'], Control['count']))
for Mod in M:
for Mod in M:
fname = open(Control['filename'] +'._'+str(Control['count'])+'.MC'+ Grafico[M.index(Mod)].title+'.Date' , mode='w')
for n in range(int(Interface['spinboxes'][0].get())):
fname.write(str(n+1)+' '+str(Mod.Data[n])+'\n')
fname.close()
Interface['labels'][5]['text'] = '%s.%d' %(Control['filename'], Control['count'])
Interface['labels'][3*len(Grafico) +2]['text'] = '%s.%d' %(Control['filename'], Control['count'])
def load_buff():
......@@ -470,9 +499,9 @@ def saveas(): # Salva os dados no arquivo selecionado
fname.write(str(n+1)+' '+str(Mod.Data[n])+'\n')
fname.close()
Interface['labels'][5]['text'] = '%s.%d' %(Control['filename'], Control['count'])
Interface['labels'][3*len(Grafico) +2]['text'] = '%s.%d' %(Control['filename'], Control['count'])
Control['count'] = Control['count'] + 1
Interface['labels'][8].configure(text='%s.%d' %(Control['filename'], Control['count']))
Interface['labels'][3*len(Grafico) +2].configure(text='%s.%d' %(Control['filename'], Control['count']))
def load(): # Manda os dados carregados para leitura
......@@ -564,6 +593,36 @@ def lldt(): #Definir o lower level detection trueshot
lldtbut.pack(side='left')
lldtwin.mainloop()
def Open_About():
AboutWin= tk.Toplevel()
#http://stackoverflow.com/questions/20251161/tkinter-tclerror-image-pyimage3-doesnt-exist - LINK SALVADOR AboutWin.minsize(600,600)
AboutWin.configure(bg='white')
AboutWin.title('About')
tk.Label(AboutWin, text="Authors: Julio Cesar Ferreira Tambara ",bg='white' ).pack(side='top',fill='x')
tk.Label(AboutWin, text=" Mateus Vicente Wrasse Wiebusch Müller ",bg='white').pack(side='top',fill='x')
tk.Label(AboutWin, text="Rudder: Rafael Pereti Pezzi ",bg='white').pack(side='top',fill='x')
imagens = tk.Frame(AboutWin,takefocus=0,bg='white')
Imagem_load =os.path.dirname(os.path.realpath(__file__))+ "/Imagens"
photo = ImageTk.PhotoImage(file=Imagem_load + '/banner_cta.png')
photo2= ImageTk.PhotoImage(file=Imagem_load +'/implantador130.png' )
tk.Label(imagens, image=photo,bg='white').pack(side='left')
tk.Label(imagens, image=photo2,bg='white').pack(side='left')
imagens.pack(side='top',fill='both')
tk.Label(AboutWin, text="Repository: http://cta.if.ufrgs.br/projects/estacao-de-espectrometria/repository ",bg='white').pack(side='top',fill='x')
tk.Label(AboutWin, text="Laboratory: http://implantador.if.ufrgs.br ",bg='white').pack(side='top',fill='x')
tk.Label(AboutWin, text="License: GNU General Public License V3 ",bg='white').pack(side='top',fill='x')
tk.Label(AboutWin, text="Contact:julio.tambara@ufrgs.br",bg='white').pack(side='top',fill='x')
AboutWin.mainloop()
##############################################################################
##############################################################################
......@@ -571,20 +630,20 @@ def lldt(): #Definir o lower level detection trueshot
for i in range(4):
if i == 2:
Interface['frames'].insert(i, tk.Frame(root,takefocus=0))
Interface['frames'].insert(i, tk.Frame(root,takefocus=0,bg='grey'))
Interface['frames'][i].pack(side='top',fill='both', expand=1)
else:
Interface['frames'].insert(i, tk.Frame(root))
Interface['frames'][i].pack(side='top',fill='x', expand=0)
Frame_bin_scale=tk.Frame(Interface['frames'][0],takefocus=0)
Frame_bin_scale=tk.Frame(Interface['frames'][0],takefocus=0,bg='grey')
Frame_bin_scale.pack(side='right')
Interface['labelframes'].insert(0,tk.LabelFrame(Frame_bin_scale, relief='raised',takefocus=0, text='Bins', bd=1, pady=0, bg='grey',height=2.0))
Interface['labelframes'].insert(1,tk.LabelFrame(Interface['frames'][0], relief='raised',takefocus=0, text='Time', bd=1, height=5, pady=2, bg='grey'))
Interface['labelframes'].insert(2,tk.LabelFrame(Frame_bin_scale, relief='raised',takefocus=0, bd=2, pady=2, bg='grey',height=2.0))
Interface['labelframes'][1].pack(side='right')
Interface['labelframes'][1].pack(side='right',fill='both')
Interface['labelframes'][0].pack(side='top')
Interface['labelframes'][2].pack(side='top',fill='x')
......@@ -599,7 +658,10 @@ Interface['spinboxes'].insert(0, tk.Spinbox(Interface['labelframes'][0], command
var.set("512")
Interface['spinboxes'][0].pack()
tk.Checkbutton(Interface['labelframes'][2], text="Log Scale",takefocus=0,command=lambda i=i:change_variable(), variable = Control['Logaritmo'],bg='grey').pack(expand=1)
tk.Checkbutton(Interface['labelframes'][2], text="Log Scale",takefocus=0,command=lambda i=i:Change_Log_Scale(), variable = Control['Logaritmo'],bg='grey').pack(expand=1,fill='x')
Checkbutton_grid = tk.Checkbutton(Interface['labelframes'][2], text="Grid",takefocus=0,command=lambda i=i:Change_Grid(), bg='grey')
Checkbutton_grid.select()
Checkbutton_grid.pack(expand=1,fill='x')
......@@ -619,8 +681,8 @@ settings.add_command(label="Regions of Interest", command = lambda i=i: roiroi()
settings.add_command(label="Straight Calibration", command = lambda i=i:str_cali())
buffermenu = tk.Menu(menubar, tearoff=0)
buffermenu.add_command(label="M[0]", command = lambda i=i:load_buff())
buffermenu.add_command(label="M[1]", command = lambda i=i:loadbuffer2())
buffermenu.add_command(label="Load", command = lambda i=i:load_buff())
rig_but_menu= tk.Menu(root, tearoff=0)
rig_but_menu.add_command(label="Open", command = lambda i=i:load())
......@@ -629,9 +691,13 @@ rig_but_menu.add_command(label="Hide graphic", command = lambda i=i:hide_graphic
rig_but_menu.add_command(label="Select graphic", command = lambda i=i:Grafico[1].dataPlot.get_tk_widget().focus_set())
helpmenu=tk.Menu(root,tearoff=0)
helpmenu.add_command(label="About", command= lambda i=i: Open_About())
menubar.add_cascade(label="File", menu=filemenu)
menubar.add_cascade(label="Settings", menu=settings)
menubar.add_cascade(label="Buffer", menu=buffermenu)
menubar.add_cascade(label="Help", menu= helpmenu)
root.config(menu=menubar)
##############################################################################
......@@ -656,9 +722,10 @@ for G in Grafico:
Interface['frames'].insert(10, None)#arrumar depois
Interface['frames'].insert(11, None)
for x in range(len(M)):
Interface['frames'].insert(12 + x, tk.Frame(Interface['labelframes'][1]))
Interface['frames'][12+x].pack(side='top',fill='both', expand=1)
Interface['frames'].insert(12 + x, tk.Frame(Interface['labelframes'][1],bg='grey'))
aux=0
......@@ -674,6 +741,9 @@ for Mod in M:
aux=aux+3
for x in range(len(M)):
Interface['frames'][12+x].pack(side='top',fill='both', expand='y')
Interface['labels'].insert(aux,tk.Label(Interface['frames'][7], text='Waiting to Start', anchor='w'))
Interface['labels'][aux].pack(fill='x')
......@@ -895,10 +965,14 @@ for G in Grafico:
##############################################################################
#Start
#Interface['labels'][3*len(M)].configure(text="Connecting to #%d" %Mod.Nmr_serial)
print os.path.dirname(os.path.realpath(__file__))
#print os.path.dirname(os.path.realpath(__file__))
temp = tkFileDialog.asksaveasfilename(title='File Name',initialdir= os.path.dirname(os.path.realpath(__file__))+'/Save')
Control['filename'] = temp
Control['count']=0
Interface['labels'][3*len(Grafico) +2]['text'] = '%s.%d' %(Control['filename'], Control['count'])
Interface['labels'][3*len(Grafico) +2].configure(text='%s.%d' %(Control['filename'], Control['count']))
#sys.getfilesystemencoding()
......
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