/
LaunchGUI.py
189 lines (141 loc) · 7.03 KB
/
LaunchGUI.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
import tkinter as tk
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk#Agg
from matplotlib.figure import Figure
LARGE_FONT = ("Verdana", 12)
class Tonyapp(tk.Tk):
def __init__(self, active_traps, maxima, pulse_widths, current, voltage, starts, ends, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, CustomPage, GraphPage):
frame = F(container, self, active_traps, maxima, pulse_widths, current, voltage, starts, ends)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky='nsew')
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller, active_traps, maxima, pulse_widths, current, voltage, starts, ends):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text='Start Page', font=LARGE_FONT)
label.pack(pady=10,padx=10)
# NAVIGATION BUTTONS
graph_button = tk.Button(self, text="Compare All Pulses",
command = lambda: controller.show_frame(GraphPage))
graph_button.pack()
custom_button = tk.Button(self, text="Compare Select Pulses",
command = lambda: controller.show_frame(CustomPage))
custom_button.pack()
f = Figure(figsize=(10,6))#, dpi=100)
gs = f.add_gridspec(3, 2)
a = f.add_subplot(gs[0, 0])
a.scatter(active_traps,maxima)
a.set_title('Peak Current vs Trap Number')
a.set_xlabel('Trap Number')
a.set_ylabel('Peak Curennt (A)')
a.set_ylim([0,1.1*max(maxima)]) #1.1 for visibility
b = f.add_subplot(gs[0,1])
b.scatter(active_traps,pulse_widths+[0]*(len(active_traps)-len(pulse_widths)))
b.set_title('Pulse Width vs Trap Number')
b.set_xlabel('Trap Number')
b.set_ylabel('Pulse Width (s)')
b.set_ylim([0,1.1*max(pulse_widths)]) #1.1 for visibility
c = f.add_subplot(gs[1,:])
c.scatter(current['Time (s)'].apply(lambda x: x*1000*1000).to_list(),current['Current (A)'].to_list())
c.set_title('Current vs Time')
c.set_xlabel('Time (us)')
c.set_ylabel('Current (A)')
d = f.add_subplot(gs[2,:])
d.scatter(voltage['Time (s)'].apply(lambda x: x*1000*1000).to_list(),voltage['Voltage (V)'].to_list())
d.set_title('Voltage vs Time')
d.set_xlabel('Time (us)')
d.set_ylabel('Voltage (V)')
f.tight_layout()
canvas = FigureCanvasTkAgg(f, self)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2Tk(canvas, self)
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
class GraphPage(tk.Frame):
def __init__(self, parent, controller, active_traps, maxima, pulse_widths, current, voltage, starts, ends):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text='Graph Page', font=LARGE_FONT)
label.pack(pady=10, padx=10)
# NAVIGATION BUTTONS
home_button = tk.Button(self, text="Back to Home",
command = lambda: controller.show_frame(StartPage))
home_button.pack()
custom_button = tk.Button(self, text="Compare Select Pulses",
command = lambda: controller.show_frame(CustomPage))
custom_button.pack()
f = Figure(figsize=(5,5))#, dpi=100)
a = f.add_subplot(111)
for start, end in zip(starts, ends):
mod_start, mod_end = 0, end -start
a.scatter(current['Time (s)'].to_list()[mod_start:mod_end], current['Current (A)'].to_list()[start:end])
#a.scatter(current['Time (s)'].to_list()[start:end], current['Current (A)'].to_list()[start:end])
a.set_title('Current vs Time')
a.set_xlabel('Time (s)')
a.set_ylabel('Current (A)')
canvas = FigureCanvasTkAgg(f, self)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2Tk(canvas, self)
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
class CustomPage(tk.Frame):
def __init__(self, parent, controller, active_traps, maxima, pulse_widths, current, voltage, starts, ends):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text='Choose Which Pulses to Compare', font=LARGE_FONT)
label.pack(pady=10, padx=10)
# NAVIGATION BUTTONS
home_button = tk.Button(self, text="Back to Home",
command = lambda: controller.show_frame(StartPage))
home_button.pack()
graph_button = tk.Button(self, text="Compare All Pulses",
command = lambda: controller.show_frame(GraphPage))
graph_button.pack()
# LIST BOX
listbox = tk.Listbox(self, selectmode=tk.MULTIPLE)
tk.Label(self, text="Choose a trap").pack()
listbox.pack()
for x,item in enumerate(active_traps):
listbox.insert(x, item)
#PLOT GRAPH
def plot_graph():
selected = listbox.curselection()
selected_traps = [active_traps[x] for x in selected]
selected_starts = [starts[x] for x in selected]
selected_ends = [ends[x] for x in selected]
f = Figure(figsize=(3,3))#, dpi=100)
a = f.add_subplot(111)
for start, end in zip(selected_starts, selected_ends):
mod_start, mod_end = 0, end -start
a.scatter(current['Time (s)'].to_list()[mod_start:mod_end], current['Current (A)'].to_list()[start:end])
a.legend(selected_traps)
a.set_xlabel('Time (s)')
a.set_ylabel('Current (A)')
f.tight_layout()
#a.scatter(current['Time (s)'].to_list()[start:end], current['Current (A)'].to_list()[start:end])
def clear_graph():
canvas._tkcanvas.pack_forget()
canvas.get_tk_widget().pack_forget()
toolbar.pack_forget()
b.pack_forget()
b = tk.Button(self, text="Clear Graph", command=clear_graph)
b.pack()
canvas = FigureCanvasTkAgg(f, self)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2Tk(canvas, self)
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
plot_button = tk.Button(self, text="Plot Graph", command = plot_graph)
plot_button.pack()