InterfaceL.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. from idlelib.colorizer import color_config
  2. from tkinter import *
  3. import tkinter as tk
  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, NavigationToolbar2Tk)
  9. from random import choice
  10. import matplotlib.pyplot as plt
  11. import matplotlib
  12. import matplotlib.animation as animation
  13. import numpy as np
  14. import os
  15. class Interface():
  16. window = Tk()
  17. def __init__(self):
  18. pass
  19. def create_widgets_S(self):
  20. Interface.window.title("project_gamma_new_2vi")
  21. Interface.window.geometry('500x250+100+100')
  22. photo = tk.PhotoImage(file='iconka.png')
  23. Interface.window.iconphoto(False, photo)
  24. self.f_top = ttk.LabelFrame(Interface.window, text="Виртуальный COM порт", relief=SOLID, padding=[8, 10])
  25. self.combo = Combobox(self.f_top)
  26. self.combo['values'] = (1, 2, 3, 4, 5)
  27. self.combo.current(4)
  28. self.f_top.grid(column=0, row=0)
  29. self.combo.pack(side=BOTTOM)
  30. self.f_file = ttk.LabelFrame(Interface.window, text="Выбрать файл txt для записи", relief=SOLID, padding=[8, 10])
  31. self.f_file.grid(column=1, row=0)
  32. self.txt = Entry(self.f_file, width=40)
  33. self.txt.pack(side=LEFT)
  34. self.btn = Button(self.f_file, height=1, text='Файл', bg="gray", fg="red", command=self.clicked_file)
  35. self.btn.pack(side=LEFT)
  36. self.f_start = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
  37. self.t1 = Label(self.f_start, text="Состояние работы", fg="black")
  38. self.t2 = Label(self.f_start, text="Начать сбор данных", fg="black")
  39. self.t3 = Label(self.f_start, text="Остановить сбор данных", fg="black")
  40. self.t4 = Label(self.f_start, text="Выключено", fg="white", bg="black")
  41. self.button_start = Button(self.f_start, text="Пуск", bg="lightgray", fg="black", command=self.clicked_start1)
  42. self.button_startoff = Button(self.f_start, text="Стоп", bg="lightgray", fg="red",
  43. command=self.clicked_start2,
  44. state=['disabled'])
  45. self.f_start1= ttk.LabelFrame(Interface.window, text='Принятые символы', relief=SOLID, padding=[8, 10])
  46. self.t_entry = Entry(self.f_start1, width=40)
  47. self.f_start.grid(column=2, row=0)
  48. self.f_start1.grid(column=3, row=0)
  49. self.t1.grid(column=0, row=0)
  50. self.t2.grid(column=1, row=0)
  51. self.t3.grid(column=2, row=0)
  52. self.t4.grid(column=0, row=1)
  53. self.t_entry.grid(column=0, row=1)
  54. self.button_start.grid(column=1, row=1)
  55. self.button_startoff.grid(column=2, row=1)
  56. def create_widgets_W(self):
  57. self.f_W = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
  58. self.f_W.grid(column=0, row=1)
  59. self.tspin1 = Label(self.f_W, text="Время экспозиции, с", fg="black")
  60. self.tspin2 = Label(self.f_W, text="Макс. время сбора данных, с", fg="black")
  61. self.tspin3 = Label(self.f_W, text="Прошло времени, с", fg="black")
  62. self.spin1 = Spinbox(self.f_W, from_=0, to=100, width=7)
  63. self.spin2 = Spinbox(self.f_W, from_=0, to=10000000, increment=500, width=11)
  64. self.t_entry = Entry(self.f_W, width=20, state=['disabled'])
  65. self.tspin1.grid(column=0, row=0, ipadx=10)
  66. self.spin1.grid(column=0, row=1, pady=10)
  67. self.tspin2.grid(column=0, row=2, ipadx=10)
  68. self.spin2.grid(column=0, row=3, pady=10)
  69. self.tspin3.grid(column=0, row=4, pady=10)
  70. self.t_entry.grid(column=0, row=5)
  71. self.f_W1 = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
  72. self.f_W1.grid(column=0, row=2)
  73. self.tspin_0 = Label(self.f_W1, text="Коэффициент делителя", fg="black")
  74. self.spin_0 = Spinbox(self.f_W1, from_=0, to=100, width=7)
  75. self.tspin_0.grid(column=0, row=0, ipadx=10)
  76. self.spin_0.grid(column=0, row=1, pady=10)
  77. self.f_W2 = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
  78. self.f_W2.grid(column=0, row=3)
  79. self.spin1_zap = Spinbox(self.f_W2, from_=0.0, to=50.0, increment=0.1, width=6)
  80. self.spin2_zap = Spinbox(self.f_W2, from_=0, to=100, increment=1, width=6)
  81. self.spin3_zap = Spinbox(self.f_W2, from_=0, to=500, width=6)
  82. self.spin4_zap = Spinbox(self.f_W2, from_=0, to=500 , width=6)
  83. self.tspin1_zap = Label(self.f_W2, text="ЦАП канал 1.0...3.29В", fg="black")
  84. self.tspin2_zap = Label(self.f_W2, text="ЦАП канал 2.0...3.29В", fg="black")
  85. self.tspin3_zap = Label(self.f_W2, text="ЦАП канал 3.1...256", fg="black")
  86. self.tspin4_zap = Label(self.f_W2, text="ЦАП канал 4.1...256", fg="black")
  87. self.tbut1_zap = Label(self.f_W2, text='''Обновить значение
  88. каналов DAC''', fg="black")
  89. self.tbut2_zap = Label(self.f_W2, text='''Прочесть текущее
  90. значение каналов DAC''', fg="black")
  91. self.button1_zap= Button(self.f_W2, text="Обновить", bg="lightgray", fg="black")
  92. self.button2_zap = Button(self.f_W2, text="Прочесть", bg="lightgray", fg="black")
  93. self.tspin1_zap.grid(column=0, row=0, ipadx=10)
  94. self.spin1_zap.grid(column=0, row=1, pady=10)
  95. self.tspin2_zap.grid(column=0, row=2, ipadx=10)
  96. self.spin2_zap.grid(column=0, row=3, pady=10)
  97. self.tspin3_zap.grid(column=0, row=4, ipadx=10)
  98. self.spin3_zap.grid(column=0, row=5, pady=10)
  99. self.tspin4_zap.grid(column=0, row=6, ipadx=10)
  100. self.spin4_zap.grid(column=0, row=7, pady=10)
  101. self.tbut1_zap.grid(column=0, row=8)
  102. self.button1_zap.grid(column=0, row=9)
  103. self.tbut2_zap.grid(column=0, row=10)
  104. self.button2_zap.grid(column=0, row=11)
  105. self.f_W3 = ttk.Frame(Interface.window, relief=SOLID, padding=[8, 10])
  106. self.txt0_fw3 = Label(self.f_W3, text="Порт В1 напряжения", fg="black")
  107. self.txt1_fw3 = Label(self.f_W3, text=" 0 B ", fg="black", bg="pink")
  108. self.m = ' 0 B '
  109. self.txt2_fw3 = Label(self.f_W3, text='''Выбор напряжения:
  110. 0 В 3.3B''')
  111. self.but_fw3 = Button(self.f_W3, text='<---', command=self.clicked_V)
  112. self.f_W3.grid(column=0, row=4)
  113. self.txt0_fw3.grid(column=0, row=0)
  114. self.txt1_fw3.grid(column=0, row=1, pady=10)
  115. self.txt2_fw3.grid(column=0, row=2)
  116. self.but_fw3.grid(column=0, row=3)
  117. def create_Figure(self):
  118. self.file1 = open("1234test.txt", 'r')
  119. self.data = self.file1.readlines()
  120. self.mnojtel = int(self.data[0])
  121. self.f_graf = ttk.LabelFrame(Interface.window,
  122. text='Количество импульсов в минуту', relief=SOLID)
  123. self.f_graf.grid(column=1, row=1, columnspan=2, rowspan=2)
  124. self.fig = Figure(figsize=(7, 4), dpi=80)
  125. self.t = np.linspace(0, 100, num=10000)
  126. self.ax = self.fig.add_subplot(111)
  127. self.ax.set_xlabel('Время, с')
  128. self.ax.set_ylabel('Импульсы')
  129. self.ax.plot(self.t, 5000 + 5000 * np.sin(self.t / self.mnojtel), '-rh',
  130. linewidth=1, markersize=1, markerfacecolor='b')
  131. self.ax.grid(color='black', linewidth=1.0)
  132. self.canvas = FigureCanvasTkAgg(self.fig, master=self.f_graf)
  133. self.canvas.draw()
  134. self.canvas.get_tk_widget().grid(column=0, row=0)
  135. Interface.window.after(100, None)
  136. self.f_grafbtn = ttk.LabelFrame(self.f_graf, text='Время отоброжения', padding=[8, 10])
  137. self.f_grafbtn.grid(column=1, row=0)
  138. self.tgrafsp = Label(self.f_grafbtn, text="Начало времени, с", fg="black")
  139. self.tgrafsp.grid(column=0, row=0)
  140. self.grafspin = Spinbox(self.f_grafbtn, from_=0, to=1000, increment=100, width=7)
  141. self.grafspin.grid(column=0, row=1)
  142. self.t1grafbtn = Label(self.f_grafbtn, text="Выбор конца времени", fg="black")
  143. self.t1grafbtn.grid(column=0, row=2)
  144. self.button_time1 = Button(self.f_grafbtn, text="start",
  145. bg="lightgray", fg="black", command=self.clicked_time)
  146. self.button_time1.grid(column=0, row=3, sticky=EW)
  147. self.tgrafsp1 = Label(self.f_grafbtn, text="Конец времени, с", fg="black")
  148. self.tgrafsp1.grid(column=0, row=4)
  149. self.Time_flag = 'disabled'
  150. self.spinbox_varTime = StringVar(value=100)
  151. self.grafspin1 = Spinbox(self.f_grafbtn, from_=100, to=50000, increment=100, width=7,
  152. textvariable=self.spinbox_varTime, state=[self.Time_flag])
  153. self.grafspin1.grid(column=0, row=5)
  154. self.spinbox_var1 = StringVar(value=0)
  155. self.tgrafspTmin = Label(self.f_grafbtn, text="Нижняя граница, имп/с", fg="black")
  156. self.tgrafspTmin.grid(column=0, row=6)
  157. self.grafspinTmin = Spinbox(self.f_grafbtn, from_=0, to=5000,
  158. textvariable=self.spinbox_var1, increment=500, width=7)
  159. self.grafspinTmin.grid(column=0, row=7)
  160. self.tgrafspTmax = Label(self.f_grafbtn, text="Верхняя граница, имп/с", fg="black")
  161. self.tgrafspTmax.grid(column=0, row=8)
  162. self.spinbox_var2 = StringVar(value=10000)
  163. self.grafspinTmax = Spinbox(self.f_grafbtn, from_=5000, to=10000, increment=500,
  164. textvariable=self.spinbox_var2, width=7)
  165. self.grafspinTmax.grid(column=0, row=9)
  166. def start(self):
  167. self.mennuB()
  168. self.create_widgets_S()
  169. self.create_widgets_W()
  170. self.create_Figure()
  171. Interface.window.mainloop()
  172. def clicked_file(self):
  173. self.file1 = filedialog.askopenfile(filetypes=(("Text files","*.txt"),("all files","*.*")))
  174. self.file = os.path.abspath(self.file1.name)
  175. self.txt.delete(0, END)
  176. self.txt.insert(0, self.file)
  177. def clicked_start1(self):
  178. self.button_start.configure(state=["disabled"])
  179. self.t4.configure(text="Включено", bg="black", fg="green")
  180. self.button_startoff.configure(state=["active"])
  181. def clicked_start2(self):
  182. self.button_start.configure(state=["active"])
  183. self.t4.configure(text="Выключено", bg="black", fg="white")
  184. self.button_startoff.configure(state=['disabled'])
  185. def clicked_V(self):
  186. if self.m == " 0 B ":
  187. self.m = ' 3.3 B '
  188. self.txt1_fw3.configure(text=' 3.3 B ')
  189. self.but_fw3.configure(text="--->")
  190. else:
  191. self.m = ' 0 B '
  192. self.but_fw3.configure(text='<---')
  193. self.txt1_fw3.configure(text=' 0 B ')
  194. def clicked_time(self):
  195. if self.Time_flag == 'disabled':
  196. self.Time_flag = 'normal'
  197. self.grafspin1.configure(state=[self.Time_flag])
  198. else:
  199. self.file1 = open(self.file, 'r')
  200. self.data = self.file1.readlines()
  201. self.mnojtel = int(self.data[0])
  202. self.Time_flag = 'disabled'
  203. self.grafspin1.configure(state=[self.Time_flag])
  204. self.fig.clear()
  205. self.fig = Figure(figsize=(7, 4), dpi=80)
  206. self.ax = self.fig.add_subplot(111)
  207. self.t = np.linspace(0, int(self.spinbox_varTime.get()), num=10000)
  208. self.ax.set_ylim(bottom=0, top=10000)
  209. self.ax.set_xlabel('Время, с')
  210. self.ax.set_ylabel('Импульсы')
  211. self.ax.plot(self.t,
  212. int(self.spinbox_var1.get()) + abs(int(self.spinbox_var1.get()) - int(self.spinbox_var2.get())) * 0.5 * (1 + np.sin(self.t / self.mnojtel)),
  213. '-rh', linewidth=1, markersize=1, markerfacecolor='b')
  214. self.ax.grid(color='black', linewidth=1.0)
  215. self.canvas = FigureCanvasTkAgg(self.fig, master=self.f_graf)
  216. self.canvas.draw()
  217. self.canvas.get_tk_widget().grid(column=0, row=0)
  218. Interface.window.after(100, None)
  219. def mennuB(self):
  220. menubar1 = tk.Menu(self.window)
  221. self.window.config(menu=menubar1)
  222. setting_menu1 = tk.Menu(menubar1)
  223. setting_menu1.add_command(label='---')
  224. menubar1.add_cascade(label='File', menu=setting_menu1)
  225. setting_menu2 = tk.Menu(menubar1)
  226. setting_menu2.add_command(label='----')
  227. menubar1.add_cascade(label='Edit', menu=setting_menu2)
  228. setting_menu3 = tk.Menu(menubar1)
  229. setting_menu3.add_command(label='---')
  230. menubar1.add_cascade(label='Operate', menu=setting_menu3)
  231. setting_menu4 = tk.Menu(menubar1)
  232. setting_menu4.add_command(label='-----')
  233. menubar1.add_cascade(label='Tools', menu=setting_menu4)
  234. setting_menu5 = tk.Menu(menubar1)
  235. setting_menu5.add_command(label='-----')
  236. menubar1.add_cascade(label='Window', menu=setting_menu5)
  237. setting_menu6 = tk.Menu(menubar1)
  238. setting_menu6.add_command(label='-----')
  239. menubar1.add_cascade(label='Help', menu=setting_menu6)
  240. interface = Interface()
  241. interface.start()