layers.py 4.19 KB
Newer Older
1
2
# -*- coding: iso-8859-15 -*-

3
import Tkinter as tk
4
5
from numpy import arange, math
from PTE import *
6
7

Frms = list()
8
Ldict = list()
9
10
11
12
13
Laycount = 0

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

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
class Layer:
    global Ldict

    def self_destruct():
        return 0

    def elem_select(i):
        return 0

    def addel(self):
        i = int(self.Ecount)
        self.Elements[i]=dict(name="New",symbol="Hf",mass=178.,Z=72,LineShape=200.,profundidademax=10.)
        self.Ebuttons.insert(i, tk.Button(self.Frames[6], text=i, command = lambda i=i : elem_select(i) ))
        self.Ebuttons[i].grid(column=0, row=i)
        self.Spinboxes.insert(i, tk.Spinbox(self.Frames[7], from_=0, to=1, increment=0.05, bd=5 ))
        self.Spinboxes[i].grid(column=0, row=i)
        self.Ecount = self.Ecount + 1

    def rmvel(self):
        return 0

    def __init__(self, canvas, count):
        self.Number=count
        self.Ecount=0
        self.Elements=dict()
        self.Ebuttons=list()
        self.Spinboxes=list()
        self.Frames=list()
        self.LandE=list()
        self.Buttons=list()
        self.LabelFrm = tk.LabelFrame(canvas, text = 'Layer %d' %int(Laycount+1), relief='raised', bd=2)
        self.LabelFrm.grid(column=(Laycount%4), row=int(math.floor(Laycount/4)) )

        for i in range(2):
            self.Frames.insert(i, tk.Frame(self.LabelFrm))
        for i in arange(2,4):
            self.Frames.insert(i, tk.Frame(self.Frames[0]))
        for i in arange(4,6):
            self.Frames.insert(i, tk.Frame(self.Frames[2]))
        for i in arange(6,8):
            self.Frames.insert(i, tk.Frame(self.Frames[1]))

        self.Frames[0].pack(side='top')
        self.Frames[1].pack(side='bottom')
        self.Frames[2].pack(side='left')
        self.Frames[3].pack(side='right')
        self.Frames[4].pack(side='left')
        self.Frames[5].pack(side='right')
        self.Frames[6].pack(side='left')
        self.Frames[7].pack(side='right')

        self.LandE.insert(0, tk.Label(self.Frames[4], width=14, pady=2, text='dƐ/dx') )
        self.LandE.insert(1, tk.Label(self.Frames[4], width=14, pady=2, text='dω²/dx') )

        for i in arange(2,4):
            self.LandE.insert(i, tk.Entry(self.Frames[5], width=11) )

        for i in range(4):
            self.LandE[i].pack()

        self.Buttons.insert(0, tk.Button(self.Frames[4], command=lambda i=i :Ldict[self.Number].addel(), text='Add element',width=11))
        self.Buttons.insert(1, tk.Button(self.Frames[5], command=lambda i=i :Ldict[self.Number].rmvel(), text='Remove element',width=11))
        for i in range(2):
            self.Buttons[i].pack()

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

def addlay(Laycanvas):
    global Laycount, Ldict
    Ldict.insert(Laycount, Layer(Laycanvas, Laycount))
    Laycount = Laycount + 1

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

def rmvlay():
    global Laycount, Ldict
    if Laycount > 0:
        Ldict[Laycount].self_destruct()
        Laycount = Laycount - 1

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

98
def layers():
99
100
101
    global Laycount, Ldict
    Laycount = 0

102
103
    laywin = tk.Tk()
    laywin.title('Layers')
104
105
    laywin.minsize(400,400)
    laywin.geometry('400x400+200+400')
106
107
108
109
110
111

    for i in range(2):
        Frms.insert(i, tk.Frame(laywin))

    Frms[0].pack(side='top')
    Frms[1].pack(side='bottom')
112
113
    Laycanvas = tk.Canvas(Frms[1])
    Laycanvas.pack(fill='both',expand=0)
114

115
    butadd = tk.Button(Frms[0], command=lambda i=i :addlay(Laycanvas), text='Add layer', bd=1, height=1,width=10, pady='4')
116
    butadd.pack(side='left')
117
    butrmv = tk.Button(Frms[0], command=lambda i=i :rmvlay, text='Remove layer', bd=1, height=1,width=10, pady='4')
118
119
120
121
122
    butrmv.pack(side='left')

    laywin.mainloop()

##############################################################################
123
##############################################################################