-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.py
256 lines (223 loc) · 6.65 KB
/
graphics.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
from tkinter import *
import sys
import time
from ping import Ping
enable=False
def callback():
global enable
print(enable)
if(enable):
for x in range(0,4):
distance=sensors[x].distance()
setLines(x,distance)
w.itemconfigure("s%d"%(x+1),text="%-8d cm" % round(distance))
Gui.after(500,callback)
"""d1=round(sensor1.distance())
setLines(0,d1)
w.itemconfigure("s1",text="%-8d cm" % round(d1))
print("S1 called the callback!")
w.itemconfigure("s2",text="%-8d cm" % round(sensor2.distance()))
print("S2 called the callback!")
w.itemconfigure("s3",text="%-8d cm" % round(sensor3.distance()))
print("S3 called the callback!")
w.itemconfigure("s4",text="%-8d cm" % round(sensor4.distance()))
print("S4 called the callback!")"""
def stop():
global enable
enable=False
print("Stop"+str(enable))
for x in range(0,4):
setLines(x,0)
def start():
global enable
enable=True
print("Start"+str(enable))
#define function for 1 sensor set up
def Sensor1():
#delete print in final code
print("1 sensor")
#define function for 2 sensor set up
def Sensor2():
#delete print in final code
print("2 sensors")
#define function for 3 sensor set up
def Sensor3():
#delete print in final code
print("3 sensors")
#define function for 4 sensor set up
def Sensor4():
#delete print in final code
print("4 sensors")
#draw the circle that indicates the sensor
#w.create_
#call gridlayout
GridLayout()
#define the dislog box for exit confirmation
def Exit():
result = messagebox.askyesno("Warning", "Do you wish to exit the system?")
if result == True:
exit()
#define function to draw grid
def GridLayout():
x = 10
for i in range(60, 10):
w.create_line(0,x, 600,x)
x +=10
def setLines(sensor,distance):
#tk.NORMAL
#w.item.configure("",state=tk.HIDDEN)
if distance <= 50:
line=0
elif(distance>50 and distance<=100):
line=1
elif(distance>100 and distance<=150):
line=2
elif(distance>150 and distance<=200):
line=3
elif(distance>200 and distance<=250):
line=4
elif(distance>250 and distance<=300):
line=5
elif(distance>300 and distance<=350):
line=6
elif(distance>350):
line=7
for x in range(0,8,1):
if(x<=line):
w.itemconfigure("line%d%d"%(sensor,x),state=NORMAL)
else:
w.itemconfigure("line%d%d"%(sensor,x),state=HIDDEN)
def drawSensorLine():
colors=["RED","YELLOW","BLUE","BLUE","BLUE","GREEN","GREEN","GREEN"]
x = 200
y1 = 110
y2 = 130
distances = [200,300,400,500,600,700,800,900]
for sensor in range(0,4,1):
for line in range(0,8,1):
w.create_line(distances[line],y1-10*line,distances[line],y2+10*line,fill=colors[line],width=3,tags="line%d%d"%(sensor,line))
y1+=150
y2+=150
#create the main gui window
Gui = Tk()
Gui.geometry('1000x800')
Gui.title("Ultrasonic Sensor Ping Representation")
# create a menu for main window
menu = Menu(Gui)
Gui.config(menu=menu)
#file menu
FileM = Menu(menu)
menu.add_cascade(label="File", menu=FileM)
FileM.add_command(label="Exit", command=Exit)
#sensor menu
SensorM = Menu(menu)
menu.add_cascade(label="Sensors", menu=SensorM)
SensorM.add_command(label="One Sensor", command=Sensor1)
SensorM.add_command(label="Two Sensors", command=Sensor2)
SensorM.add_command(label="Three Sensors", command=Sensor3)
SensorM.add_command(label="Four Sensors", command=Sensor4)
#help menu
HelpM = Menu(menu)
menu.add_cascade(label="Help", menu=HelpM)
HelpM.add_command(label = "Help", command = callback)
HelpM.add_command(label="About", command=callback)
#create start button
S = Button(Gui, text="Start", justify=CENTER, command=start)
S.config(height=2, width=10)
S.pack()
S = Button(Gui, text="Stop", justify=CENTER, command=stop)
S.config(height=2, width=10)
S.pack()
#create the canvas to draw on
w = Canvas(Gui, width=1000, height=700)
w.pack()
#Sensor 1 labels
w.create_text(35,50,text="Sensor 1: ")
w.pack()
w.create_text(120,50,text="testing",tag="s1")
w.pack()
w.create_line(70,90,70,150)
w.create_line(40,120,100,120)
#Sensor 2 labels
w.create_text(35,200,text="Sensor 2: ")
w.pack()
w.create_text(120,200,text="testing",tag="s2")
w.pack()
w.create_line(70,240,70,300)
w.create_line(40,270,100,270)
#Sensor 3 labels
w.create_text(35,350,text="Sensor 3: ")
w.pack()
w.create_text(120,350,text="testing",tag="s3")
w.pack()
w.create_line(70,390,70,450)
w.create_line(40,420,100,420)
#Sensor 4 labels
w.create_text(35,500,text="Sensor 4: ")
w.pack()
w.create_text(120,500,text="testing",tag="s4")
w.pack()
w.create_line(70,540,70,600)
w.create_line(40,570,100,570)
"""
sensor1 = Ping(17, 21)
sensor2 = Ping(18, 22)
sensor3 = Ping(19, 23)
sensor4 = Ping(20, 24)"""
sensors = [Ping(17, 21),Ping(18, 22),Ping(19, 23),Ping(20, 24)]
colors=["RED","YELLOW","BLUE","BLUE","BLUE","GREEN","GREEN","GREEN"]
x = 200
y1 = 110
y2 = 130
distances = [200,300,400,500,600,700,800,900]#range(200,900,100)
"""for x in range(200,900,100):
# w.create_line(x, y1, x, y2,fill=colors[3])
# y1-=10
# y2+=10
distance1=sensor1.distance()
print(distance1)
print(distances)
distance1=sensor1.distance()
if distance1 <= 50:
w.create_line(distances[0],y1,distances[0],y2,fill=colors[0])
elif(distance1>50 and distance1<=100):
y1-=10
y2+=10
w.create_line(distances[1],y1,distances[1],y2,fill=colors[1])
elif(distance1>100 and distance1<=150):
w.create_line(distances[1],y1,distances[1],y2,fill=colors[2])
y1-=10
y2+=10
w.create_line(distances[2],y1,distances[2],y2,fill=colors[2])
elif(distance1>150 and distance1<=200):
w.create_line(distances[1],y1,distances[1],y2,fill=colors[3])
y1-=10
y2+=10
w.create_line(distances[2],y1,distances[2],y2,fill=colors[3])
y1-=10
y2+=10
w.create_line(distances[3],y1,distances[3],y2,fill=colors[3])
elif(distance1>200 and distance1<=250):
w.create_line(distances[4],y1,distances[4],y2,fill=colors[4])
y1-=10
y2+=10
elif(distance1>250 and distance1<=300):
w.create_line(distances[5],y1,distances[5],y2,fill=colors[5])
y1-=10
y2+=10
elif(distance1>300 and distance1<=350):
w.create_line(distances[6],y1,distances[6],y2,fill=colors[6])
y1-=10
y2+=10
elif(distance1>350):
print("7")
w.create_line(distances[7],y1,distances[7],y2,fill=colors[7])
y1-=10
y2+=10
"""
#draw arc
#w.create_arc(start = 362.5, extent = 15, style = ARC, )
drawSensorLine()
#Gui.after(1,callback)
callback()
Gui.mainloop()