Ewindow.py 5.87 KB
Newer Older
1 2
import Tkinter as tk
from PTE import *
3
from numpy import ones
4

5
Edict = dict()
6 7 8 9 10 11
Ebuttons = list()
i=0

points = []
spline = 0
tag1 = "theline"
12 13 14 15 16 17 18
Econtrol = 0

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

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

20
##############################################################################
21
# Element callback
22 23 24 25
def elem_callback(edict , ebutton, canvas, i, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol, EntryLS):
    global Econtrol
    Econtrol = i
    PTable(edict , ebutton, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol, EntryLS)
26

27
##############################################################################
28 29
# Element addition

30
def ewin_build(window, xmax, xstep):
31 32 33

    def create():
        global i, Edict, Ebuttons
34
        Edict[i] = dict(name = "New", symbol = "Hf", mass = 178.00, Z = 72, dist = ones(int(xmax/xstep)), control = 0, LineShape = 200.)
35
        Ebuttons.insert(i, tk.Button(Eframe,text=i,width=1,height=1, command=lambda i=i : elem_callback(Edict[i] , Ebuttons[i], Distcanvas, i, Labelmass, LabelZ, Labelname, Labelsymbol, LabelLS, Entrymass, EntryZ, Entryname, Entrysymbol, EntryLS )))
36 37 38
        Ebuttons[i].pack(side='left')
        i=i+1

39 40 41 42 43 44 45
    def remove():
        global i, Edict, Ebuttons
        if i > 1:
            i=i-1
            del Edict[i]
            Ebuttons[i].destroy()
            del Ebuttons[i]
46

47
##############################################################################
48 49 50 51 52 53 54 55
# Element Frames

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

    Eframe = tk.Canvas(Label1)
    Eframe.pack(fill='both',expand=0)
    
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
##############################################################################
# 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'])
        Edict[i]['LineShape'] = float(EntryLS.get())
        LabelLS.configure(text = 'Line Shape - %f' %Edict[i]['LineShape'])
        print Edict[i]

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

    EPframel = tk.Frame(Labelprop)
    EPframel.pack(side='left')
    EPframee = tk.Frame(Labelprop)
    EPframee.pack(side='right')

    Labelname = tk.Label(EPframel, width=30, pady=2, text='%s' %Edict[int(Econtrol)]['name'])
    Labelmass = tk.Label(EPframel, width=30, pady=2, text='Mass - %f' %Edict[int(Econtrol)]['mass'])
    LabelZ = tk.Label(EPframel, width=30, pady=2, text='Z - %f' %Edict[int(Econtrol)]['Z'])
    Labelsymbol = tk.Label(EPframel, width=30, 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'])
    Labelname.pack()
    Labelmass.pack()
    LabelZ.pack()
    Labelsymbol.pack()
    LabelLS.pack()

    Entryname = tk.Entry(EPframee, width=22)
    Entrymass = tk.Entry(EPframee, width=22)
    EntryZ = tk.Entry(EPframee, width=22)
    Entrysymbol = tk.Entry(EPframee, width=22)
    EntryLS = tk.Entry(EPframee, width=22)
    Entryname.pack()
    Entrymass.pack()
    EntryZ.pack()
    Entrysymbol.pack()
    EntryLS.pack()

    BUpdate = tk.Button(EPframee, text ='Update', command=lambda i=int(Econtrol) :update(i), width=20)
    BUpdate.pack(side='bottom')

    but = tk.Button(EPframel, command=create, text='Add element', bd=1, height=1,width=15)
    but.pack(side='left') 

    butrmv = tk.Button(EPframel, command=remove, text='Remove element', bd=1, height=1,width=15)
    butrmv.pack(side='right')

##############################################################################
# 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'])
    EntryLS.insert(0, Edict[int(Econtrol)]['LineShape'])
124

125
##############################################################################
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
# 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

151
##############################################################################
152 153
# Drawing Canvas

154 155 156 157 158
    Label2 = tk.LabelFrame(window, text = 'Distribution', bd=1)
    #Label2.pack()   
    Label2.place(anchor='w', y=375, x=5)  

    Distcanvas = tk.Canvas(Label2, bg="white", width=800, height= 300)
159 160 161 162 163 164 165 166
    #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)

167
##############################################################################
168