wheelsmanx

AI_CAR_GAUGE_REV2

Dec 11th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.74 KB | None | 0 0
  1. #AI CAR GAUGE By Justin S Hagerty
  2. #Date 12/11/2016
  3. #Not Yet Opperational Just Test Files
  4.  
  5.  
  6. from tkinter import *
  7. import time
  8.  
  9. window_w = 800
  10. window_h = 350
  11. numberofbuttons = 7
  12. gaugeaccuracy = 31
  13. buttonnames = ["Display Settings", "Gauge Reset", "Instrument Panel", "Test","Test","Test","Gauges"]
  14. yes=" "
  15.  
  16. def creategauge(inputa):
  17. for i in range(0,gaugeaccuracy):
  18. carstart.inputa.append(yes)
  19. carstart2.inputa.append(yes)
  20.  
  21. class carstart1():
  22. gas = 30
  23. rpm = 30
  24. speed = 30
  25. oiltemp = 30
  26. coolanttemp = 30
  27.  
  28. class carstart2():
  29. gas = 1
  30. rpm = 1
  31. speed = 1
  32. oiltemp = 1
  33. coolanttemp = 1
  34.  
  35.  
  36.  
  37. class car():
  38. gas = 1
  39. rpm = 1
  40. speed = 1
  41. oiltemp = 1
  42. coolanttemp = 1
  43.  
  44. class gauge():
  45. gas = []
  46. gastext = []
  47. speed = []
  48. oiltemp = []
  49. coolanttemp = []
  50. rpm = []
  51. led = []
  52.  
  53. def createdisplay():
  54. global tk, canvas, light
  55. tk = Tk()
  56. canvas = Canvas(tk, width=window_w, height=window_h, background="black")
  57. canvas.pack()
  58. createbuttonbar()
  59. tk.mainloop()
  60.  
  61.  
  62. def createbuttonbar():
  63. creategauge()
  64. buttonlist = []
  65. for i in range(0,numberofbuttons):
  66. buttonlist.append(yes)
  67. buttonlist[0] = Button(tk, text=buttonnames[0], command=displaysettings, bg="blue")
  68. buttonlist[1] = Button(tk, text=buttonnames[1], command=test, bg="blue")
  69. buttonlist[2] = Button(tk, text=buttonnames[2], command=test, bg="blue")
  70. buttonlist[3] = Button(tk, text=buttonnames[3], command=test, bg="blue")
  71. buttonlist[4] = Button(tk, text=buttonnames[4], command=test, bg="blue")
  72. buttonlist[5] = Button(tk, text=buttonnames[5], command=test, bg="blue")
  73. buttonlist[6] = Button(tk, text=buttonnames[6], command=showgauge, bg="blue")
  74. for i in range(0,numberofbuttons):
  75. width = 100
  76. height = 52
  77. x = 0
  78. y = 50 * i
  79. buttonlist[i].place(x=x,y=y,height=height,width=width)
  80.  
  81. def displaysettings():
  82. resetgaugs()
  83. print("display settings")
  84. tk.update()
  85.  
  86.  
  87. def showgauge():
  88. fillcolor="red"
  89. for i in range(0,gaugeaccuracy):
  90. canvas.itemconfig(gauge.gas[i], fill=fillcolor)
  91. canvas.itemconfig(gauge.speed[i], fill=fillcolor)
  92. canvas.itemconfig(gauge.rpm[i], fill=fillcolor)
  93. canvas.itemconfig(gauge.oiltemp[i], fill=fillcolor)
  94. canvas.itemconfig(gauge.coolanttemp[i], fill=fillcolor)
  95. fillcolor="white"
  96. for i in range(0, len(gauge.gastext)):
  97. canvas.itemconfig(gauge.gastext[i], fill=fillcolor)
  98. tk.update()
  99. carstart()
  100.  
  101. def creategauge():
  102. global tk, canvas
  103. gaugefill = ""
  104. textfill = ""
  105. for i in range(0,gaugeaccuracy):
  106. x = 100
  107. y = window_h - 30 - (i * 10)
  108. x1= 150
  109. y1= window_h - 30 - (i * 10 - 5)
  110. b = i*.53
  111. b = round(b, 2)
  112. if i % 10:
  113. x1 = 130
  114. else:
  115. gauge.gastext.append(canvas.create_text(x+70,y, fill=textfill, text=b))
  116. gauge.gas.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
  117. x = 200
  118. y = window_h - 30 - (i * 10)
  119. x1= 250
  120. y1= window_h - 30 - (i * 10 - 5)
  121. b = 5 * i
  122. if i % 2:
  123. x1 = 230
  124. else:
  125. gauge.gastext.append(canvas.create_text(x+65,y, fill=textfill, text=b))
  126. gauge.speed.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
  127. x = 300
  128. y = window_h - 30 - (i * 10)
  129. x1= 350
  130. y1= window_h - 30 - (i * 10 - 5)
  131. b = 250 * i
  132. if i % 2:
  133. x1 = 330
  134. else:
  135. gauge.gastext.append(canvas.create_text(x+70,y, fill=textfill, text=b))
  136. gauge.rpm.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
  137. x = 400
  138. y = window_h - 30 - (i * 10)
  139. x1= 450
  140. y1= window_h - 30 - (i * 10 - 5)
  141. b = 25 * i
  142. if i % 3:
  143. x1 = 430
  144. else:
  145. gauge.gastext.append(canvas.create_text(x+70,y, fill=textfill, text=b))
  146. gauge.coolanttemp.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
  147. x = 500
  148. y = window_h - 30 - (i * 10)
  149. x1= 550
  150. y1= window_h - 30 - (i * 10 - 5)
  151. b = 25 * i
  152. if i % 3:
  153. x1 = 530
  154. else:
  155. gauge.gastext.append(canvas.create_text(x+70,y, fill=textfill, text=b))
  156. gauge.oiltemp.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
  157. x = 600
  158. y = window_h - 30 - (i * 10)
  159. x1= 610
  160. y1= window_h - 30 - (i * 10 - 5)
  161. if i % 5:
  162. x1 = 600
  163. else:
  164. gauge.gastext.append(canvas.create_text(x+25,y, fill=textfill, text="test"))
  165. gauge.led.append(canvas.create_rectangle(x,y,x1,y1, fill=gaugefill))
  166.  
  167. y = window_h - 10
  168. x = 115
  169. gauge.gastext.append(canvas.create_text(x,y, fill=textfill, text="Gas"))
  170. gauge.gastext.append(canvas.create_text(x+100,y, fill=textfill, text="Speed"))
  171. gauge.gastext.append(canvas.create_text(x+200,y, fill=textfill, text="Rpm"))
  172. gauge.gastext.append(canvas.create_text(x+320,y, fill=textfill, text="Coolant Temp"))
  173. gauge.gastext.append(canvas.create_text(x+400,y, fill=textfill, text="Oil Temp"))
  174. tk.update()
  175.  
  176.  
  177. def carstart():
  178. for i in range(0, gaugeaccuracy):
  179. time.sleep(.05)
  180. if i < carstart1.gas :
  181. canvas.itemconfig(gauge.gas[i], fill="white")
  182. if i < carstart1.speed :
  183. canvas.itemconfig(gauge.speed[i], fill="white")
  184. if i < carstart1.rpm :
  185. canvas.itemconfig(gauge.rpm[i], fill="white")
  186. if i < carstart1.oiltemp :
  187. canvas.itemconfig(gauge.oiltemp[i], fill="white")
  188. if i < carstart1.coolanttemp :
  189. canvas.itemconfig(gauge.coolanttemp[i], fill="white")
  190. tk.update()
  191. resetgauge()
  192. time.sleep(.15)
  193. i = 0
  194. for i in range(0, gaugeaccuracy):
  195. time.sleep(.05)
  196. if i < carstart2.gas :
  197. canvas.itemconfig(gauge.gas[i], fill="white")
  198. if i < carstart2.speed :
  199. canvas.itemconfig(gauge.speed[i], fill="white")
  200. if i < carstart2.rpm :
  201. canvas.itemconfig(gauge.rpm[i], fill="white")
  202. if i < carstart2.oiltemp :
  203. canvas.itemconfig(gauge.oiltemp[i], fill="white")
  204. if i < carstart2.coolanttemp :
  205. canvas.itemconfig(gauge.coolanttemp[i], fill="white")
  206. tk.update()
  207.  
  208. def resetgauge():
  209. for i in range(0, gaugeaccuracy):
  210. time.sleep(.05)
  211. if i < carstart1.gas :
  212. canvas.itemconfig(gauge.gas[i], fill="red")
  213. if i < carstart1.speed :
  214. canvas.itemconfig(gauge.speed[i], fill="red")
  215. if i < carstart1.rpm :
  216. canvas.itemconfig(gauge.rpm[i], fill="red")
  217. if i < carstart1.oiltemp :
  218. canvas.itemconfig(gauge.oiltemp[i], fill="red")
  219. if i < carstart1.coolanttemp :
  220. canvas.itemconfig(gauge.coolanttemp[i], fill="red")
  221. tk.update()
  222.  
  223.  
  224. def update():
  225. for i in range(0, gaugeaccuracy):
  226. time.sleep(.012)
  227. if i < car.gas :
  228. canvas.itemconfig(gauge.gas[i], fill="white")
  229. if i < car.speed :
  230. canvas.itemconfig(gauge.speed[i], fill="white")
  231. if i < car.rpm :
  232. canvas.itemconfig(gauge.rpm[i], fill="white")
  233. if i < car.oiltemp :
  234. canvas.itemconfig(gauge.oiltemp[i], fill="white")
  235. if i < car.coolanttemp :
  236. canvas.itemconfig(gauge.coolanttemp[i], fill="white")
  237. tk.update()
  238.  
  239. def test():
  240. print("test")
  241.  
  242.  
  243. def terminate():
  244. global tk
  245. tk.destroy()
  246.  
  247. def main():
  248. createdisplay()
  249.  
  250.  
  251. main()
Advertisement
Add Comment
Please, Sign In to add comment