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

3
4
import Tkinter as tk
from PTE import *
Matheus Müller's avatar
Matheus Müller committed
5
6
7
from pylab import *
from numpy import zeros
import os
8

Matheus Müller's avatar
Matheus Müller committed
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

Matheus Müller's avatar
Matheus Müller committed
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

Matheus Müller's avatar
Matheus Müller committed
33
def elem_select(i, button, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol,EntryLS):
34
35
36

    global Econtrol, Edict
    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'])
Matheus Müller's avatar
Matheus Müller committed
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()))
Matheus Müller's avatar
Matheus Müller committed
50
    EntryLS.delete (0, len(EntryLS.get()))
51
52
53

    Entrymass.insert(0, Edict[int(Econtrol)]['mass'])
    Entryname.insert(0, Edict[int(Econtrol)]['name'])
Matheus Müller's avatar
Matheus Müller committed
54
    EntryZ.insert(0, int(Edict[int(Econtrol)]['Z']))
55
    Entrysymbol.insert(0, Edict[int(Econtrol)]['symbol'])
Matheus Müller's avatar
Matheus Müller committed
56
    EntryLS.insert(0, Edict[int(Econtrol)]['LineShape'])
57

Matheus Müller's avatar
Matheus Müller committed
58
##############################################################################
59
# Init
60

Matheus Müller's avatar
Matheus Müller committed
61
def ewin_build(window, xmax, xstep):
62

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

66
67
    def create():
        global i, Edict, Ebuttons
Matheus Müller's avatar
Matheus Müller committed
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

Matheus Müller's avatar
Matheus Müller committed
87
##############################################################################
88
89
# Element Frames

Matheus Müller's avatar
Matheus Müller committed
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)
Matheus Müller's avatar
Matheus Müller committed
94
    Label1.pack(side = 'top') 
95
96
97

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

99
100
101
##############################################################################
# Init
    create()
Matheus Müller's avatar
Matheus Müller committed
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'])
Matheus Müller's avatar
Matheus Müller committed
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')

Matheus Müller's avatar
Matheus Müller committed
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()
Matheus Müller's avatar
Matheus Müller committed
147
    LabelLS.pack()
148

Matheus Müller's avatar
Matheus Müller committed
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()
Matheus Müller's avatar
Matheus Müller committed
158
    EntryLS.pack()
159

160
161
162
##############################################################################
# Buttons

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

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

169
170
    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')
171

Matheus Müller's avatar
Matheus Müller committed
172
173
    BUpdate = tk.Button(EPframel2, text ='Update properties', command=lambda i=int(Econtrol) :update(Econtrol), width=15)
    BUpdate.pack()#side='right')
174

Matheus Müller's avatar
Matheus Müller committed
175
176
    BUpdateD = tk.Button(EPframel2, text ='Distribution', command =lambda i=int(Econtrol) : os.system("python profiler.py %s &" %Edict[int(Econtrol)]['symbol']), width=15)
    BUpdateD.pack()#side='left')
177

Matheus Müller's avatar
Matheus Müller committed
178
##############################################################################
Matheus Müller's avatar
Matheus Müller committed
179
180
# Init
    Ebuttons[0].invoke()
181

Matheus Müller's avatar
Matheus Müller committed
182
##############################################################################
183