Ewindow.py 7.13 KB
Newer Older
1 2
# -*- coding: iso-8859-15 -*-

3 4
import Tkinter as tk
from PTE import *
5 6 7
from pylab import *
from numpy import zeros
import os
8

9
Edict = dict()
10 11 12 13 14 15
Ebuttons = list()
i=0

points = []
spline = 0
tag1 = "theline"
16 17 18 19 20 21 22
Econtrol = 0

##############################################################################
# PTE window

#PTE = tk.Tk()
#PTE.title('Periodic Table of Elements')
23

24
##############################################################################
25
# Element callback
26 27 28 29 30 31 32

def elem_callback(x, edict , ebutton, Labelmass, LabelZ, Labelname, Labelsymbol, Entrymass, EntryZ, Entryname, Entrysymbol):
    PTable(edict[x] , ebutton[x], Labelmass, LabelZ, Labelname, Labelsymbol, Entrymass, EntryZ, Entryname, Entrysymbol)

##############################################################################
# Element selection

33
def elem_select(i, button, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol,EntryLS):
34

35
    global Econtrol, Edict, methodvar
36
    button[Econtrol]['relief']='raised'
37
    Econtrol = i
38 39 40 41 42 43
    button[i]['relief']='sunken'

    Labelmass.configure(text = 'Mass - %f' %Edict[i]['mass'])
    LabelZ.configure(text = 'Z - %f' %Edict[i]['Z'])
    Labelname.configure(text = '%s' %Edict[i]['name'])
    Labelsymbol.configure(text = 'Symbol - %s' %Edict[i]['symbol'])
44
    LabelLS.configure(text = 'Line Shape α - %f' %Edict[i]['LineShape'])
45 46 47 48 49

    Entrymass.delete (0, len(Entrymass.get()))
    Entryname.delete (0, len(Entryname.get()))
    EntryZ.delete (0, len(EntryZ.get()))
    Entrysymbol.delete (0, len(Entrysymbol.get()))
50
    EntryLS.delete (0, len(EntryLS.get()))
51 52 53

    Entrymass.insert(0, Edict[int(Econtrol)]['mass'])
    Entryname.insert(0, Edict[int(Econtrol)]['name'])
54
    EntryZ.insert(0, int(Edict[int(Econtrol)]['Z']))
55
    Entrysymbol.insert(0, Edict[int(Econtrol)]['symbol'])
56
    EntryLS.insert(0, Edict[int(Econtrol)]['LineShape'])
57

58
##############################################################################
59
# Init
60

61
def ewin_build(window, xmax, xstep):
62

63 64 65
##############################################################################
# Element addition

66 67
    def create():
        global i, Edict, Ebuttons
68 69 70
        Edict[i] = dict(name = "Element X", symbol = "Hf", mass = 178.00, Z = 72, dist = zeros(int(xmax/xstep)), control = 0, LineShape = 200.)
        Ebuttons.insert(i, tk.Button(Eframe, text=i, width=1, height=1, command = lambda i=i : elem_select(i,Ebuttons,Labelmass,LabelZ,Labelname,Labelsymbol,LabelLS,Entrymass,EntryZ,Entryname,Entrysymbol,EntryLS)))
        Ebuttons[i].grid(column = ((len(Ebuttons)-1)%15), row = int(math.floor((len(Ebuttons)-1)/15)))
71 72
        i=i+1

73 74 75
##############################################################################
# Element deletion

76
    def remove():
77
        global i, Edict, Ebuttons, Econtrol
78 79 80 81 82
        if i > 1:
            i=i-1
            del Edict[i]
            Ebuttons[i].destroy()
            del Ebuttons[i]
83 84 85
            if Econtrol == i:
                Econtrol = Econtrol -1
                Ebuttons[Econtrol]['relief']='sunken'
86

87
##############################################################################
88 89
# Element Frames

90 91 92
    Labelprop = tk.LabelFrame(window, text = 'Properties', relief='raised', bd=2)
    Labelprop.pack(side = 'top')

93
    Label1 = tk.LabelFrame(window, text = 'Elements', relief='raised', bd=2)
94
    Label1.pack(side = 'top') 
95 96 97

    Eframe = tk.Canvas(Label1)
    Eframe.pack(fill='both',expand=0)
98

99 100 101
##############################################################################
# Init
    create()
102
    
103 104 105 106 107 108 109 110 111 112 113 114 115
##############################################################################
# Properties

    global Econtrol, Edict
    def update(i):
        Edict[i]['mass'] = float(Entrymass.get())
        Labelmass.configure(text = 'Mass - %f' %Edict[i]['mass'])
        Edict[i]['Z'] = float(EntryZ.get())
        LabelZ.configure(text = 'Z - %f' %Edict[i]['Z'])
        Edict[i]['name'] = str(Entryname.get())
        Labelname.configure(text = '%s' %Edict[i]['name'])
        Edict[i]['symbol'] = str(Entrysymbol.get())
        Labelsymbol.configure(text = 'Symbol - %s' %Edict[i]['symbol'])
116 117 118
        Edict[i]['LineShape'] = float(EntryLS.get())
        LabelLS.configure(text = 'Line Shape α - %f' %Edict[i]['LineShape'])
        Edict[i]['dist'] = np.loadtxt(Edict[i]['symbol']+".prof")
119 120
        print Edict[i]

121 122 123 124 125 126 127 128
    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)
129
    EPframel.pack(side='left')
130
    EPframee = tk.Frame(LpFrame1)
131 132
    EPframee.pack(side='right')

133 134 135 136 137
    EPframel2 = tk.Frame(LpFrame2)
    EPframel2.pack(side='left')
    EPframee2 = tk.Frame(LpFrame2)
    EPframee2.pack(side='right')

138 139 140 141 142
    Labelname = tk.Label(EPframel, width=26, pady=2, text='%s' %Edict[int(Econtrol)]['name'])
    Labelmass = tk.Label(EPframel, width=26, pady=2, text='Mass - %f' %Edict[int(Econtrol)]['mass'])
    LabelZ = tk.Label(EPframel, width=26, pady=2, text='Z - %f' %Edict[int(Econtrol)]['Z'])
    Labelsymbol = tk.Label(EPframel, width=26, pady=2, text= 'Symbol - %s' %Edict[int(Econtrol)]['symbol'])
    LabelLS = tk.Label(EPframel, width=26, pady=2, text='Line Shape α - %f' %Edict[int(Econtrol)]['LineShape'])
143 144 145 146
    Labelname.pack()
    Labelmass.pack()
    LabelZ.pack()
    Labelsymbol.pack()
147
    LabelLS.pack()
148

149 150 151 152 153
    Entryname = tk.Entry(EPframee, width=18)
    Entrymass = tk.Entry(EPframee, width=18)
    EntryZ = tk.Entry(EPframee, width=18)
    Entrysymbol = tk.Entry(EPframee, width=18)
    EntryLS = tk.Entry(EPframee, width=18)
154 155 156 157
    Entryname.pack()
    Entrymass.pack()
    EntryZ.pack()
    Entrysymbol.pack()
158
    EntryLS.pack()
159

160 161 162
    methodvar = tk.StringVar()
    methodvar.set('reta')

163 164 165
##############################################################################
# Buttons

166 167
    but = tk.Button(EPframel2, command=create, text='Add element', bd=1, height=1,width=15)
    but.pack()#side='left') 
168

169 170
    butrmv = tk.Button(EPframel2, command=remove, text='Remove element', bd=1, height=1,width=15)
    butrmv.pack()#side='right')
171

172 173
    butPTE = tk.Button(EPframel2, text='Show PTE', bd=1, width=15, command=lambda i=i :elem_callback(Econtrol,Edict,Ebuttons,Labelmass,LabelZ,Labelname,Labelsymbol,Entrymass,EntryZ,Entryname,Entrysymbol))
    butPTE.pack()#side='left')
174

175 176
    BUpdate = tk.Button(EPframel2, text ='Update properties', command=lambda i=int(Econtrol) :update(Econtrol), width=15)
    BUpdate.pack()#side='right')
177

178
    BUpdateD = tk.Button(EPframel2, text ='Distribution', command =lambda i=int(Econtrol) : os.system("python profiler.py %s %s &" %( Edict[int(Econtrol)]['symbol'], str(methodvar.get()) ) ), width=15)
179
    BUpdateD.pack()#side='left')
180

181 182 183 184 185 186 187 188
##############################################################################
# Interpolation methods

    RS = tk.Radiobutton(Labelprop, text="Step", variable=methodvar, value='step')
    RS.pack()
    RL = tk.Radiobutton(Labelprop, text="Lines", variable=methodvar, value='reta')
    RL.pack()

189
##############################################################################
190
# Init
191
    RS.select()
192
    Ebuttons[0].invoke()
193

194
##############################################################################
195