Ewindow.py 2.48 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
import Tkinter as tk
from PTE import *

Edict = list()
Ebuttons = list()
i=0

points = []
spline = 0
tag1 = "theline"

#######################################
# Element callback
def elem_callback(edict , ebutton, frm):
    #plot_dist(edict, frm)
    PTable(edict , ebutton)

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

def ewin_build(window):

    def create():
        global i, Edict, Ebuttons
        Edict.insert(i, dict(name = "New", symbol = "Hf", mass = 178.00, Z = 72, dist = [1./3.]*200 + [0.]*1800, control = 0))
        Ebuttons.insert(i, tk.Button(Eframe,text=i,width=1,height=1, command=lambda i=i : elem_callback(Edict[i] , Ebuttons[i], Dframe)))
        Ebuttons[i].pack(side='left')
        i=i+1

    but = tk.Button(window, command=create, text='Add element', bd=2, height=2,width=7)
    but.pack() 
    but.place(anchor='n', y=5, x=44)

#######################################
# Element Frames

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

    Label2 = tk.LabelFrame(window, text = 'Distribution', bd=1)
    Label2.pack()   
    Label2.place(anchor='w', y=210)   

    Eframe = tk.Canvas(Label1)
    Eframe.pack(fill='both',expand=0)
    
    Dframe = tk.Frame(Label2)
    Dframe.pack()

#######################################
# 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

#######################################
# Drawing Canvas

    Distcanvas = tk.Canvas(Dframe, bg="white", width=600, height= 300)
    #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)

#######################################
# Init
    create()
    print Distcanvas.grid_size()

#######################################