Ewindow.py 8.58 KB
Newer Older
1
# -*- coding: iso-8859-15 -*-
2
3
import Tkinter as tk
from PTE import *
Matheus Müller's avatar
Matheus Müller committed
4
5
6
from pylab import *
from numpy import zeros
import os
7
import tkFileDialog
8

9
10
##############################################################################
# Control variables and lists
Matheus Müller's avatar
Matheus Müller committed
11
Edict = dict()
12
Ebuttons = list()
13
Labentrys = list()
14
i=0
15
16
Econtrol = 0

Matheus Müller's avatar
Matheus Müller committed
17
##############################################################################
18
# Element callback
19
20
21
def elem_callback(x, edict , ebutton):
    global Labentrys
    PTable(edict[x] , ebutton[x], Labentrys)
22
23
24

##############################################################################
# Element selection
25
def elem_select(i, button):
26

27
    global Econtrol, Edict, Labentrys
28
    button[Econtrol]['relief']='raised'
29
    Econtrol = i
30
31
    button[i]['relief']='sunken'

32
33
34
35
36
37
    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'])
38

39
40
    for i in arange(6,12):
        Labentrys[i].delete (0, len(Labentrys[i].get()))
41

42
43
44
45
46
47
    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'])
48

Matheus Müller's avatar
Matheus Müller committed
49
##############################################################################
50
# Init
51
def ewin_build(window, EntryDstep):
52

53
54
##############################################################################
# Element addition
55
56
    def create():
        global i, Edict, Ebuttons
57
58
59
60
        Edict[i] = dict(name = "New Element", symbol = "Hf", mass = 178.00, Z = 72, dist = zeros(int(10./float(EntryDstep.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
61

62
63
##############################################################################
# Element deletion
64
    def remove():
65
        global i, Edict, Ebuttons, Econtrol
66
        if i > 1:
67
            i = i-1
68
69
70
            del Edict[i]
            Ebuttons[i].destroy()
            del Ebuttons[i]
71
72
73
            if Econtrol == i:
                Econtrol = Econtrol -1
                Ebuttons[Econtrol]['relief']='sunken'
74
        elem_select(0, Ebuttons)
75

Matheus Müller's avatar
Matheus Müller committed
76
##############################################################################
77
78
# Element Frames

Matheus Müller's avatar
Matheus Müller committed
79
80
81
    Labelprop = tk.LabelFrame(window, text = 'Properties', relief='raised', bd=2)
    Labelprop.pack(side = 'top')

82
    Label1 = tk.LabelFrame(window, text = 'Elements', relief='raised', bd=2)
Matheus Müller's avatar
Matheus Müller committed
83
    Label1.pack(side = 'top') 
84
85
86

    Eframe = tk.Canvas(Label1)
    Eframe.pack(fill='both',expand=0)
Matheus Müller's avatar
Matheus Müller committed
87

88
89
90
##############################################################################
# Init
    create()
Matheus Müller's avatar
Matheus Müller committed
91
    
92
93
94
##############################################################################
# Properties

95
    global Econtrol, Edict, Labentrys
96
    def update(i):
97
98
99
100
101
102
103
104
105
106
107
108
        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'])
Matheus Müller's avatar
Matheus Müller committed
109
        Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof")
110

111
112
113
114
115
116
117
118
    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)
119
    EPframel.pack(side='left')
120
    EPframee = tk.Frame(LpFrame1)
121
122
    EPframee.pack(side='right')

123
124
125
126
127
    EPframel2 = tk.Frame(LpFrame2)
    EPframel2.pack(side='left')
    EPframee2 = tk.Frame(LpFrame2)
    EPframee2.pack(side='right')

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    # 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
150
151
152
    methodvar = tk.StringVar()
    methodvar.set('reta')

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
##############################################################################
# Load/Save sample
    def LOADSAMPLE():
        arquivo = tkFileDialog.askopenfilename()
        f = loadtxt(arquivo, dtype="string")
        els = f[:, 0]
        eln = f[:, 1]
        elm = f[:, 2]
        elz = f[:, 3]
        LSs = f[:, 4]
        eld = f[:, 5]
        for n in range(len(els)):
            if n < (len(els)-1):
                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])
        elem_select(0,Ebuttons)

    def SAVESAMPLE():
177
        elist = tkFileDialog.asksaveasfile(mode='w')
178
179
180
181
182
        for n in range(len(Ebuttons)):
            elist.write(Edict[n]['symbol']+' ')
            elist.write(Edict[n]['name']+' ')
            elist.write(str(Edict[n]['mass'])+' ')
            elist.write(str(Edict[n]['Z'])+' ')
183
            elist.write(str(Edict[n]['LineShape'])+' ')
184
185
186
            elist.write(str(Edict[n]['profundidademax'])+'\n')
        elist.close()

187
188
189
##############################################################################
# Buttons

190
    but = tk.Button(EPframel2, command=create, text='Add element', bd=1, height=1,width=15)
191
    but.pack()
192
    butrmv = tk.Button(EPframel2, command=remove, text='Remove element', bd=1, height=1,width=15)
193
194
195
    butrmv.pack()
    butPTE = tk.Button(EPframel2, text='Show PTE', bd=1, width=15, command=lambda i=i :elem_callback(Econtrol,Edict,Ebuttons) )
    butPTE.pack()
Matheus Müller's avatar
Matheus Müller committed
196
    BUpdate = tk.Button(EPframel2, text ='Update properties', command=lambda i=int(Econtrol) :update(Econtrol), width=15)
197
198
199
200
201
202
203
204
205
    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(EntryDstep.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()
206

207
208
209
210
##############################################################################
# Interpolation methods

    RS = tk.Radiobutton(Labelprop, text="Step", variable=methodvar, value='step')
211
    RS.pack(side='left')
212
    RL = tk.Radiobutton(Labelprop, text="Lines", variable=methodvar, value='reta')
213
    RL.pack(side='right')
214

Matheus Müller's avatar
Matheus Müller committed
215
##############################################################################
Matheus Müller's avatar
Matheus Müller committed
216
# Init
217
    RS.select()
Matheus Müller's avatar
Matheus Müller committed
218
    Ebuttons[0].invoke()
219

Matheus Müller's avatar
Matheus Müller committed
220
##############################################################################
221