InterfaceL.py 32 KB

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