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

Hotkeys, Zoom com mouse, Bug save as + cancell fixed

ainda falta beep, metodo grafico para ROIs e limpar o buffer do modulo
parent 708eda69
......@@ -246,6 +246,7 @@ int main(int argc, char **argv)
goto exit_point;
}
tot_data_read+= data_read;
for( i= 0; i< data_read; i++) {
// Check for user commands
......@@ -258,9 +259,24 @@ int main(int argc, char **argv)
for(w=0; w<8192; w++)
histograma[w] = 0;
break;
case 'p':
case 'p':
case 'P':
/*if(!paused)
{
if( ( N957_error_code= N957_StopAcquire( user_setting.m_N957_handle))!= N957Success)
{
ret_val= -24;
goto exit_point;
}
}
else
if( ( N957_error_code= N957_StartAcquire( user_setting.m_N957_handle, user_setting.m_mode))!= N957Success)
{
ret_val= -8;
goto exit_point;
}*/
paused= !paused;
break;
case 'a':
fator = 1;
......
......@@ -2,17 +2,18 @@
# -*- coding: iso-8859-15 -*-
import os
import sys
import pexpect
import numpy as np
import Tkinter as tk
import tkMessageBox
import tkFileDialog
import matplotlib.pyplot as plt
from pylab import *
from threading import *
import time
from pylab import *
from clsbeep import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import tkFileDialog
##############################################################################
##############################################################################
......@@ -27,13 +28,14 @@ sys.setrecursionlimit(5000)
##############################################################################
# Histrogram
Control = dict(t = 1500, bmin = 0, bmax = 8192, j = 0, filename = 'temp', count = 0, paused = False, ROIctrl = list())
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.)
Data=list()
ROIs=list()
for a in range(8192):
Data.insert(a, 0)
#############################################################################
##############################################################################
##############################################################################
# Main window
......@@ -41,6 +43,18 @@ root = tk.Tk()
root.minsize(825,640)
root.title('Modulo Multicanal')
##############################################################################
##############################################################################
# BEEP (nao funciona)
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'
##############################################################################
##############################################################################
# Atualiza grade do plot de acordo com regiao escolhida
......@@ -56,22 +70,29 @@ def grid(a, n):
##############################################################################
# Regiao de interesse
def realtimerefresh(k):
Control['ROIctrl'][k] = 1
def updateroi(fator):
for n in range(len(ROIs)):
ROIs[n].xmin = ROIs[n].xmin*fator/Control['bmaxold']
ROIs[n].xmax = ROIs[n].xmax*fator/Control['bmaxold']
ROIs[n].xmine.delete(0, 'end')
ROIs[n].xmaxe.delete(0, 'end')
ROIs[n].xmine.insert(0, ROIs[n].xmin)
ROIs[n].xmaxe.insert(0, ROIs[n].xmax)
Control['bmaxold'] = fator
class InterestRegion:
def __init__(self, labfrm, j):
self.Area = 0
self.xmin = 0
self.xmax = 0
self.xmax = Control['bmax']
self.xmine = tk.Entry(labfrm)
self.xmine.pack(side='left')
self.xmine.insert(0, self.xmin)
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: realtimerefresh(j))
self.button.pack(side='left')
self.xmaxe.insert(0, self.xmax)
self.label2 = tk.Label(labfrm, text='Total counts: %d' %self.Area)
self.label2.pack(side='bottom')
......@@ -99,6 +120,7 @@ def roiroi():
Labelsf[Control['j']].pack(side='top')
ROIs.insert(Control['j'], InterestRegion(Labelsf[Control['j']], Control['j']))
Control['ROIctrl'].insert(Control['j'], 0)
Control['ROIctrl'][int(Control['j'])] = 1
Control['j'] = Control['j'] + 1
roibut = tk.Button(roiwin, text = 'Add', command = lambda i=i: addROI(), bd=2, width=7, height=1)
......@@ -110,48 +132,57 @@ def roiroi():
##############################################################################
Interface = dict(frames=list(), buttons=list(), labels=list(), spinboxes=list(), entries=list(), labelframes=list())
Livetime = dict(ADC_Conversion='0' , Time='0' , LiveTime='0' )
Livetime = dict(ADC_Conversion=0 , Time=0. , LiveTime=0. )
def set_fator(canais): # Define o fator para conversao do numero de canais
global Interface, child
if int(canais) == 8192:
child.send('a')
Control['bmax'] = 8192
updateroi(8192)
elif int(canais) == 4096:
child.send('b')
Control['bmax'] = 4096
updateroi(4096)
elif int(canais) == 2048:
child.send('c')
updateroi(2048)
Control['bmax'] = 2048
elif int(canais) == 1024:
child.send('d')
Control['bmax'] = 1024
updateroi(1024)
elif int(canais) == 512:
child.send('e')
Control['bmax'] = 512
updateroi(512)
elif int(canais) == 256:
child.send('f')
Control['bmax'] = 256
updateroi(256)
elif int(canais) == 128:
child.send('g')
Control['bmax'] = 128
updateroi(128)
elif int(canais) == 64:
child.send('h')
Control['bmax'] = 64
updateroi(64)
def settime():
Livetime['ADC_Conversion'] = child.readline().strip("\r\n")
Livetime['Time'] = child.readline().strip("\r\n")
Livetime['LiveTime'] = child.readline().strip("\r\n")
Interface['labels'][0].configure(text='ADC Conversions: %s' %Livetime['ADC_Conversion'])
Interface['labels'][1].configure(text='Total Time: %s' %Livetime['Time'])
Interface['labels'][2].configure(text='Live Time: %s' %Livetime['LiveTime'])
Livetime['ADC_Conversion'] = int(child.readline().strip("\r\n"))
Livetime['Time'] = float(child.readline().strip("\r\n"))
Livetime['LiveTime'] = float(child.readline().strip("\r\n"))
Interface['labels'][0].configure(text='ADC Conversions: %s' %str(Livetime['ADC_Conversion']))
Interface['labels'][1].configure(text='Total Time: %ss' %str(Livetime['Time']/1000))
Interface['labels'][2].configure(text='Live Time: %ss' %str(Livetime['LiveTime']/1000))
def graphic2(Data): #Plot
temp.set_xdata(range(int(Interface['spinboxes'][0].get())))
temp.set_ydata(Data)
plt.xlim(Control['bmin'], Control['bmax'])
plt.ylim(0, max(Data[int(Control['bmin']):int(Control['bmax'])])*1.2)
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()))
f.canvas.draw()
......@@ -183,7 +214,10 @@ def realtimeplot(): # Funcao recursiva para plot em tempo real
# Control functions
def reset(): # Zera o vetor de aquisicao
global child
global child, Data
for a in range(int(Interface['spinboxes'][0].get())):
Data[a] = 0
graphic2(Data)
child.send('r')
def pause(): # Para/Continua a aquisicao de dados
......@@ -209,25 +243,26 @@ def restart(): # Reinicia o programa de aquisicao
def save(): # Salva os dados no arquivo selecionado
global child, Data
Control['count'] = Control['count'] + 1
fname = open(Control['filename']+'.'+str(Control['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' %(Control['filename'], Control['count'])
Control['count'] = Control['count'] + 1
def saveas(): # Salva os dados no arquivo selecionado
global child, Data
Control['filename'] = tkFileDialog.asksaveasfilename()
Control['count']=0
fname = open(Control['filename']+'.'+str(Control['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' %(Control['filename'], Control['count'])
Control['count'] = Control['count'] + 1
#child.send('z')
temp = tkFileDialog.asksaveasfilename(title='Save as')
if temp != str():
Control['filename'] = temp
Control['count']=0
fname = open(Control['filename']+'.'+str(Control['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' %(Control['filename'], Control['count'])
Control['count'] = Control['count'] + 1
def load(): # Manda os dados carregados para leitura
global child
newfile = tkFileDialog.askopenfilename()
......@@ -241,10 +276,12 @@ def load(): # Manda os dados carregados para leitura
def refreshrate(): # Define a frequencia de atualizacao do grafico
rrwin = tk.Tk()
rrwin.title('Set Refresh Rate(ms)')
rrwin.title('Set Refresh Rate')
rrent = tk.Entry(rrwin)
rrent.pack(side='left')
rrlab = tk.Label(rrwin, text='ms')
rrlab.pack(side='left')
def setrr():
if rrent.get().isdigit():
if int(rrent.get()) > 499: # Valores muito baixos causam stack overflow
......@@ -292,10 +329,8 @@ for i in range(3):
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]))
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'][0].pack()
Interface['spinboxes'][0].delete(0,len(Interface['spinboxes'][0].get()))
Interface['spinboxes'][0].insert(0,512)
##############################################################################
# Menu
......@@ -320,8 +355,8 @@ Interface['buttons'].insert(3, tk.Button(Interface['frames'][0], text = 'Restar
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))
for i in range(6):
Interface['buttons'][i].pack(side = 'left')
for i in range(5):
Interface['buttons'][i+1].pack(side = 'left')
for i in range(3):
Interface['frames'].insert(i+7, tk.Frame(Interface['frames'][3]))
......@@ -334,6 +369,61 @@ 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')
##############################################################################
##############################################################################
# Key Bindings
def key_1(event):
Interface['buttons'][1].invoke()
#beep()
def key_2(event):
Interface['buttons'][2].invoke()
def key_3(event):
roiroi()
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:
PlotLimControl['x1'] = int(Control['bmax'])
PlotLimControl['y1'] = max(Data)*1.2
PlotLimControl['limupdt'] = False
PlotLimControl['limctrl'] = True
elif event.button == 2:
PlotLimControl['limupdt'] = True
PlotLimControl['limctrl'] = False
PlotLimControl['limtrans'] = False
elif event.button == 1:
PlotLimControl['limupdt'] = False
PlotLimControl['limtrans'] = 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(int(PlotLimControl['x0']+PlotLimControl['dx']), int(PlotLimControl['x1'])-PlotLimControl['dx'])
plt.ylim(int(PlotLimControl['y0']+PlotLimControl['dy']), int(PlotLimControl['y1'])-PlotLimControl['dy'])
if PlotLimControl['limtrans'] == True:
PlotLimControl['dx'] = float(event.xdata) - PlotLimControl['pressx']
PlotLimControl['dy'] = float(event.ydata) - PlotLimControl['pressy']
plt.xlim(int(PlotLimControl['x0']-PlotLimControl['dx']), int(PlotLimControl['x1'])-PlotLimControl['dx'])
plt.ylim(int(PlotLimControl['y0']-PlotLimControl['dy']), int(PlotLimControl['y1'])-PlotLimControl['dy'])
def key_6(event):
(PlotLimControl['x0'] , PlotLimControl['x1']) = plt.xlim()
(PlotLimControl['y0'] , PlotLimControl['y1']) = plt.ylim()
if event.button == 3:
PlotLimControl['limctrl'] = False
if event.button == 1:
PlotLimControl['limtrans'] = False
root.bind_all("<Alt-KeyPress-1>", key_1)
root.bind_all("<Alt-KeyPress-2>", key_1)
root.bind_all("<Alt-KeyPress-3>", key_2)
root.bind_all("<Alt-KeyPress-6>", key_3)
##############################################################################
##############################################################################
# Plotting embedded
......@@ -347,12 +437,16 @@ xx = arange(0, 8192)
temp, = a.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)
##############################################################################
##############################################################################
# Paralel processing
# Paralel mainloop and initiations
set_fator(Interface['spinboxes'][0].get())
for n in range(3):
Interface['spinboxes'][0].invoke('buttonup')
Interface['buttons'][0].invoke()
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