InterfaceL.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. from idlelib.colorizer import color_config
  2. from logging import disable
  3. from tkinter import Tk, Label, Entry, Button, Spinbox, StringVar, BOTTOM, LEFT, SOLID, EW, END
  4. from tkinter import ttk
  5. from tkinter import filedialog
  6. from tkinter.ttk import Combobox
  7. from matplotlib.figure import Figure
  8. from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  9. from matplotlib.backends._backend_tk import NavigationToolbar2Tk
  10. from random import choice
  11. import matplotlib.pyplot as plt
  12. import matplotlib
  13. import matplotlib.animation as animation
  14. import numpy as np
  15. import time
  16. import os
  17. from matplotlib.animation import FuncAnimation
  18. import tkinter as tk
  19. class Interface():
  20. window = Tk()
  21. def __init__(self):
  22. pass
  23. def create_widgets_S(self):
  24. Interface.window.title("project_gamma_new_2vi")
  25. Interface.window.geometry('500x250+100+100')
  26. photo = tk.PhotoImage(file='iconka.png')
  27. Interface.window.iconphoto(False, photo)
  28. self.f_top = ttk.LabelFrame(Interface.window, text="Виртуальный COM порт", relief=SOLID, padding=(8, 10))
  29. self.combo = Combobox(self.f_top)
  30. self.combo['values'] = (1, 2, 3, 4, 5)
  31. self.combo.current(4)
  32. self.f_top.grid(column=0, row=0)
  33. self.combo.pack(side=BOTTOM)
  34. self.f_file = ttk.LabelFrame(Interface.window, text="Выбрать файл txt для записи", relief=SOLID,
  35. padding=(8, 10))
  36. self.f_file.grid(column=1, row=0)
  37. self.txt = Entry(self.f_file, width=40)
  38. self.txt.pack(side=LEFT)
  39. self.btn = Button(self.f_file, height=1, text='Файл', bg="gray", fg="red", command=self.clicked_file)
  40. self.btn.pack(side=LEFT)
  41. self.f_start = ttk.Frame(Interface.window, relief=SOLID, padding=(8, 10))
  42. self.t1 = Label(self.f_start, text="Состояние работы", fg="black")
  43. self.t2 = Label(self.f_start, text="Начать сбор данных", fg="black")
  44. self.t3 = Label(self.f_start, text="Остановить сбор данных", fg="black")
  45. self.t4 = Label(self.f_start, text="Выключено", fg="white", bg="black")
  46. self.button_start = Button(self.f_start, text="Пуск", bg="lightgray", fg="black", command=self.clicked_start1)
  47. self.button_startoff = Button(self.f_start, text="Стоп", bg="lightgray", fg="red",
  48. command=self.clicked_start2,
  49. state='disabled')
  50. self.f_start1 = ttk.LabelFrame(Interface.window, text='Принятые символы', relief=SOLID, padding=(8, 10))
  51. self.t_entry = Entry(self.f_start1, width=40, state=['disable'])
  52. self.f_start.grid(column=2, row=0)
  53. self.f_start1.grid(column=3, row=0)
  54. self.t1.grid(column=0, row=0)
  55. self.t2.grid(column=1, row=0)
  56. self.t3.grid(column=2, row=0)
  57. self.t4.grid(column=0, row=1)
  58. self.t_entry.grid(column=0, row=1)
  59. self.button_start.grid(column=1, row=1)
  60. self.button_startoff.grid(column=2, row=1)
  61. def create_widgets_W(self):
  62. self.f_W = ttk.Frame(Interface.window, relief=SOLID, padding=(8, 10))
  63. self.f_W.grid(column=0, row=1)
  64. self.tspin1 = Label(self.f_W, text="Время экспозиции, с", fg="black")
  65. self.tspin2 = Label(self.f_W, text="Макс. время сбора данных, с", fg="black")
  66. self.tspin3 = Label(self.f_W, text="Прошло времени, с", fg="black")
  67. self.spin1 = Spinbox(self.f_W, from_=0, to=100, width=7)
  68. self.spin2 = Spinbox(self.f_W, from_=0, to=10000000, increment=500, width=11)
  69. self.t_entry = Entry(self.f_W, width=20, state='disabled')
  70. self.tspin1.grid(column=0, row=0, ipadx=10)
  71. self.spin1.grid(column=0, row=1, pady=10)
  72. self.tspin2.grid(column=0, row=2, ipadx=10)
  73. self.spin2.grid(column=0, row=3, pady=10)
  74. self.tspin3.grid(column=0, row=4, pady=10)
  75. self.t_entry.grid(column=0, row=5)
  76. self.f_W1 = ttk.Frame(Interface.window, relief=SOLID, padding=(8, 10))
  77. self.f_W1.grid(column=0, row=2)
  78. self.tspin_0 = Label(self.f_W1, text="Коэффициент делителя", fg="black")
  79. self.spin_0 = Spinbox(self.f_W1, from_=0, to=100, width=7)
  80. self.tspin_0.grid(column=0, row=0, ipadx=10)
  81. self.spin_0.grid(column=0, row=1, pady=10)
  82. self.f_W2 = ttk.Frame(Interface.window, relief=SOLID, padding=(8, 10))
  83. self.f_W2.grid(column=0, row=3)
  84. self.spin1_zap = Spinbox(self.f_W2, from_=0.0, to=50.0, increment=0.1, width=6)
  85. self.spin2_zap = Spinbox(self.f_W2, from_=0, to=100, increment=1, width=6)
  86. self.spin3_zap = Spinbox(self.f_W2, from_=0, to=500, width=6)
  87. self.spin4_zap = Spinbox(self.f_W2, from_=0, to=500, width=6)
  88. self.tspin1_zap = Label(self.f_W2, text="ЦАП канал 1.0...3.29В", fg="black")
  89. self.tspin2_zap = Label(self.f_W2, text="ЦАП канал 2.0...3.29В", fg="black")
  90. self.tspin3_zap = Label(self.f_W2, text="ЦАП канал 3.1...256", fg="black")
  91. self.tspin4_zap = Label(self.f_W2, text="ЦАП канал 4.1...256", fg="black")
  92. self.tbut1_zap = Label(self.f_W2, text='''Обновить значение
  93. каналов DAC''', fg="black")
  94. self.tbut2_zap = Label(self.f_W2, text='''Прочесть текущее
  95. значение каналов DAC''', fg="black")
  96. self.button1_zap = Button(self.f_W2, text="Обновить", bg="lightgray", fg="black")
  97. self.button2_zap = Button(self.f_W2, text="Прочесть", bg="lightgray", fg="black")
  98. self.tspin1_zap.grid(column=0, row=0, ipadx=10)
  99. self.spin1_zap.grid(column=0, row=1, pady=10)
  100. self.tspin2_zap.grid(column=0, row=2, ipadx=10)
  101. self.spin2_zap.grid(column=0, row=3, pady=10)
  102. self.tspin3_zap.grid(column=0, row=4, ipadx=10)
  103. self.spin3_zap.grid(column=0, row=5, pady=10)
  104. self.tspin4_zap.grid(column=0, row=6, ipadx=10)
  105. self.spin4_zap.grid(column=0, row=7, pady=10)
  106. self.tbut1_zap.grid(column=0, row=8)
  107. self.button1_zap.grid(column=0, row=9)
  108. self.tbut2_zap.grid(column=0, row=10)
  109. self.button2_zap.grid(column=0, row=11)
  110. self.f_W3 = ttk.Frame(Interface.window, relief=SOLID, padding=(8, 10))
  111. self.txt0_fw3 = Label(self.f_W3, text="Порт В1 напряжения", fg="black")
  112. self.txt1_fw3 = Label(self.f_W3, text=" 0 B ", fg="black", bg="pink")
  113. self.m = ' 0 B '
  114. self.txt2_fw3 = Label(self.f_W3, text='''Выбор напряжения:
  115. 0 В 3.3B''')
  116. self.but_fw3 = Button(self.f_W3, text='<---', command=self.clicked_V)
  117. self.f_W3.grid(column=0, row=4)
  118. self.txt0_fw3.grid(column=0, row=0)
  119. self.txt1_fw3.grid(column=0, row=1, pady=10)
  120. self.txt2_fw3.grid(column=0, row=2)
  121. self.but_fw3.grid(column=0, row=3)
  122. def create_Figure(self):
  123. self.file1 = open('coordinates.txt', 'r')
  124. with self.file1 as f:
  125. self.lines = f.readlines()
  126. self.data = [line.strip().split() for line in self.lines]
  127. self.xdata, self.ydata = zip(*[(float(x), float(y)) for x, y in self.data])
  128. self.f_graf = ttk.LabelFrame(Interface.window,
  129. text='Количество импульсов в минуту', relief=SOLID)
  130. self.f_graf.grid(column=1, row=1, columnspan=2, rowspan=2)
  131. self.fig = Figure(figsize=(7, 4), dpi=80)
  132. self.ax = self.fig.add_subplot(111)
  133. self.ax.set_xlabel('Время, с')
  134. self.ax.set_ylabel('Импульсы')
  135. self.ax.grid(color='black', linewidth=1.0)
  136. self.ax.set_xlim(0, 3000)
  137. self.ax.set_ylim(0, 10000)
  138. self.canvas = FigureCanvasTkAgg(self.fig, master=self.f_graf)
  139. self.canvas.draw()
  140. self.canvas.get_tk_widget().grid(column=0, row=0)
  141. self.line, = self.ax.plot([], [], 'ro-')
  142. def init():
  143. self.line.set_data([], [])
  144. return self.line,
  145. def update(frame):
  146. self.line.set_data(self.xdata[:frame], self.ydata[:frame])
  147. return self.line,
  148. self.ani = FuncAnimation(self.fig, update, frames=len(self.xdata),
  149. init_func=init, blit=True, interval=5, repeat=False)
  150. Interface.window.after(100, lambda: None)
  151. self.f_grafbtn = ttk.LabelFrame(self.f_graf, text='Время отоброжения', padding=(8, 10))
  152. self.f_grafbtn.grid(column=1, row=0)
  153. self.tgrafsp = Label(self.f_grafbtn, text="Начало времени, с", fg="black")
  154. self.tgrafsp.grid(column=0, row=0)
  155. self.grafspin = Spinbox(self.f_grafbtn, from_=0, to=1000, increment=100, width=7)
  156. self.grafspin.grid(column=0, row=1)
  157. self.t1grafbtn = Label(self.f_grafbtn, text="Выбор конца времени", fg="black")
  158. self.t1grafbtn.grid(column=0, row=2)
  159. self.button_time1 = Button(self.f_grafbtn, text="Текущее время",
  160. bg="lightgray", fg="black", command=self.clicked_time, state=['disable'])
  161. self.button_time1.grid(column=0, row=3, sticky=EW)
  162. self.tgrafsp1 = Label(self.f_grafbtn, text="Конец времени, с", fg="black")
  163. self.tgrafsp1.grid(column=0, row=4)
  164. self.Time_flag = 'disabled'
  165. self.grafspin1 = Entry(self.f_grafbtn, width=7,state=self.Time_flag)
  166. self.grafspin1.grid(column=0, row=5)
  167. self.spinbox_var1 = StringVar(value=str(0))
  168. self.tgrafspTmin = Label(self.f_grafbtn, text="Нижняя граница, имп/с", fg="black")
  169. self.tgrafspTmin.grid(column=0, row=6)
  170. self.grafspinTmin = Spinbox(self.f_grafbtn, from_=0, to=5000,
  171. textvariable=self.spinbox_var1, increment=500, width=7)
  172. self.grafspinTmin.grid(column=0, row=7)
  173. self.tgrafspTmax = Label(self.f_grafbtn, text="Верхняя граница, имп/с", fg="black")
  174. self.tgrafspTmax.grid(column=0, row=8)
  175. self.spinbox_var2 = StringVar(value=str(10000))
  176. self.grafspinTmax = Spinbox(self.f_grafbtn, from_=5000, to=10000, increment=500,
  177. textvariable=self.spinbox_var2, width=7)
  178. self.grafspinTmax.grid(column=0, row=9)
  179. def ADC_create_Figure(self):
  180. self.ADC_file1 = open('coordinates.txt', 'r')
  181. with self.ADC_file1 as f:
  182. self.ADC_lines = f.readlines()
  183. self.ADC_data = [line.strip().split() for line in self.ADC_lines]
  184. self.ADC_xdata, self.ADC_ydata = zip(*[(float(x), float(y)) for x, y in self.ADC_data])
  185. self.f_graf_ADC = ttk.LabelFrame(Interface.window,
  186. text='АЦП канал 1, В', relief=SOLID)
  187. self.f_graf_ADC.grid(column=3, row=1, columnspan=2, rowspan=2)
  188. self.fig_ADC = Figure(figsize=(7, 4), dpi=80)
  189. self.ax_ADC = self.fig_ADC.add_subplot(111)
  190. self.ax_ADC.set_xlabel('Время, с')
  191. self.ax_ADC.set_ylabel('Напряжение, В')
  192. self.ax_ADC.grid(color='black', linewidth=1.0)
  193. self.ax_ADC.set_xlim(0, 3000)
  194. self.ax_ADC.set_ylim(0, 10000)
  195. self.canvas_ADC = FigureCanvasTkAgg(self.fig_ADC, master=self.f_graf_ADC)
  196. self.canvas_ADC.draw()
  197. self.canvas_ADC.get_tk_widget().grid(column=0, row=0)
  198. self.ADC_line, = self.ax_ADC.plot([], [], 'ro-')
  199. def init():
  200. self.ADC_line.set_data([], [])
  201. return self.ADC_line,
  202. def update(frame):
  203. self.ADC_line.set_data(self.ADC_xdata[:frame], self.ADC_ydata[:frame])
  204. return self.ADC_line,
  205. self.ADC_ani = FuncAnimation(self.fig_ADC, update, frames=len(self.ADC_xdata),
  206. init_func=init, blit=True, interval=5, repeat=False)
  207. Interface.window.after(100, lambda: None)
  208. self.f_grafbtnADC = ttk.LabelFrame(self.f_graf_ADC, text='Время отоброжения', padding=(8, 10))
  209. self.f_grafbtnADC.grid(column=1, row=0)
  210. self.tgrafspADC = Label(self.f_grafbtnADC, text="Начало времени, с", fg="black")
  211. self.tgrafspADC.grid(column=0, row=0)
  212. self.grafspinADC = Spinbox(self.f_grafbtnADC, from_=0, to=1000, increment=100, width=7)
  213. self.grafspinADC.grid(column=0, row=1)
  214. self.t1grafbtnADC = Label(self.f_grafbtnADC, text="Выбор конца времени", fg="black")
  215. self.t1grafbtnADC.grid(column=0, row=2)
  216. self.button_time1ADC = Button(self.f_grafbtnADC, text="Текущее время",
  217. bg="lightgray", fg="black", command=self.clicked_timeADC, state=['disable'])
  218. self.button_time1ADC.grid(column=0, row=3, sticky=EW)
  219. self.tgrafsp1ADC = Label(self.f_grafbtnADC, text="Конец времени, с", fg="black")
  220. self.tgrafsp1ADC.grid(column=0, row=4)
  221. self.Time_flagADC = 'disabled'
  222. self.grafspin1ADC = Entry(self.f_grafbtnADC, width=7, state=self.Time_flagADC)
  223. self.grafspin1ADC.grid(column=0, row=5)
  224. self.spinbox_var1ADC = StringVar(value=str(0))
  225. self.tgrafspTminADC = Label(self.f_grafbtnADC, text="Нижняя граница, В", fg="black")
  226. self.tgrafspTminADC.grid(column=0, row=6)
  227. self.grafspinTminADC = Spinbox(self.f_grafbtnADC, from_=0, to=5000,
  228. textvariable=self.spinbox_var1ADC, increment=500, width=7)
  229. self.grafspinTminADC.grid(column=0, row=7)
  230. self.tgrafspTmaxADC = Label(self.f_grafbtnADC, text="Верхняя граница, В", fg="black")
  231. self.tgrafspTmaxADC.grid(column=0, row=8)
  232. self.spinbox_var2ADC = StringVar(value=str(10000))
  233. self.grafspinTmaxADC = Spinbox(self.f_grafbtnADC, from_=5000, to=10000, increment=500,
  234. textvariable=self.spinbox_var2ADC, width=7)
  235. self.grafspinTmaxADC.grid(column=0, row=9)
  236. def TEM_create_Figure(self):
  237. self.TEM_file1 = open('coordinates.txt', 'r')
  238. with self.TEM_file1 as f:
  239. self.TEM_lines = f.readlines()
  240. self.TEM_data = [line.strip().split() for line in self.TEM_lines]
  241. self.TEM_xdata, self.TEM_ydata = zip(*[(float(x), float(y)) for x, y in self.TEM_data])
  242. self.f_graf_TEM = ttk.LabelFrame(Interface.window,
  243. text='Температура, С', relief=SOLID)
  244. self.f_graf_TEM.grid(column=1, row=3, columnspan=2, rowspan=2)
  245. self.fig_TEM = Figure(figsize=(7, 4), dpi=80)
  246. self.ax_TEM = self.fig_TEM.add_subplot(111)
  247. self.ax_TEM.set_xlabel('Время, с')
  248. self.ax_TEM.set_ylabel('Температура, С')
  249. self.ax_TEM.grid(color='black', linewidth=1.0)
  250. self.ax_TEM.set_xlim(0, 3000)
  251. self.ax_TEM.set_ylim(0, 10000)
  252. self.canvas_TEM = FigureCanvasTkAgg(self.fig_TEM, master=self.f_graf_TEM)
  253. self.canvas_TEM.draw()
  254. self.canvas_TEM.get_tk_widget().grid(column=0, row=0)
  255. self.TEM_line, = self.ax_TEM.plot([], [], 'ro-')
  256. def init():
  257. self.TEM_line.set_data([], [])
  258. return self.TEM_line,
  259. def update(frame):
  260. self.TEM_line.set_data(self.TEM_xdata[:frame], self.TEM_ydata[:frame])
  261. return self.TEM_line,
  262. self.TEM_ani = FuncAnimation(self.fig_TEM, update, frames=len(self.TEM_xdata),
  263. init_func=init, blit=True, interval=5, repeat=False)
  264. Interface.window.after(100, lambda: None)
  265. self.f_grafbtnTEM = ttk.LabelFrame(self.f_graf_TEM, text='Время отоброжения', padding=(8, 10))
  266. self.f_grafbtnTEM.grid(column=1, row=0)
  267. self.tgrafspTEM = Label(self.f_grafbtnTEM, text="Начало времени, с", fg="black")
  268. self.tgrafspTEM.grid(column=0, row=0)
  269. self.grafspinTEM = Spinbox(self.f_grafbtnTEM, from_=0, to=1000, increment=100, width=7)
  270. self.grafspinTEM.grid(column=0, row=1)
  271. self.t1grafbtnTEM = Label(self.f_grafbtnTEM, text="Выбор конца времени", fg="black")
  272. self.t1grafbtnTEM.grid(column=0, row=2)
  273. self.button_time1TEM = Button(self.f_grafbtnTEM, text="Текущее время",
  274. bg="lightgray", fg="black", command=self.clicked_timeTEM, state=['disable'])
  275. self.button_time1TEM.grid(column=0, row=3, sticky=EW)
  276. self.tgrafsp1TEM = Label(self.f_grafbtnTEM, text="Конец времени, с", fg="black")
  277. self.tgrafsp1TEM.grid(column=0, row=4)
  278. self.Time_flagTEM = 'disabled'
  279. self.grafspin1TEM = Entry(self.f_grafbtnTEM, width=7, state=self.Time_flagTEM)
  280. self.grafspin1TEM.grid(column=0, row=5)
  281. self.spinbox_var1TEM = StringVar(value=str(0))
  282. self.tgrafspTminTEM = Label(self.f_grafbtnTEM, text="Нижняя граница, С", fg="black")
  283. self.tgrafspTminTEM.grid(column=0, row=6)
  284. self.grafspinTminTEM = Spinbox(self.f_grafbtnTEM, from_=0, to=5000,
  285. textvariable=self.spinbox_var1TEM, increment=500, width=7)
  286. self.grafspinTminTEM.grid(column=0, row=7)
  287. self.tgrafspTmaxTEM = Label(self.f_grafbtnTEM, text="Верхняя граница, С", fg="black")
  288. self.tgrafspTmaxTEM.grid(column=0, row=8)
  289. self.spinbox_var2TEM = StringVar(value=str(10000))
  290. self.grafspinTmaxTEM = Spinbox(self.f_grafbtnTEM, from_=5000, to=10000, increment=500,
  291. textvariable=self.spinbox_var2TEM, width=7)
  292. self.grafspinTmaxTEM.grid(column=0, row=9)
  293. def start(self):
  294. self.mennuB()
  295. self.create_widgets_S()
  296. self.create_widgets_W()
  297. self.create_Figure()
  298. self.ADC_create_Figure()
  299. self.TEM_create_Figure()
  300. self.block_control()
  301. #scrollbar = ttk.Scrollbar(Interface.window, orient='vertical')
  302. #scrollbar.grid(column=5, row=0, rowspan=3, padx=50)
  303. Interface.window.mainloop()
  304. def clicked_file(self):
  305. self.file1 = filedialog.askopenfile(filetypes=(("Text files", "*.txt"), ("all files", "*.*")))
  306. assert self.file1 is not None
  307. self.file = os.path.abspath(self.file1.name)
  308. self.txt.delete(0, END)
  309. self.txt.insert(0, self.file)
  310. def clicked_start1(self):
  311. self.button_start.configure(state="disabled")
  312. self.t4.configure(text="Включено", bg="black", fg="green")
  313. self.button_startoff.configure(state="active")
  314. self.seconds1 = time.time()
  315. self.clicked_time()
  316. self.clicked_timeADC()
  317. self.clicked_timeTEM()
  318. def clicked_start2(self):
  319. self.seconds2 = time.time()
  320. self.button_start.configure(state="active")
  321. self.t4.configure(text="Выключено", bg="black", fg="white")
  322. self.button_startoff.configure(state='disabled')
  323. self.grafspin1.configure(state="normal")
  324. self.grafspin1ADC.configure(state="normal")
  325. self.grafspin1TEM.configure(state="normal")
  326. self.IMP_entry.configure(state="normal")
  327. self.ADC_entry.configure(state="normal")
  328. self.TEM_entry.configure(state="normal")
  329. if self.ani is not None:
  330. self.ani.event_source.stop()
  331. self.ani = None
  332. if self.ADC_ani is not None:
  333. self.ADC_ani.event_source.stop()
  334. self.ADC_ani = None
  335. if self.TEM_ani is not None:
  336. self.TEM_ani.event_source.stop()
  337. self.TEM_ani = None
  338. if self.ani1 is not None:
  339. self.ani1.event_source.stop()
  340. self.ani1 = None
  341. if self.ADC_ani1 is not None:
  342. self.ADC_ani1.event_source.stop()
  343. self.ADC_ani1 = None
  344. if self.TEM_ani1 is not None:
  345. self.TEM_ani1.event_source.stop()
  346. self.TEM_ani1 = None
  347. self.indexxx = (self.seconds2 - self.seconds1)
  348. self.grafspin1.delete(0, last=END)
  349. self.grafspin1.insert(0, str(self.xdata[round(self.indexxx * 5)]))
  350. self.grafspin1ADC.delete(0, last=END)
  351. self.grafspin1ADC.insert(0, str(self.ADC_xdata[round(self.indexxx * 5)]))
  352. self.grafspin1TEM.delete(0, last=END)
  353. self.grafspin1TEM.insert(0, str(self.TEM_xdata[round(self.indexxx * 5)]))
  354. self.IMP_entry.delete(0, last=END)
  355. self.IMP_entry.insert(0, str(round(self.ydata[round(self.indexxx * 5)])))
  356. self.ADC_entry.delete(0, last=END)
  357. self.ADC_entry.insert(0, str(round(self.ADC_ydata[round(self.indexxx * 5)])))
  358. self.TEM_entry.delete(0, last=END)
  359. self.TEM_entry.insert(0, str(round(self.TEM_ydata[round(self.indexxx * 5)])))
  360. self.grafspin1.configure(state="disabled")
  361. self.grafspin1ADC.configure(state="disabled")
  362. self.grafspin1TEM.configure(state="disabled")
  363. self.IMP_entry.configure(state="disabled")
  364. self.ADC_entry.configure(state="disabled")
  365. self.TEM_entry.configure(state="disabled")
  366. def clicked_V(self):
  367. if self.m == " 0 B ":
  368. self.m = ' 3.3 B '
  369. self.txt1_fw3.configure(text=' 3.3 B ')
  370. self.but_fw3.configure(text="--->")
  371. else:
  372. self.m = ' 0 B '
  373. self.but_fw3.configure(text='<---')
  374. self.txt1_fw3.configure(text=' 0 B ')
  375. def clicked_time(self):
  376. if self.ani is not None:
  377. self.ani.event_source.stop()
  378. self.ani = None
  379. self.file1 = open(self.file, 'r')
  380. with self.file1 as f:
  381. self.lines = f.readlines()
  382. self.data = [line.strip().split() for line in self.lines]
  383. self.xdata, self.ydata = zip(*[(float(x), float(y) + 100 * (-1) ** (round(float(y)) % 2)) for x, y in self.data])
  384. min_time = self.grafspin.get()
  385. self.xdata = list(filter(lambda x: x >= int(min_time), self.xdata))
  386. self.ax.clear()
  387. self.ax.set_xlabel('Время, с')
  388. self.ax.set_ylabel('Импульсы')
  389. self.ax.grid(color='black', linewidth=1.0)
  390. self.ax.set_xlim(min(self.xdata), 3000)
  391. self.ax.set_ylim(int(self.spinbox_var1.get()),
  392. int(self.spinbox_var2.get()))
  393. self.line, = self.ax.plot([], [], 'ro-')
  394. def init1():
  395. self.line.set_data([], [])
  396. return self.line,
  397. def update1(frame):
  398. self.line.set_data(self.xdata[:frame], self.ydata[:frame])
  399. return self.line,
  400. self.ani1 = FuncAnimation(self.fig, update1, frames=len(self.xdata),
  401. init_func=init1, blit=True, interval=200, repeat=False)
  402. self.canvas.draw()
  403. Interface.window.after(10, lambda: None)
  404. def clicked_timeADC(self):
  405. if self.ADC_ani is not None:
  406. self.ADC_ani.event_source.stop()
  407. self.ADC_ani = None
  408. self.ADC_file1 = open(self.file, 'r')
  409. self.Time_flagADC = 'disabled'
  410. self.grafspin1.configure(state=self.Time_flagADC)
  411. with self.ADC_file1 as f:
  412. self.ADC_lines = f.readlines()
  413. self.ADC_data = [line.strip().split() for line in self.ADC_lines]
  414. self.ADC_xdata, self.ADC_ydata = zip(*[(float(x), float(y)) for x, y in self.ADC_data])
  415. max_time = self.grafspin1ADC.get()
  416. min_time = self.grafspinADC.get()
  417. self.ADC_xdata = list(filter(lambda x: x >= int(min_time), self.ADC_xdata))
  418. self.ax_ADC.clear()
  419. self.ax_ADC.set_xlabel('Время, с')
  420. self.ax_ADC.set_ylabel('Напряжение, В')
  421. self.ax_ADC.grid(color='black', linewidth=1.0)
  422. self.ax_ADC.set_xlim(min(self.ADC_xdata), 3000)
  423. self.ax_ADC.set_ylim(int(self.spinbox_var1ADC.get()),
  424. int(self.spinbox_var2ADC.get()))
  425. self.ADC_line, = self.ax_ADC.plot([], [], 'ro-')
  426. def init1():
  427. self.ADC_line.set_data([], [])
  428. return self.ADC_line,
  429. def update1(frame):
  430. self.ADC_line.set_data(self.ADC_xdata[:frame], self.ADC_ydata[:frame])
  431. return self.ADC_line,
  432. self.ADC_ani1 = FuncAnimation(self.fig_ADC, update1, frames=len(self.ADC_xdata),
  433. init_func=init1, blit=True, interval=200, repeat=False)
  434. self.canvas_ADC.draw()
  435. Interface.window.after(10, lambda: None)
  436. def clicked_timeTEM(self):
  437. if self.TEM_ani is not None:
  438. self.TEM_ani.event_source.stop()
  439. self.TEM_ani = None
  440. self.TEM_file1 = open(self.file, 'r')
  441. self.Time_flagTEM = 'disabled'
  442. self.grafspin1TEM.configure(state=self.Time_flagTEM)
  443. with self.TEM_file1 as f:
  444. self.TEM_lines = f.readlines()
  445. self.TEM_data = [line.strip().split() for line in self.ADC_lines]
  446. self.TEM_xdata, self.TEM_ydata = zip(*[(float(x), float(y)) for x, y in self.TEM_data])
  447. max_time = self.grafspin1TEM.get()
  448. min_time = self.grafspinTEM.get()
  449. self.TEM_xdata = list(filter(lambda x: x >= int(min_time), self.TEM_xdata))
  450. self.ax_TEM.clear()
  451. self.ax_TEM.set_xlabel('Время, с')
  452. self.ax_TEM.set_ylabel('Температура, С')
  453. self.ax_TEM.grid(color='black', linewidth=1.0)
  454. self.ax_TEM.set_xlim(min(self.TEM_xdata), 3000)
  455. self.ax_TEM.set_ylim(int(self.spinbox_var1TEM.get()),
  456. int(self.spinbox_var2TEM.get()))
  457. self.TEM_line, = self.ax_TEM.plot([], [], 'ro-')
  458. def init1():
  459. self.TEM_line.set_data([], [])
  460. return self.TEM_line,
  461. def update1(frame):
  462. self.TEM_line.set_data(self.TEM_xdata[:frame], self.TEM_ydata[:frame])
  463. return self.TEM_line,
  464. self.TEM_ani1 = FuncAnimation(self.fig_TEM, update1, frames=len(self.TEM_xdata),
  465. init_func=init1, blit=True, interval=200, repeat=False)
  466. self.canvas_TEM.draw()
  467. Interface.window.after(10, lambda: None)
  468. def block_control(self):
  469. self.f_BC = ttk.LabelFrame(Interface.window, text='Текущее значение данных:', relief=SOLID)
  470. self.f_BC.grid(column=3, row=3, columnspan=2, rowspan=2)
  471. self.text_BC = Label(self.f_BC, text="Кол-во импульсов", fg="black")
  472. self.text_BC.grid(column=0, row=0, pady=10)
  473. self.text_BC_ADC = Label(self.f_BC, text="АЦП канал 1, В", fg="black")
  474. self.text_BC_ADC.grid(column=1, row=0, ipadx=15, pady=10)
  475. self.text_BC_TEM = Label(self.f_BC, text="Температура, С", fg="black")
  476. self.text_BC_TEM.grid(column=2, row=0, ipady=10)
  477. self.impSV = StringVar(value=round(self.ydata[0]))
  478. self.adcSV = StringVar(value=round(self.ADC_ydata[0]))
  479. self.temSV = StringVar(value=round(self.TEM_ydata[0]))
  480. self.IMP_entry = Entry(self.f_BC, width=15, state='disabled', textvariable=self.impSV)
  481. self.IMP_entry.grid(column=0, row=1)
  482. self.ADC_entry = Entry(self.f_BC, width=15, state='disabled', textvariable=self.adcSV)
  483. self.ADC_entry.grid(column=1, row=1, padx=15)
  484. self.TEM_entry = Entry(self.f_BC, width=15, state='disabled', textvariable=self.temSV)
  485. self.TEM_entry.grid(column=2, row=1)
  486. self.SDT = Label(self.f_BC, text="Работает", fg="black", bg="green")
  487. self.SDT.grid(column=0, row=2, pady=10, sticky='NSEW')
  488. self.SVadc = Label(self.f_BC, text="Работает", fg="black", bg="green")
  489. self.SVadc.grid(column=2, row=2, pady=10, sticky='NSEW')
  490. def mennuB(self):
  491. menubar1 = tk.Menu(self.window)
  492. self.window.config(menu=menubar1)
  493. setting_menu1 = tk.Menu(menubar1)
  494. setting_menu1.add_command(label='---')
  495. menubar1.add_cascade(label='File', menu=setting_menu1)
  496. setting_menu2 = tk.Menu(menubar1)
  497. setting_menu2.add_command(label='----')
  498. menubar1.add_cascade(label='Edit', menu=setting_menu2)
  499. setting_menu3 = tk.Menu(menubar1)
  500. setting_menu3.add_command(label='---')
  501. menubar1.add_cascade(label='Operate', menu=setting_menu3)
  502. setting_menu4 = tk.Menu(menubar1)
  503. setting_menu4.add_command(label='-----')
  504. menubar1.add_cascade(label='Tools', menu=setting_menu4)
  505. setting_menu5 = tk.Menu(menubar1)
  506. setting_menu5.add_command(label='-----')
  507. menubar1.add_cascade(label='Window', menu=setting_menu5)
  508. setting_menu6 = tk.Menu(menubar1)
  509. setting_menu6.add_command(label='-----')
  510. menubar1.add_cascade(label='Help', menu=setting_menu6)
  511. interface = Interface()
  512. interface.start()