InterfaceL.py 27 KB

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