Ewindow.py 2.76 KB
Newer Older
1
2
import Tkinter as tk
from PTE import *
Matheus Müller's avatar
Matheus Müller committed
3
from numpy import ones
4

Matheus Müller's avatar
Matheus Müller committed
5
Edict = dict()
6
7
8
9
10
11
12
Ebuttons = list()
i=0

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

Matheus Müller's avatar
Matheus Müller committed
13
##############################################################################
14
15
16
17
18
# Element callback
def elem_callback(edict , ebutton, frm):
    #plot_dist(edict, frm)
    PTable(edict , ebutton)

Matheus Müller's avatar
Matheus Müller committed
19
##############################################################################
20
21
# Element addition

Matheus Müller's avatar
Matheus Müller committed
22
def ewin_build(window, xmax, xstep):
23
24
25

    def create():
        global i, Edict, Ebuttons
Matheus Müller's avatar
Matheus Müller committed
26
        Edict[i] = dict(name = "New", symbol = "Hf", mass = 178.00, Z = 72, dist = ones(int(xmax/xstep)), control = 0, LineShape = 200.)
27
28
29
30
31
32
33
34
        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)

Matheus Müller's avatar
Matheus Müller committed
35
##############################################################################
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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()

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

Matheus Müller's avatar
Matheus Müller committed
77
##############################################################################
78
79
80
81
82
83
84
85
86
87
88
# 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)

Matheus Müller's avatar
Matheus Müller committed
89
##############################################################################
90
91
92
# Init
    create()

Matheus Müller's avatar
Matheus Müller committed
93
##############################################################################