-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
236 lines (202 loc) · 8.04 KB
/
GUI.py
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
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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# -*- coding: utf-8 -*-
"""
Antenna Visualizer
Created on Thu Feb 27 18:05:13 2020
Description: A GUI based antenna simulator. Tweak sliders to adjust antenna parameters such as length, array patterns, and excitation phasing.
Authors:
Jordan Baxter
Chelsea Starr
"""
import tkinter as tk
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
# Implement the default Matplotlib key bindings.
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import plots
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
master.title("GUI Based Antenna Simulation")
self.pack()
self.create_frames()
self.create_widgets()
def create_frames(self):
self.p_frame = tk.Frame(self.master)
self.p_frame.pack(side = 'left')
self.w_frame = tk.Frame(self.master)
self.w_frame.pack(side = 'right')
self.plots = plots.Plots(figsize=(11,9), dpi=75)
self.canvas = FigureCanvasTkAgg(self.plots, master=self.p_frame)
self.canvas.draw()
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
def create_widgets(self):
### DROPDOWN OPTIONS MENU ###
self.simType = tk.StringVar()
self.simType.set("Single Dipole")
self.simTypeMenu = tk.OptionMenu(self.w_frame,
self.simType,
"Single Dipole",
"Antenna Array",
command=self.updateControls)
self.simTypeMenu.grid(row=0,
column=1,
columnspan=2)
tk.Label(self.w_frame, text="Simulation Type").grid(row=0, column=0)
### DROPDOWN OPTIONS MENU ###
### DELTA PHI SLIDER ###
self.dp_sc = tk.Scale(self.w_frame,
from_=-180,
to=180,
resolution=10,
length=300,
orient='horizontal',
tickinterval=20,
command=self.upDPhi,
label="Excitation Phasing [deg]")
### /DELTA PHI SLIDER ###
### D SLIDER ###
self.d_sc = tk.Scale(self.w_frame,
from_=0,
to=2,
resolution=0.01,
length=300,
orient='horizontal',
tickinterval=0.25,
command=self.upD,
label="Distance Between Elements [d / \u03bb]")
### /D SLIDER ###
### L SLIDER ###
self.l_sc = tk.Scale(self.w_frame,
from_=0,
to=1.75,
resolution=0.01,
length=300,
orient='horizontal',
tickinterval=0.25,
command=self.upL,
label="Length of Dipole [l / \u03bb]")
self.l_sc.grid(row=2,
columnspan=3)
### /L SLIDER ###
### NUMBER OF ELEMENTS SLIDER ###
self.ne_sc = tk.Scale(self.w_frame,
from_=2,
to=20,
resolution=1,
length=300,
orient='horizontal',
tickinterval=2,
command=self.upNumEle,
label="Number of Elements")
### /NUMBER OF ELEMENTS SLIDER ###
### INSERT DIPOLE CHECKBOX ###
self.insDipVar = tk.IntVar()
self.insDipVar.set(1)
self.noDip = tk.Radiobutton(self.w_frame,text="No Dipole", variable=self.insDipVar, value=1, command=self.insDip)
self.coLin = tk.Radiobutton(self.w_frame, text="Colinear Array", variable=self.insDipVar, value=2, command=self.insDip)
self.perp = tk.Radiobutton(self.w_frame, text="Perpendicular Array", variable=self.insDipVar, value=3, command=self.insDip)
### /INSERT DIPOLE CHECKBOX ###
### Toggle 3D Button ###
self.button3D = tk.Button(self.w_frame,
text="Show 3D Plot", fg="green",
command=self.up3D)
self.button3D.grid(row=1,
column=1,
columnspan=2)
### QUIT BUTTON ###
self.quit = tk.Button(self.master, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")
def upNumEle(self, slidevalue):
self.plots.setNumEle(slidevalue)
self.canvas.draw()
def upDPhi(self, slidevalue):
self.plots.setDPhi(slidevalue)
self.canvas.draw()
def upD(self, slidevalue):
if (float(slidevalue) == 0):
newVal = 0.0001
else:
newVal = slidevalue
self.plots.setD(newVal)
self.canvas.draw()
def upL(self, slidevalue):
if (float(slidevalue) == 0):
newVal = 0.0001
else:
newVal = slidevalue
self.plots.setL(newVal)
self.canvas.draw()
def up3D(self):
if (self.plots.toggle3D() == True):
self.toggleWidgets("off")
else:
self.toggleWidgets("on")
self.canvas.draw()
def insDip(self):
arrType = self.insDipVar.get()
if(arrType == 1):
self.l_sc.grid_forget()
self.plots.setArrType("NoDip")
elif(arrType == 2):
self.l_sc.grid(row=6,
columnspan=3)
self.plots.setArrType("ColArray")
elif(arrType == 3):
self.l_sc.grid(row=6,
columnspan=3)
self.plots.setArrType("PerpArray")
self.canvas.draw()
def updateControls(self, value):
simType = self.simType.get()
if(simType == "Single Dipole"):
self.dp_sc.grid_forget()
self.d_sc.grid_forget()
self.ne_sc.grid_forget()
self.noDip.grid_forget()
self.coLin.grid_forget()
self.perp.grid_forget()
self.insDipVar.set(1)
self.l_sc.grid(row=2,
columnspan=3)
elif(simType == "Antenna Array"):
self.l_sc.grid_forget()
self.d_sc.grid(row=2,
columnspan=3)
self.dp_sc.grid(row=3,
columnspan=3)
self.ne_sc.grid(row=4,
columnspan=3)
self.noDip.grid(row=5,
column=0)
self.coLin.grid(row=5,
column=1)
self.perp.grid(row=5,
column=2)
self.plots.setSimType(simType)
self.canvas.draw()
def toggleWidgets(self,onOff='on'):
if(onOff == "off"):
self.dp_sc.configure(state='disabled')
self.d_sc.configure(state='disabled')
self.noDip.configure(state='disabled')
self.coLin.configure(state='disabled')
self.perp.configure(state='disabled')
self.l_sc.configure(state='disabled')
self.simTypeMenu.configure(state='disabled')
else:
self.dp_sc.configure(state='normal')
self.d_sc.configure(state='normal')
self.noDip.configure(state='normal')
self.coLin.configure(state='normal')
self.perp.configure(state='normal')
self.l_sc.configure(state='normal')
self.simTypeMenu.configure(state='normal')
### Constuct Figures ###
root = tk.Tk()
app = Application(master=root)
app.mainloop()