layers.py 9.58 KB
Newer Older
1 2
# -*- coding: iso-8859-15 -*-

3
import Tkinter as tk
4 5
from numpy import arange, math
from PTE import *
6 7

Frms = list()
8
Ldict = list()
9
Laycount = 0
10
currdepht = 0
11 12 13

##############################################################################
##############################################################################
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)
31

32 33 34 35 36
##############################################################################

def elem_callback(x, edict , ebutton, Labentrys):
    PTable(edict[x] , ebutton[x], Labentrys)

37 38
##############################################################################
##############################################################################
39

40
class Layer:
41

42
    def self_destruct(self):
43 44
        for n in range(len(self.Elements)):
            del self.Elements[n]
45
            self.Ebuttons[n].grid_forget()
46
            del self.Ebuttons[n]
47
            self.Spinboxes[n].grid_forget()
48
            del self.Spinboxes[n]
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()
        
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
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']) )
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'])

117
        butPTE = tk.Button(Frames[1],text='Select from PTE',width=15,command=lambda i=i:elem_callback(i,self.Elements,self.Ebuttons,Labentrys))
118
        butPTE.pack()
119
        BUpdate = tk.Button(Frames[1], text ='Update properties', command=lambda i=i: update(i, self.Elements), width=15)
120 121 122
        BUpdate.pack()

        tempw.mainloop()
123 124 125

    def addel(self):
        i = int(self.Ecount)
126
        n = int(self.Number)
127
        self.Elements[i]=dict(name="New",symbol="Hf",mass=178.,Z=72,LineShape=200.)
128
        self.Ebuttons.insert(i, tk.Button(self.Frames[6], text=i, command = lambda x=0: Ldict[n].elem_select(i) ))
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
133
        
134
    def rmvel(self):
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]
142 143

    def __init__(self, canvas, count):
144 145
        global Ldict, currdepht

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()
154 155
        self.Dmin=currdepht
        self.Dmax=currdepht+1.
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') )
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)') )
181

182
        for i in arange(4,6):
183
            self.LandE.insert(i, tk.Entry(self.Frames[5], width=11) )
184 185
        self.LandE.insert(6, tk.Entry(self.Frames[5], width=11, ))
        self.LandE.insert(7, tk.Entry(self.Frames[5], width=11, ))
186

187
        for i in range(8):
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()

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.

202 203 204 205 206 207
##############################################################################
##############################################################################

def addlay(Laycanvas):
    global Laycount, Ldict
    Ldict.insert(Laycount, Layer(Laycanvas, Laycount))
208
    Ldict[Laycount].addel()
209 210 211 212 213 214
    Laycount = Laycount + 1

##############################################################################

def rmvlay():
    global Laycount, Ldict
215 216
    if Laycount > 1:
        Ldict[Laycount-1].self_destruct()
217
        del Ldict[Laycount-1]
218 219 220 221 222
        Laycount = Laycount - 1

##############################################################################
##############################################################################

223
def layers():
224 225 226
    global Laycount, Ldict
    Laycount = 0

227 228
    laywin = tk.Tk()
    laywin.title('Layers')
229
    laywin.minsize(950,400)
230
    laywin.geometry('950x200+200+600')
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')
237
    Laycanvas = tk.Canvas(Frms[1])
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) 
245

246
    butadd = tk.Button(Frms[0], command=lambda i=i :addlay(Laycanvas), text='Add layer', bd=1, height=1,width=10, pady='4')
247
    butadd.pack(side='left')
248
    butrmv = tk.Button(Frms[0], command=lambda i=i :rmvlay(), text='Remove layer', bd=1, height=1,width=10, pady='4')
249 250
    butrmv.pack(side='left')

251 252
    butadd.invoke()

253 254 255
    laywin.mainloop()

##############################################################################
256
##############################################################################