-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.py
More file actions
executable file
·260 lines (161 loc) · 6.57 KB
/
GUI.py
File metadata and controls
executable file
·260 lines (161 loc) · 6.57 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#Imports
import tkinter as tk
from tkinter import PhotoImage
import matplotlib.pyplot as plt
from PIL import Image
from PIL import ImageTk
from camera import camera
from control import control
from tkinter import messagebox
#initialise the control class
x = control()
y = camera()
class Demo1():
"""
This class handles the first screen, where the user chooses what to do
"""
def __init__(self, master):
"""
THe init function for the screen class, this populates the screen
with buttons
"""
self.master = master
self.frame = tk.Frame(self.master)
self.button1 = tk.Button(self.frame, text = 'Collect Data', width = 25, command = self.new_window_cd)
self.button1.pack()
self.button2 = tk.Button(self.frame, text = 'Plot The Data', width = 25, command = self.new_window_plot)
self.button2.pack()
self.button3 = tk.Button(self.frame, text = 'export data', width = 25, command = x.export_data)
self.button3.pack()
self.button4 = tk.Button(self.frame, text = 'Is Sample Positive', width = 25, command = self.is_sample_positive)
self.button4.pack()
self.button5 = tk.Button(self.frame, text = 'Self Test', width = 25, command = self.run_self_test)
self.button5.pack()
self.button6 = tk.Button(self.frame, text = 'See Camera Output', width = 25, command = self.new_window_cam)
self.button6.pack()
self.frame.pack()
def new_window_cd(self):
"""
creates the window for saying that the data has completed recording
"""
self.newWindow = tk.Toplevel(self.master)
self.app = DataDone(self.newWindow)
def new_window_plot(self):
"""
creates the window for plotting the data
"""
self.newWindow = tk.Toplevel(self.master)
self.app = plot_data(self.newWindow)
def new_window_cam(self):
"""
creates the window for showing the camera output
"""
self.newWindow = tk.Toplevel(self.master)
self.app = cam_output(self.newWindow)
def run_self_test(self):
"""
runs the self check, aborts the process if the self check fails
"""
result = x.self_check()
if result == False:
print('the self test has failed: aborting')
self.master.destroy()
else:
print('The self check has completed, there were no reported errors')
def is_sample_positive(self):
"""
creates a dialogue box saying if the sample is positive or negative
"""
if x.is_sample_positive() == True:
messagebox.showinfo("Result", "The sample is positive")
else:
messagebox.showinfo("Result", "The sample is not positive")
class DataDone():
"""
window for when the data has finished collecting, will displace a picture
of a dog
"""
def __init__(self, master):
"""
The init method
"""
self.master = master
self.frame = tk.Frame(self.master)
self.label = tk.Label(self.frame, text="The Data Has Collected, here is a dog")
self.label.pack(pady=10,padx=10)
x.record_data(10,0.1)
self.img = ImageTk.PhotoImage(Image.open('dog.jpg'))
self.panel = tk.Label(self.frame, image = self.img)
self.panel.image = self.img
self.panel.pack()
self.quitButton = tk.Button(self.frame, text = 'Quit', width = 25, command = self.close_windows)
self.quitButton.pack()
self.frame.pack()
def close_windows(self):
"""
closes the window
"""
self.master.destroy()
class plot_data():
"""
This class handles displaying the data in the form of a graph. all of the
handling is done in the init method
"""
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master)
data = x.get_raw_data()
if data == []:
self.label = tk.Label(self.frame, text="You Havent Collected Any Data")
self.label.pack(pady=10,padx=10)
self.img = ImageTk.PhotoImage(Image.open('dog2.jpg'))
self.panel = tk.Label(self.frame, image = self.img)
self.panel.image = self.img
self.panel.pack()
else:
self.label = tk.Label(self.frame, text="plot of the data")
self.label.pack(pady=10,padx=10)
data2 = []
for i in data:
data2.append(i[0])
plt.scatter((range(0,len(data2))),data2)
plt.savefig('out', format = 'png')
self.img = ImageTk.PhotoImage(Image.open('out'))
self.panel = tk.Label(self.frame, image = self.img)
self.panel.image = self.img
self.panel.pack()
self.quitButton = tk.Button(self.frame, text = 'Quit', width = 25, command = self.close_windows)
self.quitButton.pack()
self.frame.pack()
def close_windows(self):
self.master.destroy()
class cam_output():
"""
displays the camera output
"""
def __init__(self, master):
"""
The init method
"""
self.master = master
self.frame = tk.Frame(self.master)
self.label = tk.Label(self.frame, text="camera output")
self.label.pack(pady=10,padx=10)
y.get_picture()
self.img = ImageTk.PhotoImage(Image.open('image.jpg'))
self.panel = tk.Label(self.frame, image = self.img)
self.panel.image = self.img
self.panel.pack()
self.quitButton = tk.Button(self.frame, text = 'Quit', width = 25, command = self.close_windows)
self.quitButton.pack()
self.frame.pack()
def close_windows(self):
"""
closes the window
"""
self.master.destroy()
def main():
root = tk.Tk()
app = Demo1(root)
root.mainloop()
main()