# -*- coding: iso-8859-15 -*- import Tkinter as tk from PTE import * from pylab import * from numpy import zeros import os import tkFileDialog import shutil ############################################################################## # Control variables and lists Edict = dict() Ebuttons = list() Labentrys = list() i=0 Econtrol = 0 ############################################################################## # Element callback def elem_callback(x, edict , ebutton): global Labentrys PTable(edict[x] , ebutton[x], Labentrys) ############################################################################## # Element selection def elem_select(i, button): global Econtrol, Edict, Labentrys button[Econtrol]['relief']='raised' Econtrol = i button[i]['relief']='sunken' Labentrys[0].configure(text = '%s' %Edict[i]['name']) Labentrys[1].configure(text = 'Mass - %f' %Edict[i]['mass']) Labentrys[2].configure(text = 'Z - %f' %Edict[i]['Z']) Labentrys[3].configure(text = 'Symbol - %s' %Edict[i]['symbol']) Labentrys[4].configure(text = 'Line Shape α - %f' %Edict[i]['LineShape']) Labentrys[5].configure(text = 'Max Depht - %f' %Edict[i]['profundidademax']) for i in arange(6,12): Labentrys[i].delete (0, len(Labentrys[i].get())) Labentrys[6].insert(0, Edict[int(Econtrol)]['name']) Labentrys[7].insert(0, Edict[int(Econtrol)]['mass']) Labentrys[8].insert(0, int(Edict[int(Econtrol)]['Z'])) Labentrys[9].insert(0, Edict[int(Econtrol)]['symbol']) Labentrys[10].insert(0, Edict[int(Econtrol)]['LineShape']) Labentrys[11].insert(0, Edict[int(Econtrol)]['profundidademax']) ############################################################################## # Init def ewin_build(window, OFlabentries): ############################################################################## # Element addition def create(): global i, Edict, Ebuttons Edict[i] = dict(name = "New", symbol = "Hf", mass = 178.00, Z = 72, dist = zeros(int(10./float(OFlabentries[17].get()) )), LineShape = 200., profundidademax=10.) Ebuttons.insert(i, tk.Button(Eframe, text=i, width=1, height=1, command = lambda i=i : elem_select(i,Ebuttons)) ) Ebuttons[i].grid(column = ((len(Ebuttons)-1)%14), row = int(math.floor((len(Ebuttons)-1)/14))) i = i+1 ############################################################################## # Element deletion def remove(): global i, Edict, Ebuttons, Econtrol if i > 1: i = i-1 del Edict[i] Ebuttons[i].destroy() del Ebuttons[i] if Econtrol == i: Econtrol = Econtrol -1 Ebuttons[Econtrol]['relief']='sunken' elem_select(0, Ebuttons) ############################################################################## # Element Frames Labelprop = tk.LabelFrame(window, text = 'Properties', relief='raised', bd=2) Labelprop.pack(side = 'top') Label1 = tk.LabelFrame(window, text = 'Elements', relief='raised', bd=2) Label1.pack(side = 'top') Eframe = tk.Canvas(Label1) Eframe.pack(fill='both',expand=0) ############################################################################## # Init create() ############################################################################## # Properties global Econtrol, Edict, Labentrys def update(i): Edict[i]['name'] = str(Labentrys[6].get()) Labentrys[0].configure(text = '%s' %Edict[i]['name']) Edict[i]['mass'] = float(Labentrys[7].get()) Labentrys[1].configure(text = 'Mass - %f' %Edict[i]['mass']) Edict[i]['Z'] = float(Labentrys[8].get()) Labentrys[2].configure(text = 'Z - %f' %Edict[i]['Z']) Edict[i]['symbol'] = str(Labentrys[9].get()) Labentrys[3].configure(text = 'Symbol - %s' %Edict[i]['symbol']) Edict[i]['LineShape'] = float(Labentrys[10].get()) Labentrys[4].configure(text = 'Line Shape α - %f' %Edict[i]['LineShape']) Edict[i]['profundidademax'] = float(Labentrys[11].get()) Labentrys[5].configure(text = 'Max Depht - %f' %Edict[i]['profundidademax']) Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof") LpFrame1 = tk.Frame(Labelprop) LpFrame1.pack(side='left') LpFrame2 = tk.Frame(Labelprop) LpFrame2.pack(side='top') LpFrame3 = tk.Frame(Labelprop) LpFrame3.pack(side='right') EPframel = tk.Frame(LpFrame1) EPframel.pack(side='left') EPframee = tk.Frame(LpFrame1) EPframee.pack(side='right') EPframel2 = tk.Frame(LpFrame2) EPframel2.pack(side='left') EPframee2 = tk.Frame(LpFrame2) EPframee2.pack(side='right') # Label // Entries numbers: # 0 // 6 = Name # 1 // 7 = Mass # 2 // 8 = Z (Atomic number) # 3 // 9 = Symbol # 4 // 10 = Line shape # 5 // 11 = Max Depht Labentrys.insert(0, tk.Label(EPframel, width=26, pady=2, text='%s' %Edict[int(Econtrol)]['name']) ) Labentrys.insert(1, tk.Label(EPframel, width=26, pady=2, text='Mass - %f' %Edict[int(Econtrol)]['mass']) ) Labentrys.insert(2, tk.Label(EPframel, width=26, pady=2, text='Z - %f' %Edict[int(Econtrol)]['Z']) ) Labentrys.insert(3, tk.Label(EPframel, width=26, pady=2, text= 'Symbol - %s' %Edict[int(Econtrol)]['symbol']) ) Labentrys.insert(4, tk.Label(EPframel, width=26, pady=2, text='Line Shape α - %f' %Edict[int(Econtrol)]['LineShape']) ) Labentrys.insert(5, tk.Label(EPframel, width=26, pady=2, text='Max Depht - %f' %Edict[int(Econtrol)]['profundidademax']) ) for i in range(6): Labentrys[i].pack() for i in arange(6, 12): Labentrys.insert(i, tk.Entry(EPframee, width=18) ) Labentrys[i].pack() # Declaration of interpolation method variable methodvar = tk.StringVar() methodvar.set('reta') ############################################################################## # Load/Save sample def LOADSAMPLE(): global i, Econtrol arquivo = tkFileDialog.askopenfile() for n in arange(9,18): OFlabentries[n].delete(0,len(OFlabentries[n].get())) OFlabentries[n].insert(0,float(arquivo.readline())) for n in arange(21,24): OFlabentries[n].delete(0,len(OFlabentries[n].get())) OFlabentries[n].insert(0,float(arquivo.readline())) f = loadtxt(arquivo.name + '.elm', dtype="string") els = f[:, 0] eln = f[:, 1] elm = f[:, 2] elz = f[:, 3] LSs = f[:, 4] eld = f[:, 5] Edict.clear() for n in range(len(Ebuttons)): Ebuttons[n].destroy() del Ebuttons[:] i = 0 Econtrol = 0 for n in range(len(els)): create() Edict[n]['LineShape'] = float(LSs[n]) Edict[n]['symbol'] = str(els[n]) Edict[n]['name'] = str(eln[n]) Edict[n]['mass'] = float(elm[n]) Edict[n]['Z'] = float(elz[n]) Edict[n]['profundidademax'] = float(eld[n]) Ebuttons[n]['text'] = str(els[n]) shutil.copy(arquivo.name + '-' + Edict[n]['symbol'] + '.dat' , Edict[n]['symbol']+'.dat') shutil.copy(arquivo.name + '-' + Edict[n]['symbol'] + '.prof' , Edict[n]['symbol']+'.prof') elem_select(0,Ebuttons) arquivo.close() def SAVESAMPLE(): config = tkFileDialog.asksaveasfile(mode='w') elist = open(config.name + '.elm', 'w+') for k in arange(9,18): config.write( (OFlabentries[k].get())+'\n' ) for j in arange(21,24): config.write( (OFlabentries[j].get())+'\n' ) config.write( '##############################################################################\n' ) config.write( '# dƐ/dx\n# dω²/dx\n# θ out\n# θ in\n# FWHM\n# E min\n# E max\n# E step\n# Depth step\n# Ion energy\n# Ion mass\n# Ion Z\n' ) for n in range(len(Edict)): elist.write(Edict[n]['symbol']+' ') elist.write(Edict[n]['name']+' ') elist.write(str(Edict[n]['mass'])+' ') elist.write(str(Edict[n]['Z'])+' ') elist.write(str(Edict[n]['LineShape'])+' ') elist.write(str(Edict[n]['profundidademax'])+'\n') shutil.copy(Edict[n]['symbol']+'.prof', config.name + '-' + Edict[n]['symbol'] + '.prof') shutil.copy(Edict[n]['symbol']+'.dat', config.name + '-' + Edict[n]['symbol'] + '.dat') shutil.copy('temp.sim', config.name + '.sim') elist.close() config.close() ############################################################################## # Buttons but = tk.Button(EPframel2, command=create, text='Add element', bd=1, height=1,width=15) but.pack() butrmv = tk.Button(EPframel2, command=remove, text='Remove element', bd=1, height=1,width=15) butrmv.pack() butPTE = tk.Button(EPframel2, text='Show PTE', bd=1, width=15, command=lambda i=i :elem_callback(Econtrol,Edict,Ebuttons) ) butPTE.pack() BUpdate = tk.Button(EPframel2, text ='Update properties', command=lambda i=int(Econtrol) :update(Econtrol), width=15) BUpdate.pack() BUpdateD = tk.Button(EPframel2, text ='Distribution', command =lambda i=int(Econtrol) : os.system("python profiler.py %s %s %s %s &" %( Edict[int(Econtrol)]['symbol'], str(methodvar.get()), str(Labentrys[11].get()), str(OFlabentries[17].get()) ) ), width=15) BUpdateD.pack() BLoad = tk.Button(EPframel, text ='Load Sample', command=lambda i=int(Econtrol) :LOADSAMPLE(), width=15) BLoad.pack() BSave = tk.Button(EPframee, text ='Save Sample', command=lambda i=int(Econtrol) :SAVESAMPLE(), width=15) BSave.pack() ############################################################################## # Interpolation methods RS = tk.Radiobutton(Labelprop, text="Step", variable=methodvar, value='step') RS.pack(side='left') RL = tk.Radiobutton(Labelprop, text="Lines", variable=methodvar, value='reta') RL.pack(side='right') ############################################################################## # Init RS.select() Ebuttons[0].invoke() ##############################################################################