layers.py 9.58 KB
Newer Older
 Matheus Müller committed Mar 21, 2012 1 2 ``````# -*- coding: iso-8859-15 -*- `````` Matheus Müller committed Mar 05, 2012 3 ``````import Tkinter as tk `````` Matheus Müller committed Mar 21, 2012 4 5 ``````from numpy import arange, math from PTE import * `````` Matheus Müller committed Mar 05, 2012 6 7 `````` Frms = list() `````` Matheus Müller committed Mar 21, 2012 8 ``````Ldict = list() `````` Matheus Müller committed Mar 05, 2012 9 ``````Laycount = 0 `````` Matheus Müller committed Mar 26, 2012 10 ``````currdepht = 0 `````` Matheus Müller committed Mar 05, 2012 11 12 13 `````` ############################################################################## ############################################################################## `````` Matheus Müller committed Mar 26, 2012 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ``````# Common Functions def Dminchange(layernum): number = float(Ldict[layernum]['LandE'][6].get()) Ldict[layernum]['Dmin'] = number if layernum > 0: Ldict[layernum-1]['Dmax'] = number Ldict[layernum-1]['LandE'][7].delete(0, 'end') Ldict[layernum-1]['LandE'][7].insert(0, number) def Dmaxchange(layernum): number = float(Ldict[layernum]['LandE'][7].get()) Ldict[layernum]['Dmax'] = number if layernum < len(Ldict): Ldict[layernum+1]['Dmin'] = number Ldict[layernum+1]['LandE'][6].delete(0, 'end') Ldict[layernum+1]['LandE'][6].insert(0, number) `````` Matheus Müller committed Mar 05, 2012 31 `````` `````` Matheus Müller committed Mar 28, 2012 32 33 34 35 36 ``````############################################################################## def elem_callback(x, edict , ebutton, Labentrys): PTable(edict[x] , ebutton[x], Labentrys) `````` Matheus Müller committed Mar 26, 2012 37 38 ``````############################################################################## ############################################################################## `````` Matheus Müller committed Mar 21, 2012 39 `````` `````` Matheus Müller committed Mar 26, 2012 40 ``````class Layer: `````` Matheus Müller committed Mar 21, 2012 41 `````` `````` Matheus Müller committed Mar 28, 2012 42 `````` def self_destruct(self): `````` Matheus Müller committed Mar 26, 2012 43 44 `````` for n in range(len(self.Elements)): del self.Elements[n] `````` Matheus Müller committed Mar 28, 2012 45 `````` self.Ebuttons[n].grid_forget() `````` Matheus Müller committed Mar 26, 2012 46 `````` del self.Ebuttons[n] `````` Matheus Müller committed Mar 28, 2012 47 `````` self.Spinboxes[n].grid_forget() `````` Matheus Müller committed Mar 26, 2012 48 `````` del self.Spinboxes[n] `````` Matheus Müller committed Mar 28, 2012 49 50 51 52 53 54 55 56 `````` for n in range(8): self.Frames[n].pack_forget() for k in arange(0,1): self.Buttons[k].pack_forget() for j in range(4): self.LandE[j].pack_forget() self.LabelFrm.grid_forget() `````` Matheus Müller committed Mar 26, 2012 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 `````` def elem_select(self, i): Frames=list() Labentrys=list() def update(k, Elelist): Elelist[k]['name'] = str(Labentrys[6].get()) Labentrys[0].configure(text = '%s' %Elelist[k]['name']) Elelist[k]['mass'] = float(Labentrys[7].get()) Labentrys[1].configure(text = 'Mass - %f' %Elelist[k]['mass']) Elelist[k]['Z'] = float(Labentrys[8].get()) Labentrys[2].configure(text = 'Z - %f' %Elelist[k]['Z']) Elelist[k]['symbol'] = str(Labentrys[9].get()) Labentrys[3].configure(text = 'Symbol - %s' %Elelist[k]['symbol']) Elelist[k]['LineShape'] = float(Labentrys[10].get()) Labentrys[4].configure(text = 'Line Shape α - %f' %Elelist[k]['LineShape']) tempw=tk.Tk() tempw.title(self.Elements[i]['name']) for n in range(3): Frames.insert(n, tk.Frame(tempw) ) Frames[0].pack(side='left') Frames[1].pack(side='top') Frames[2].pack(side='right') for n in arange(3, 5): Frames.insert(n, tk.Frame(Frames[0]) ) Frames[3].pack(side='left') Frames[4].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 `````` Matheus Müller committed Mar 28, 2012 97 98 99 100 101 `````` Labentrys.insert(0, tk.Label(Frames[3], width=23, pady=2, text='%s' %self.Elements[i]['name']) ) Labentrys.insert(1, tk.Label(Frames[3], width=23, pady=2, text='Mass - %f' %self.Elements[i]['mass']) ) Labentrys.insert(2, tk.Label(Frames[3], width=23, pady=2, text='Z - %f' %self.Elements[i]['Z']) ) Labentrys.insert(3, tk.Label(Frames[3], width=23, pady=2, text= 'Symbol - %s' %self.Elements[i]['symbol']) ) Labentrys.insert(4, tk.Label(Frames[3], width=23, pady=2, text='Line Shape α - %f' %self.Elements[i]['LineShape']) ) `````` Matheus Müller committed Mar 26, 2012 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 `````` Labentrys.insert(5, tk.Label(Frames[3]) ) for n in range(5): Labentrys[n].pack() for n in arange(6, 11): Labentrys.insert(n, tk.Entry(Frames[4], width=17) ) Labentrys[n].pack() Labentrys[6].insert(0, self.Elements[i]['name']) Labentrys[7].insert(0, self.Elements[i]['mass']) Labentrys[8].insert(0, self.Elements[i]['Z']) Labentrys[9].insert(0, self.Elements[i]['symbol']) Labentrys[10].insert(0, self.Elements[i]['LineShape']) `````` Matheus Müller committed Mar 28, 2012 117 `````` butPTE = tk.Button(Frames[1],text='Select from PTE',width=15,command=lambda i=i:elem_callback(i,self.Elements,self.Ebuttons,Labentrys)) `````` Matheus Müller committed Mar 26, 2012 118 `````` butPTE.pack() `````` Matheus Müller committed Mar 28, 2012 119 `````` BUpdate = tk.Button(Frames[1], text ='Update properties', command=lambda i=i: update(i, self.Elements), width=15) `````` Matheus Müller committed Mar 26, 2012 120 121 122 `````` BUpdate.pack() tempw.mainloop() `````` Matheus Müller committed Mar 21, 2012 123 124 125 `````` def addel(self): i = int(self.Ecount) `````` Matheus Müller committed Mar 28, 2012 126 `````` n = int(self.Number) `````` Matheus Müller committed Mar 26, 2012 127 `````` self.Elements[i]=dict(name="New",symbol="Hf",mass=178.,Z=72,LineShape=200.) `````` Matheus Müller committed Mar 28, 2012 128 `````` self.Ebuttons.insert(i, tk.Button(self.Frames[6], text=i, command = lambda x=0: Ldict[n].elem_select(i) )) `````` Matheus Müller committed Mar 21, 2012 129 130 131 132 `````` self.Ebuttons[i].grid(column=0, row=i) self.Spinboxes.insert(i, tk.Spinbox(self.Frames[7], from_=0, to=1, increment=0.05, bd=5 )) self.Spinboxes[i].grid(column=0, row=i) self.Ecount = self.Ecount + 1 `````` Matheus Müller committed Mar 26, 2012 133 `````` `````` Matheus Müller committed Mar 21, 2012 134 `````` def rmvel(self): `````` Matheus Müller committed Mar 26, 2012 135 136 137 138 139 140 141 `````` if self.Ecount > 1: self.Ecount = self.Ecount - 1 del self.Elements[self.Ecount] self.Ebuttons[self.Ecount].destroy() del self.Ebuttons[self.Ecount] self.Spinboxes[self.Ecount].destroy() del self.Spinboxes[self.Ecount] `````` Matheus Müller committed Mar 21, 2012 142 143 `````` def __init__(self, canvas, count): `````` Matheus Müller committed Mar 26, 2012 144 145 `````` global Ldict, currdepht `````` Matheus Müller committed Mar 21, 2012 146 147 148 149 150 151 152 153 `````` self.Number=count self.Ecount=0 self.Elements=dict() self.Ebuttons=list() self.Spinboxes=list() self.Frames=list() self.LandE=list() self.Buttons=list() `````` Matheus Müller committed Mar 26, 2012 154 155 `````` self.Dmin=currdepht self.Dmax=currdepht+1. `````` Matheus Müller committed Mar 21, 2012 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 `````` self.LabelFrm = tk.LabelFrame(canvas, text = 'Layer %d' %int(Laycount+1), relief='raised', bd=2) self.LabelFrm.grid(column=(Laycount%4), row=int(math.floor(Laycount/4)) ) for i in range(2): self.Frames.insert(i, tk.Frame(self.LabelFrm)) for i in arange(2,4): self.Frames.insert(i, tk.Frame(self.Frames[0])) for i in arange(4,6): self.Frames.insert(i, tk.Frame(self.Frames[2])) for i in arange(6,8): self.Frames.insert(i, tk.Frame(self.Frames[1])) self.Frames[0].pack(side='top') self.Frames[1].pack(side='bottom') self.Frames[2].pack(side='left') self.Frames[3].pack(side='right') self.Frames[4].pack(side='left') self.Frames[5].pack(side='right') self.Frames[6].pack(side='left') self.Frames[7].pack(side='right') self.LandE.insert(0, tk.Label(self.Frames[4], width=14, pady=2, text='dƐ/dx') ) self.LandE.insert(1, tk.Label(self.Frames[4], width=14, pady=2, text='dω²/dx') ) `````` Matheus Müller committed Mar 26, 2012 179 180 `````` self.LandE.insert(2, tk.Label(self.Frames[4], width=14, pady=2, text='Depht min(nm)') ) self.LandE.insert(3, tk.Label(self.Frames[4], width=14, pady=2, text='Depht max(nm)') ) `````` Matheus Müller committed Mar 21, 2012 181 `````` `````` Matheus Müller committed Mar 26, 2012 182 `````` for i in arange(4,6): `````` Matheus Müller committed Mar 21, 2012 183 `````` self.LandE.insert(i, tk.Entry(self.Frames[5], width=11) ) `````` Matheus Müller committed Mar 26, 2012 184 185 `````` self.LandE.insert(6, tk.Entry(self.Frames[5], width=11, )) self.LandE.insert(7, tk.Entry(self.Frames[5], width=11, )) `````` Matheus Müller committed Mar 21, 2012 186 `````` `````` Matheus Müller committed Mar 26, 2012 187 `````` for i in range(8): `````` Matheus Müller committed Mar 21, 2012 188 189 190 191 192 193 194 `````` self.LandE[i].pack() self.Buttons.insert(0, tk.Button(self.Frames[4], command=lambda i=i :Ldict[self.Number].addel(), text='Add element',width=11)) self.Buttons.insert(1, tk.Button(self.Frames[5], command=lambda i=i :Ldict[self.Number].rmvel(), text='Remove element',width=11)) for i in range(2): self.Buttons[i].pack() `````` Matheus Müller committed Mar 26, 2012 195 196 197 198 199 200 201 `````` self.LandE[4].insert(0, 200.) self.LandE[5].insert(0, 20000.) self.LandE[6].insert(0, self.Dmin) self.LandE[7].insert(0, self.Dmax) currdepht = currdepht + 1. `````` Matheus Müller committed Mar 21, 2012 202 203 204 205 206 207 ``````############################################################################## ############################################################################## def addlay(Laycanvas): global Laycount, Ldict Ldict.insert(Laycount, Layer(Laycanvas, Laycount)) `````` Matheus Müller committed Mar 26, 2012 208 `````` Ldict[Laycount].addel() `````` Matheus Müller committed Mar 21, 2012 209 210 211 212 213 214 `````` Laycount = Laycount + 1 ############################################################################## def rmvlay(): global Laycount, Ldict `````` Matheus Müller committed Mar 26, 2012 215 216 `````` if Laycount > 1: Ldict[Laycount-1].self_destruct() `````` Matheus Müller committed Mar 28, 2012 217 `````` del Ldict[Laycount-1] `````` Matheus Müller committed Mar 21, 2012 218 219 220 221 222 `````` Laycount = Laycount - 1 ############################################################################## ############################################################################## `````` Matheus Müller committed Mar 05, 2012 223 ``````def layers(): `````` Matheus Müller committed Mar 21, 2012 224 225 226 `````` global Laycount, Ldict Laycount = 0 `````` Matheus Müller committed Mar 05, 2012 227 228 `````` laywin = tk.Tk() laywin.title('Layers') `````` Matheus Müller committed Mar 28, 2012 229 `````` laywin.minsize(950,400) `````` Matheus Müller committed Mar 26, 2012 230 `````` laywin.geometry('950x200+200+600') `````` Matheus Müller committed Mar 05, 2012 231 232 233 234 235 236 `````` for i in range(2): Frms.insert(i, tk.Frame(laywin)) Frms[0].pack(side='top') Frms[1].pack(side='bottom') `````` Matheus Müller committed Mar 21, 2012 237 `````` Laycanvas = tk.Canvas(Frms[1]) `````` Matheus Müller committed Mar 26, 2012 238 239 240 241 242 243 244 `````` Laycanvas.pack(fill='both',expand='yes') #Laycanvas.config(scrollregion=(0,0,300, 1000)) #ScrollbarY = tk.Scrollbar(Laycanvas, orient='vertical') #ScrollbarY.pack( side = 'right', fill='y' ) #ScrollbarY.config(command = Laycanvas.yview) #Laycanvas.config(yscrollcommand = ScrollbarY.set) `````` Matheus Müller committed Mar 05, 2012 245 `````` `````` Matheus Müller committed Mar 21, 2012 246 `````` butadd = tk.Button(Frms[0], command=lambda i=i :addlay(Laycanvas), text='Add layer', bd=1, height=1,width=10, pady='4') `````` Matheus Müller committed Mar 05, 2012 247 `````` butadd.pack(side='left') `````` Matheus Müller committed Mar 26, 2012 248 `````` butrmv = tk.Button(Frms[0], command=lambda i=i :rmvlay(), text='Remove layer', bd=1, height=1,width=10, pady='4') `````` Matheus Müller committed Mar 05, 2012 249 250 `````` butrmv.pack(side='left') `````` Matheus Müller committed Mar 26, 2012 251 252 `````` butadd.invoke() `````` Matheus Müller committed Mar 05, 2012 253 254 255 `````` laywin.mainloop() ############################################################################## `````` Matheus Müller committed Mar 21, 2012 256 ``##############################################################################``