Eprop.py 5.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import Tkinter as tk
from Edict import *
from pylab import *

xsum=0.
xdep=0.

def atomsubmenu(elem, but):

    sub = tk.Tk()
    sub.title(elem['name'])

    propbutton = tk.Menubutton(sub, width=20, text='Edit properties') 
    edit = tk.Menu(propbutton)               
    propbutton.config(menu=edit)

    distbutton = tk.Menubutton(sub, width=20, text='Edit distribution') 
    editdist = tk.Menu(distbutton)               
    distbutton.config(menu=editdist) 

    def cmdadd():
        if  elem['control']==0:
            elem['control']=1    
            but['text'] = elem['symbol']  
            but['relief'] = 'sunken'                                    
            addremove['text']='Remove element'
        else:
            elem['control']=0
            but['relief'] = 'raised'                                   
            addremove['text']='Add element'

    addremove = tk.Button(sub, width=16, bg='white', command=cmdadd, relief='raised', bd=4)
    if  elem['control']==0:
        addremove['text']='Add element'
    else:
        addremove['text']='Remove element'
    addremove.pack(side='bottom')

    L1 = tk.Label(sub, text = 'Mass - %f' %elem['mass'])
    L1.pack()
    L2 = tk.Label(sub, text = 'Z - %d' %elem['Z'])
    L2.pack()
    L3 = tk.Label(sub, text = 'Symbol - %s' %elem['symbol'])
    L3.pack()

    def cmdmass():
        submass = tk.Tk()
        submass.title('%s - Mass' %elem['name'])
        def modmass():
            elem['mass'] = float(E1.get())
            submass.destroy()
            L1.configure(text = 'Mass - %f' %elem['mass'])
        E1 = tk.Entry(submass, bd =2, width=20)
        E1.pack()
        B1 = tk.Button(submass, text ='Modify', command=modmass, width=18)
        B1.pack()
        E1.focus_force()
        F1 = tk.Frame(submass, width=300)
        F1.pack()
        submass.mainloop()

    def cmdz():
        subz = tk.Tk()
        subz.title('%s - Z' %elem['name'])
        def modz():
            elem['Z'] = int(E2.get(), 10)
            subz.destroy()
            L2.configure(text = 'Z - %d' %elem['Z'])
        E2 = tk.Entry(subz, bd =2, width=20)
        E2.pack()
        B2 = tk.Button(subz, text ='Modify', command=modz, width=18)
        B2.pack()
        E2.focus_force()
        subz.mainloop()

    def cmdname():
        subname = tk.Tk()
        subname.title('%s - Name' %elem['name'])
        def modname():
            elem['name'] = E3.get()
            subname.destroy()
            sub.title(elem['name'])
        E3 = tk.Entry(subname, bd =2, width=20)
        E3.pack()
        B3 = tk.Button(subname, text ='Modify', command=modname, width=18)
        B3.pack()
        E3.focus_force()
        subname.mainloop()

    def cmdsymbol():
        subsymbol = tk.Tk()
        subsymbol.title('Symbol - %s' %elem['symbol'])
        def modsymbol():
            elem['symbol'] = E4.get()
            subsymbol.destroy()
            L3.configure(text = 'Symbol - %s' %elem['symbol'])
            but['text'] = elem['symbol']
        E4 = tk.Entry(subsymbol, bd =2, width=20)
        E4.pack()
        B4 = tk.Button(subsymbol, text ='Modify', command=modsymbol, width=18)
        B4.pack()
        E4.focus_force()
        subsymbol.mainloop()

    def cmddraw():
        print elem['mass']

    def cmdnume(): 
        global xsum
        xsum = 0
        subnume = tk.Tk()
        subnume.title('%s - Distribution' %elem['name'])
        subnume.minsize(295,95)
        subnume.resizable(width='false', height='false')
        F6 = tk.Frame(subnume, width=100)
        F6b = tk.Frame(subnume, width=100)
        F6.grid(column=0, row=0, sticky='w')
        F6b.grid(column=0, row=0, sticky='e')
        def modnume():
            global xsum
            global xdep
            xdep=float(E6.get())
            L6.configure(text='Current depth = %fnm' %(xdep+xsum/100))
            for j in range(int(xsum), int(xsum + xdep*100)):
                if j > 999:
                    print "Reached maximum depth"
                    break
                else:
                    elem['dist'][j]=float(E6b.get())
            xsum+=xdep*100
            E6.delete(0, 'end')
            E6.insert(0, 0)           

        E6 = tk.Entry(F6b, bd =2, width=10)
        E6.pack()
        E6b = tk.Entry(F6b, bd =2, width=10)
        E6b.pack()
        B6 = tk.Button(subnume, text ='Add depth/concentration', command=modnume, width=33)
        B6.grid(column=0, row=2)
        E6.focus_force()
        L6 = tk.Label(subnume, text = 'Current depth = %f' %xdep)
        L6.grid(column=0, row=1)
        L6b = tk.Label(F6, text = 'Depth Amount', width=25)
        L6b.pack()
        L6c = tk.Label(F6, text = 'Concentration factor (0 to 1)', width=25)
        L6c.pack()
147
148
149

        plot_dist(elem, window)

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
        subnume.mainloop()

    def cmdspecial():
        plot (elem['dist'])
        show()
         
    edit.add_command(label='Mass', command=cmdmass)
    edit.add_command(label='Name', command=cmdname)
    edit.add_command(label='Z', command=cmdz)
    edit.add_command(label='Symbol', command=cmdsymbol)

    editdist.add_command(label='Drawing',  command=cmddraw)
    editdist.add_command(label='Numerical',  command=cmdnume)
    editdist.add_command(label='Special', command=cmdspecial)

    F2 = tk.Frame(sub, width=250, height=4)
    F2.pack()
    sub.resizable(width='true', height='false')

    propbutton.pack()
    propbutton.config(bg='white', bd=4, relief='raised')
    distbutton.pack()
    distbutton.config(bg='white', bd=4, relief='raised')
    sub.mainloop()