layers.py 9.18 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
10
11
12
Laycount = 0

##############################################################################
##############################################################################
13
14
# Common Functions

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

18
19
##############################################################################
##############################################################################
20

21
class Layer:
22

23
    def self_destruct(self):
24
25
        for n in range(len(self.Elements)):
            del self.Elements[n]
26
            self.Ebuttons[n].grid_forget()
27
            del self.Ebuttons[n]
28
            self.Spinboxes[n].grid_forget()
29
            del self.Spinboxes[n]
30
31
32
33
34
35
36
37
        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()
        
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

    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
77
        # 5 // 11 = Max Depht (Not used)
78
79
80
81
82
        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']) )
83
        Labentrys.insert(5, tk.Label(Frames[3]) ) #To fill structure of function called
84
85
86
87
88
89
90
91
92
93
94
95
96
97

        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'])

98
        butPTE = tk.Button(Frames[1],text='Select from PTE',width=15,command=lambda i=i:elem_callback(i,self.Elements,self.Ebuttons,Labentrys))
99
        butPTE.pack()
100
        BUpdate = tk.Button(Frames[1], text ='Update properties', command=lambda i=i: update(i, self.Elements), width=15)
101
102
103
        BUpdate.pack()

        tempw.mainloop()
104
105
106

    def addel(self):
        i = int(self.Ecount)
107
        n = int(self.Number)
108
        self.Elements[i]=dict(name="New",symbol="Hf",mass=178.,Z=72,LineShape=200.)
109
        self.Ebuttons.insert(i, tk.Button(self.Frames[6], text=i, command = lambda x=0: Ldict[n].elem_select(i) ))
110
111
112
113
        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
114
        
115
    def rmvel(self):
116
117
118
119
120
121
122
        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]
123

Matheus Müller's avatar
Ajustes    
Matheus Müller committed
124
125
126
127
128
129
130
131
132
    def normalize(self):
        su = 0.
        for n in range(len(self.Elements)):
            su = su + float(self.Spinboxes[n].get())
        for n in range(len(self.Spinboxes)):
            normcon = float(self.Spinboxes[n].get())/su
            self.Spinboxes[n].delete (0, "end")
            self.Spinboxes[n].insert (0, normcon)

133
    def __init__(self, canvas, count):
134
        global Ldict
135

136
137
138
139
140
141
142
143
        self.Number=count
        self.Ecount=0
        self.Elements=dict()
        self.Ebuttons=list()
        self.Spinboxes=list()
        self.Frames=list()
        self.LandE=list()
        self.Buttons=list()
144
        self.Depht=1.
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
        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') )
168
        self.LandE.insert(2, tk.Label(self.Frames[4], width=14, pady=2, text='Depht(nm)') )
169

170
        for i in arange(3,5):
171
            self.LandE.insert(i, tk.Entry(self.Frames[5], width=11) )
172
        self.LandE.insert(5, tk.Entry(self.Frames[5], width=11, ))
173

174
        for i in range(6):
175
            self.LandE[i].pack(anchor='n')
176
177
178

        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))
Matheus Müller's avatar
Ajustes    
Matheus Müller committed
179
        self.Buttons.insert(2, tk.Button(self.Frames[4], command=lambda i=i :Ldict[self.Number].normalize(), text='Normalize',width=11))
180
181
        self.Buttons.insert(3, tk.Button(self.Frames[5], width=11, relief = 'flat'))
        for i in range(4):
182
183
            self.Buttons[i].pack()

184
185
186
        self.LandE[3].insert(0, 200.)
        self.LandE[4].insert(0, 20000.)
        self.LandE[5].insert(0, self.Depht)
187

188
189
190
191
192
193
##############################################################################
##############################################################################

def addlay(Laycanvas):
    global Laycount, Ldict
    Ldict.insert(Laycount, Layer(Laycanvas, Laycount))
194
    Ldict[Laycount].addel()
195
196
197
198
199
200
    Laycount = Laycount + 1

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

def rmvlay():
    global Laycount, Ldict
201
202
    if Laycount > 1:
        Ldict[Laycount-1].self_destruct()
203
        del Ldict[Laycount-1]
204
205
206
207
208
        Laycount = Laycount - 1

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

209
def layers():
210
211
212
    global Laycount, Ldict
    Laycount = 0

213
214
    laywin = tk.Tk()
    laywin.title('Layers')
215
    #laywin.minsize(950,400)
216
    laywin.geometry('950x200+200+600')
217
218
219
220
221
222

    for i in range(2):
        Frms.insert(i, tk.Frame(laywin))

    Frms[0].pack(side='top')
    Frms[1].pack(side='bottom')
Matheus Müller's avatar
Ajustes    
Matheus Müller committed
223

224
    Laycanvas = tk.Canvas(Frms[1])
Matheus Müller's avatar
Ajustes    
Matheus Müller committed
225
    Laycanvas.create_window(20, 0, anchor='nw', height=400)
226
227
    Laycanvas.pack(fill='both',expand='yes')

Matheus Müller's avatar
Ajustes    
Matheus Müller committed
228
229
230
    ScrollbarY = tk.Scrollbar(Frms[1], orient='vertical', command = Laycanvas.yview)
    ScrollbarY.pack( side = 'right', fill='y' )
    Laycanvas.config(yscrollcommand = ScrollbarY.set)
231

232
    butadd = tk.Button(Frms[0], command=lambda i=i :addlay(Laycanvas), text='Add layer', bd=1, height=1,width=10, pady='4')
233
    butadd.pack(side='left')
234
    butrmv = tk.Button(Frms[0], command=lambda i=i :rmvlay(), text='Remove layer', bd=1, height=1,width=10, pady='4')
235
236
    butrmv.pack(side='left')

237
238
    butadd.invoke()

239
240
241
    laywin.mainloop()

##############################################################################
242
##############################################################################