Commit 91374ffb authored by Julio Tambara's avatar Julio Tambara
Browse files

Bugs corrigidos

ROI, quando muda o fator de escala
     quando fechava o frame da ROI

Zoom, grid não fica mais com linha densas
      não trava mais em casos particulares

Save, modificado o diretório inicial

Entre outros pequenos problemas...
parent d343134d
import Tkinter as tk
import pexpect
import time
import numpy as np
from array import *
......@@ -29,8 +30,9 @@ class Modulo:
def set_fator(self, canais): # Define o fator para conversao do numero de canais
self.Nmr_canais=canais
self.Controle['Nmr_canais']=canais
if int(canais) == 8192: # 8192 pontos
self.child.send('a')
elif int(canais) == 4096: # 4096 pontos
self.child.send('b')
......@@ -72,12 +74,17 @@ class Modulo:
def reset(self):
self.child.send('r')
for k in range(self.Controle['Nmr_canais']):
for k in range(int(self.Controle['Nmr_canais'])):
self.Data[k] = 0
def pause(self):
self.child.send('p')
def exit(self):
self.child.send('q')
time.sleep(0.1)
self.child.close(force=True)
......
......@@ -72,7 +72,7 @@ int main(int argc, char **argv)
unsigned int nmr_ADC_pause=0;
unsigned int tempo_pause_vivo=0;
FILE* log;
short int fator = 1;
short int fator = 16;
N957_UINT32 data32;
int ret_val= 0;
N957_ConfigROM ROM;
......@@ -415,7 +415,7 @@ int main(int argc, char **argv)
exit_point:
getch();
// Stop acquisition
if(N957_StopAcquire( user_setting.m_N957_handle))
......
......@@ -29,7 +29,7 @@ from matplotlib.figure import Figure
##############################################################################
# GLOBAL VARIABLES AND DEFINITIONS
Control = dict(text_cursor='Cursor:',Refresh=600, bmin=0, bmax=8192, bmaxold=64, 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)
FocusControl = dict( full_screen= False, aux_click='gg')
Grafico=list()
M=list() #lista com módulos, instancias da classe (arquivo Modulo)
......@@ -75,17 +75,11 @@ else:
M[2].Nmr_serial=MCC
Grafico.insert(2,Graficos(M[2].Nmr_serial))
Grafico[2].f.suptitle('# C')
Grafico[2].title=('C')
Grafico[2].title=('C')
sys.setrecursionlimit(5000)
xx = arange(0, 8192)
xxx= arange(0,512)
##############################################################################
......@@ -102,6 +96,13 @@ def change_conf(parametro, valor): # modifica um parametro da execução n957 (
arq.write(line)
arq.close()
def leave():
global M, sys
if not Control['paused']:
pause()
for mod in M:
mod.exit()
sys.exit()
##############################################################################
##############################################################################
......@@ -110,20 +111,20 @@ def change_conf(parametro, valor): # modifica um parametro da execução n957 (
root = tk.Tk()
root.minsize(825,640)
root.title('Modulo Multicanal')
root.protocol('WM_DELETE_WINDOW', sys.exit)
root.protocol('WM_DELETE_WINDOW', leave)
##############################################################################
##############################################################################
# BEEP (nao funciona)
#def beep():
# if sys.platform=='win32' or sys.platform=='win64':
# print chr(7),
def beep():
if sys.platform=='win32' or sys.platform=='win64':
print chr(7),
elif sys.platform=='linux2':
open('/dev/dsp','w').write(''.join(chr(128 * (1 + int(math.sin(math.pi * 440 * i / 100.0)))) for i in xrange(1000)))
elif sys.platform=='amiga':
print '\a\v'
# elif sys.platform=='linux2':
# open('/dev/dsp','w').write(''.join(chr(128 * (1 + int(math.sin(math.pi * 440 * i / 100.0)))) for i in xrange(1000)))
# elif sys.platform=='amiga':
# print '\a\v'
##############################################################################
##############################################################################
......@@ -141,6 +142,14 @@ def grid(a, n):
##############################################################################
# Regiao de interesse
def Close_ROI():
global roiwin
for n in range(len(ROIs)):
del ROIs[0]
Control['ROIctrl'][:]=[]
Control['j']=0
roiwin.destroy()
def updateroi(fator):
for n in range(len(ROIs)):
ROIs[n].xmin = ROIs[n].xmin*fator/Control['bmaxold']
......@@ -207,7 +216,7 @@ class InterestRegion:
self.label2['text']="Invalid values"
def roiroi():
global ROIs
global ROIs , roiwin
Control['j'] = 0
Labelsf = list()
ROIs = list()
......@@ -226,53 +235,80 @@ def roiroi():
roibut = tk.Button(roiwin, text = 'Add', command = lambda i=i: addROI(), bd=2, width=7, height=1)
roibut.pack(side='top')
addROI()
roiwin.protocol('WM_DELETE_WINDOW', Close_ROI)
roiwin.mainloop()
##############################################################################
##############################################################################
def set_fator(canais): # Define o fator para conversao do numero de canais
global Control , M
for Mod in M:
Mod.set_fator(canais)
for G in Grafico:
G.Cursor['x']=(G.Cursor['x']*int(canais))/int(Control['bmax'])
G.Cursor['line'].remove()
G.Cursor['line']=G.a.axvline(x= G.Cursor['x'],color='red')
G.limupdty = True
G.limupdtx = True
G.limctrl = False
G.limtrans = False
G.x0 = 0
G.x1 = int(Interface['spinboxes'][0].get())
G.y0 = 0
G.y1 = max(M[Grafico.index(G)].Data)*1.2
for Mod in M:
Mod.dump()
graphic()
Control['text_cursor']='Cursor '
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()
Interface['labels'][1+3*len(Grafico)].configure(text= Control['text_cursor'])
Control['bmax']= int(canais)
updateroi(int(canais))
def testeerro(Data): # mensagens de erros
if not Data == 'OK':
if Data == 'error_1':
print 'erro_1'
print ("erro_1")
tkMessageBox.showinfo("Erro", "user_settings_open erro! ")
return False
elif Data == 'erro_2': # Módulo não esta ligado, não esta rodando como root
print 'erro_2'
print ('erro_2')
tkMessageBox.showinfo("Erro", "user_settings_parse_input_param error!")
return False
elif Data == 'erro_3':
print 'erro_3'
print ('erro_3')
tkMessageBox.showinfo("Erro", "N957_GetFWRelease error!")
return False
elif Data == 'erro_4':
print 'erro_4'
print ('erro_4')
tkMessageBox.showinfo("Erro", "Problemas ao iniciar")
return False
elif Data == 'erro_5':
print 'erro_5'
print ('erro_5')
tkMessageBox.showinfo("Erro", "N957_GetScaler")
return False
elif Data == 'erro_6':
print 'erro_6'
print ('erro_6')
tkMessageBox.showinfo("Erro", "N957_StartAcquire")
return False
elif Data == 'erro_7':
print 'erro_7'
print ('erro_7')
tkMessageBox.showinfo("Erro", "N957_SetSwConvFlag")
return False
elif Data == 'erro_8':
tkMessageBox.showinfo("Erro", "Erro ao criar alocar memória ")
elif Data == 'erro_8':
tkMessageBox.showinfo("Erro", "Erro ao alocar memória ")
return False
elif Data == 'erro_9':
tkMessageBox.showinfo("Erro", "N957_ReadData")
......@@ -281,7 +317,7 @@ def testeerro(Data): # mensagens de erros
tkMessageBox.showinfo("Erro_default", Data)
return False
else:
return True
return True
def graphic2(): #trata as informações que foram salvas em graphic1
......@@ -300,11 +336,12 @@ def graphic2(): #trata as informações que foram salvas em graphic1
for G in Grafico:
if G.limupdtx == True and Control['Logaritmo'] == False:
grid(G.a, int(M[Grafico.index(G)].Nmr_canais))
grid(G.a, int(M[Grafico.index(G)].Controle['Nmr_canais']))
Control['text_cursor']='Cursor '
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()
Interface['labels'][1+3*len(Grafico)].configure(text= Control['text_cursor'])
......@@ -344,7 +381,7 @@ def realtimeplot(): # Funcao recursiva para plot em tempo real
def hide_graphic(): #a= hide 1#, b=hide 2#, x= unhide
print Control['Logaritmo']
print (Control['Logaritmo'])
# if FocusControl['full_screen']==True:
# Interface['frames'][11].place_forget()
# Interface['frames'][10].place_forget()
......@@ -450,6 +487,7 @@ def load(): # Manda os dados carregados para leitura
Mod.load()
time.sleep(0.1)
def refreshrate(): # Define a frequencia de atualizacao do grafico
rrwin = tk.Tk()
rrwin.title('Set Refresh Rate')
......@@ -527,7 +565,6 @@ def lldt(): #Definir o lower level detection trueshot
lldtwin.mainloop()
##############################################################################
##############################################################################
# Interface elements
......@@ -556,8 +593,10 @@ for i in range(3):
Interface['frames'].insert((i+4), tk.Frame(Interface['labelframes'][0]))
Interface['frames'][(i+4)].pack(side='left')
var = tk.StringVar(Interface['labelframes'][0])
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],takefocus=0, width = 9, state = 'readonly', bg='grey'))
Interface['spinboxes'].insert(0, tk.Spinbox(Interface['labelframes'][0], command = lambda i=i: set_fator(Interface['spinboxes'][0].get()), values=[128,256,512,1024,2048,4096,8192],textvariable =var,takefocus=0, width = 9, state = 'readonly', bg='grey'))
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)
......@@ -571,7 +610,7 @@ filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command = lambda i=i:load())
filemenu.add_command(label ="Save", command = lambda i=i: save())
filemenu.add_command(label ="Save As", command = lambda i=i: saveas())
filemenu.add_command(label="Exit", command = sys.exit)
filemenu.add_command(label="Exit", command = lambda i=i:leave())
settings = tk.Menu(menubar, tearoff=0)
settings.add_command(label="Low level detect treshold", command = lambda i=i:lldt())
......@@ -601,8 +640,8 @@ Interface['buttons'].insert(0, tk.Button(Interface['frames'][0], takefocus=0, t
Interface['buttons'].insert(1, tk.Button(Interface['frames'][0],takefocus=0, text = 'Start', command = lambda i=i: pause(), bd=2, height=2, bg='grey'))
Interface['buttons'].insert(2, tk.Button(Interface['frames'][0],takefocus=0, text = 'Clear', command = lambda i=i: reset(), bd=2, height=2, bg='grey'))
#Interface['buttons'].insert(3, tk.Button(Interface['frames'][0],takefocus=0, text = 'Clear 2', command = lambda i=i: reset(), bd=2, height=2, bg='grey'))
Interface['buttons'].insert(3, tk.Button(Interface['frames'][0],takefocus=0, text = 'Save', command = lambda i=i: save('g12'), bd=2, height=2, bg='grey'))
Interface['buttons'].insert(4, tk.Button(Interface['frames'][0],takefocus=0, text = 'Save As', command = lambda i=i: saveas('g12'), bd=2, height=2, bg='grey'))
Interface['buttons'].insert(3, tk.Button(Interface['frames'][0],takefocus=0, text = 'Save', command = lambda i=i: save(), bd=2, height=2, bg='grey'))
Interface['buttons'].insert(4, tk.Button(Interface['frames'][0],takefocus=0, text = 'Save As', command = lambda i=i: saveas(), bd=2, height=2, bg='grey'))
for i in range(4):
Interface['buttons'][i+1].pack(side = 'left', fill='both', expand=1)
......@@ -640,7 +679,7 @@ Interface['labels'][aux].pack(fill='x')
Interface['labels'].insert(aux+1,tk.Label(Interface['frames'][8], text= Control['text_cursor'] , anchor='w'))
Interface['labels'][aux+1].pack(side='left')
Interface['labels'].insert(aux+2,tk.Label(Interface['frames'][9], text='%s.%d' %(Control['filename'], Control['count']), anchor='e'))
Interface['labels'].insert(aux+2,tk.Label(Interface['frames'][9], text=os.path.dirname(os.path.realpath(__file__))+'/Save/%s.%d' %(Control['filename'], Control['count']), anchor='e'))
Interface['labels'][aux+2].pack(fill='x')
Interface['labels'].insert(aux+3,tk.Label(Interface['frames'][8], text= '(0,0)' , anchor='w'))
Interface['labels'][aux+3].pack(side='right')
......@@ -658,7 +697,7 @@ def key_2():
reset()
def key_3():
roiroi()
def key_4(event):
def key_4(event): #'button_press_event'
G=G_cursor
if event.inaxes != G.a.axes:
G.dataPlot.get_tk_widget().focus_set()
......@@ -686,7 +725,7 @@ def key_4(event):
G.limupdtx = False
G.limtrans = True
def key_5(event):
def key_5(event):# 'motion_notify_event'
G=G_cursor
if event.inaxes != G.a.axes: return
Interface['labels'][3+3*len(Grafico)].configure(text=' (%.1f' %float(event.xdata)+ ',%.1f)'%float(event.ydata))
......@@ -699,7 +738,7 @@ def key_5(event):
def key_6(event):
def key_6(event): #'button_release_event'
G=G_cursor
if event.inaxes != G.a.axes:
if event.button == 3:
......@@ -712,7 +751,18 @@ def key_6(event):
G.limctrl = False
if event.button == 1:
G.f.canvas.get_tk_widget().delete("lines")
#if event.dblclick:
# G_cursor.Cursor['x']=int(event.x)
# G_cursor.Cursor['line'].remove()
# G_cursor.Cursor['line']=G_cursor.a.axvline(x= G_cursor.Cursor['x'],color='red')
# Control['text_cursor']='Cursor '
# 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()
# Interface['labels'][1+3*len(Grafico)].configure(text= Control['text_cursor'])
#G.f.canvas.get_tk_widget().delete("lines")
if G.limtrans == True:
if G.pressx >= event.xdata:
xx = event.xdata
......@@ -732,14 +782,29 @@ def key_6(event):
G.a.set_xlim(xx,xx2)
elif (yy2-yy) > 0.03*(G.y1-G.y0):
G.a.set_ylim(yy,yy2)
G.f.canvas.draw()
#G.f.canvas.draw()
(G.x0 , G.x1) = G.a.get_xlim()
(G.y0 , G.y1) = G.a.get_ylim()
G.limtrans = False
if int(G.x1-G.x0)>8:
grid(G.a, int(G.x1-G.x0))
G.f.canvas.draw()
else:
grid(G.a, 8)
G.f.canvas.draw()
#G_cursor.Cursor['x']=int(event.x)
#G_cursor.Cursor['line'].remove()
#G_cursor.Cursor['line']=G_cursor.a.axvline(x= G_cursor.Cursor['x'],color='red')
#Control['text_cursor']='Cursor '
#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()
#Interface['labels'][1+3*len(Grafico)].configure(text= Control['text_cursor'])
def get_x(event):
......@@ -782,11 +847,17 @@ def Shift_Cursor(side,all_grafic):
Interface['labels'][1+3*len(Grafico)].configure(text= Control['text_cursor'])
def teste():
global Grafico
print 'hi'
for G in Grafico:
G.a.yaxis.tick_left()
G.f.canvas.draw()
root.bind_all("<Up>", lambda i=i:add_cursor())
root.bind_all("<T>", lambda i=i:teste())
root.bind_all("<Shift-Up>",lambda i=i:mult_zoom(1.25,1))
root.bind_all("<Down>",lambda i=i:mult_zoom(0.8,0))
root.bind_all("<Shift-Down>",lambda i=i: mult_zoom(0.8,1))
......@@ -807,7 +878,7 @@ root.bind_all("<Shift-Right>",lambda i=i: Shift_Cursor('Right',1))
for G in Grafico:
G.dataPlot= FigureCanvasTkAgg(G.f, master=G.Frame)
G.dataPlot.get_tk_widget().pack(side='top', fill='both', expand=1)
G.temp, = G.a.plot(xx, xx*0,'o', color='yellow', lw=0.9)
G.temp, = G.a.plot(xxx, xxx*0,'o', color='yellow', lw=0.9)
G.a.set_xlabel('Channel')
G.a.set_ylabel('Counts')
......@@ -824,18 +895,23 @@ for G in Grafico:
##############################################################################
#Start
#Interface['labels'][3*len(M)].configure(text="Connecting to #%d" %Mod.Nmr_serial)
temp = tkFileDialog.asksaveasfilename(title='File Name')
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
#sys.getfilesystemencoding()
for Mod in M:
#Interface['labels'][3*len(M)]['text']= "Connecting to #%d", %Mod.Nmr_serial
while not testeerro(Mod.start()):
if not tkMessageBox.askretrycancel("Módulo não Encontrado", "Verifique se os todos os módulos estão ligados! "):
sys.exit
#while not testeerro(Mod.start()):
#if not tkMessageBox.askretrycancel("Módulo não Encontrado", "Verifique se os todos os módulos estão ligados! "):
#sys.exit
#else:
#sys.exit
if not testeerro(Mod.start()):
leave()
for Mod in M:
Mod.reset()
......@@ -844,9 +920,11 @@ for Mod in M:
##############################################################################
# Paralel mainloop and initiations
for n in range(3):
time.sleep(0.6)
Interface['spinboxes'][0].invoke('buttonup')
#for n in range(2):
# time.sleep(0.5)
# Interface['spinboxes'][0].invoke('buttonup')
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