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

3 4
import Tkinter as tk
from PTE import *
5
from numpy import ones
6

7
Edict = dict()
8 9 10 11 12 13
Ebuttons = list()
i=0

points = []
spline = 0
tag1 = "theline"
14 15 16 17 18 19 20
Econtrol = 0

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

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

22
##############################################################################
23
# Element callback
24 25 26 27 28 29 30 31 32 33 34

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

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

    global Econtrol, Edict
    button[Econtrol]['relief']='raised'
35
    Econtrol = i
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    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'])

    Entrymass.delete (0, len(Entrymass.get()))
    Entryname.delete (0, len(Entryname.get()))
    EntryZ.delete (0, len(EntryZ.get()))
    Entrysymbol.delete (0, len(Entrysymbol.get()))

    Entrymass.insert(0, Edict[int(Econtrol)]['mass'])
    Entryname.insert(0, Edict[int(Econtrol)]['name'])
    EntryZ.insert(0, Edict[int(Econtrol)]['Z'])
    Entrysymbol.insert(0, Edict[int(Econtrol)]['symbol'])

    #if Edict[i]['name'] == 'New':
    #    butPTE.invoke()
55

56
##############################################################################
57
# Init
58

59
def ewin_build(window, xmax, xstep):
60

61 62 63 64

##############################################################################
# Element addition

65 66
    def create():
        global i, Edict, Ebuttons
67
        Edict[i] = dict(name = "New", symbol = "Hf", mass = 178.00, Z = 72, dist = ones(int(xmax/xstep)), control = 0, LineShape = 200.)
68
        Ebuttons.insert(i, tk.Button(Eframe, text=i, width=1, height=1, command = lambda i=i : elem_select(i,Ebuttons,Labelmass,LabelZ,Labelname,Labelsymbol,Entrymass,EntryZ,Entryname,Entrysymbol)))
69 70 71
        Ebuttons[i].pack(side='left')
        i=i+1

72 73 74
##############################################################################
# Element deletion

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

86
##############################################################################
87 88 89 90 91 92 93 94
# Element Frames

    Label1 = tk.LabelFrame(window, text = 'Elements', relief='raised', bd=2)
    Label1.pack() 

    Eframe = tk.Canvas(Label1)
    Eframe.pack(fill='both',expand=0)
    
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
##############################################################################
# Init
    create()

##############################################################################
# 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'])
112 113
        #Edict[i]['LineShape'] = float(EntryLS.get())
        #LabelLS.configure(text = 'Line Shape α - %f' %Edict[i]['LineShape'])
114 115 116 117
        print Edict[i]

    Labelprop = tk.LabelFrame(window, text = 'Properties', relief='raised', bd=2)
    #Labelprop.pack()
118
    Labelprop.place(anchor='w', y=100, x=5)   
119

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

132 133 134 135 136 137 138 139 140 141
    EPframel2 = tk.Frame(LpFrame2)
    EPframel2.pack(side='left')
    EPframee2 = tk.Frame(LpFrame2)
    EPframee2.pack(side='right')

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

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

159
    BUpdate = tk.Button(EPframee2, text ='Update properties', command=lambda i=i :update(Econtrol), width=15)
160
    BUpdate.pack()#side='right')
161
    BUpdateD = tk.Button(EPframee2, text ='Update Distribution', command=lambda i=i :update(Econtrol), width=15)
162
    BUpdateD.pack()#side='left')
163

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

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

170 171
    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')
172 173 174 175 176 177 178

##############################################################################
# Init
    Entrymass.insert(0, Edict[int(Econtrol)]['mass'])
    Entryname.insert(0, Edict[int(Econtrol)]['name'])
    EntryZ.insert(0, Edict[int(Econtrol)]['Z'])
    Entrysymbol.insert(0, Edict[int(Econtrol)]['symbol'])
179
    #EntryLS.insert(0, Edict[int(Econtrol)]['LineShape'])
180

181
##############################################################################
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
# Canvas callback
    def point(event):
        Distcanvas.create_oval(event.x, event.y, event.x+1, event.y+1, fill="black")
        points.append(event.x)
        points.append(event.y)
        return points

    def canxy(event):
        print event.x, event.y

    def graph(event):
        global theline
        Distcanvas.create_line(points, tags="theline")

    def toggle(event):
        global spline
        if spline == 0:
            Distcanvas.itemconfigure(tag1, smooth=1)
            spline = 1
        elif spline == 1:
            Distcanvas.itemconfigure(tag1, smooth=0)
            spline = 0
        print event.x, event.y
        return spline

207
##############################################################################
208 209
# Drawing Canvas

210 211
    Label2 = tk.LabelFrame(window, text = 'Distribution', bd=1)
    #Label2.pack()   
212
    Label2.place(anchor='w', y=320, x=5)  
213 214

    Distcanvas = tk.Canvas(Label2, bg="white", width=800, height= 300)
215 216 217 218 219 220 221 222
    #Distcanvas.configure(cursor="crosshair")
    Distcanvas.grid_columnconfigure(999, weight = 1)
    Distcanvas.grid_rowconfigure(999, weight = 1)
    Distcanvas.pack()
    Distcanvas.bind("<Button-1>", point)
    Distcanvas.bind("<Button-3>", graph)
    Distcanvas.bind("<Button-2>", toggle)

223
##############################################################################
224