app.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. from tkinter import *
  2. from tkinter.ttk import Combobox
  3. from tkinter.scrolledtext import ScrolledText
  4. import tkinter.messagebox
  5. import sys
  6. import time
  7. import user
  8. import var
  9. import batch
  10. import param
  11. import production
  12. import inquire
  13. import user_socket
  14. import pro
  15. import user_openOpc
  16. import ezcad
  17. opc_value = var.opc_var()
  18. init_window = Tk() #实例化出一个父窗口
  19. user_var = var.Var_value(init_window)
  20. font_size_title = 14
  21. font_size_text = 11
  22. # 创建新线程
  23. thread_tcp = user_socket.socket_server(1, "Thread-tcp", 1)
  24. thread_work = pro.work_server(2, "Thread-work", 2)
  25. thread_opc = user_openOpc.opc_server(3, "Thread-opc", 3)
  26. thread_ezcad = ezcad.ezcad(4, "Thread-ezcad", 4)
  27. class my_gui(Frame):
  28. def __init__(self, init_window_name):
  29. global user_var
  30. self.init_window_name = init_window_name
  31. self.user_var = user_var
  32. self.opc_value = opc_value
  33. self.tcpserverParam = user_socket.tcpserverParam
  34. self.screen_width = self.user_var.screen_width
  35. self.screen_height = self.user_var.screen_height
  36. self.font_size_title = font_size_title
  37. self.font_size_text = font_size_text
  38. self.bee_stat_change_timeout = 0
  39. self.main_gui_init()
  40. self.title_canvas_init()
  41. self.button_canvas_init()
  42. self.order_frame_init()
  43. self.user_var.windows_idx = 'app'
  44. self.fun_timer()
  45. def team_sel_value(self):
  46. self.team_combobox.current(self.user_var.team_sel)
  47. def team_combobox_sel(self, *args):
  48. value = self.team_combobox.get()
  49. stat = tkinter.messagebox.askokcancel(title='提示', message='班组确认切换为{}'.format(value))
  50. if stat == True:
  51. for i in range(len(self.user_var.team_list)):
  52. if self.user_var.team_list[i] == value:
  53. self.user_var.team_sel = i
  54. self.user_var.team_value = value
  55. self.user_var.team = chr(self.user_var.team_sel + ord('A'))
  56. self.user_var.order_update_stat = True
  57. break
  58. self.team_sel_value()
  59. # def check_radiobutton_sel(self):
  60. # print(self.check_bit.get())
  61. def user_button_event(self):
  62. print("Please enter your username and password!")
  63. self.user_var.last_windows_idx = 'app'
  64. self.init_window_name.after_cancel(self.task_user)
  65. self.main_frame.destroy()
  66. user.my_reg(self.init_window_name)
  67. def param_button_event(self):
  68. if self.user_var.auth_stat == True:
  69. print("Enter Param Set!")
  70. self.user_var.last_windows_idx = 'app'
  71. self.init_window_name.after_cancel(self.task_user)
  72. self.main_frame.destroy()
  73. param.my_param(self.init_window_name)
  74. else:
  75. tkinter.messagebox.showwarning(title='提示', message='请登录后操作!')
  76. def data_button_event(self):
  77. print("Enter Data View!")
  78. self.user_var.last_windows_idx = 'app'
  79. self.init_window_name.after_cancel(self.task_user)
  80. self.main_frame.destroy()
  81. inquire.my_inquire(self.init_window_name)
  82. def print_button_event(self):
  83. print("Enter Print!")
  84. self.user_var.last_windows_idx = 'app'
  85. def produce_sel_button_event(self):
  86. if self.user_var.auth_stat == True:
  87. print("Please Select Production!")
  88. self.user_var.last_windows_idx = 'app'
  89. self.init_window_name.after_cancel(self.task_user)
  90. self.main_frame.destroy()
  91. production.my_production(self.init_window_name)
  92. else:
  93. tkinter.messagebox.showwarning(title='提示', message='请登录后操作!')
  94. def bee_button_event(self):
  95. if self.user_var.bee_stat == False:
  96. self.user_var.bee_stat = True
  97. self.bee_button.configure(relief=RAISED)
  98. self.bee_button.configure(state="disabled")
  99. self.bee_stat_change_timeout = 10
  100. self.opc_value.set_Bee(True)
  101. else:
  102. self.user_var.bee_stat = False
  103. self.bee_button.configure(relief=SUNKEN)
  104. self.bee_button.configure(state="disabled")
  105. self.bee_stat_change_timeout = 10
  106. self.opc_value.set_Bee(False)
  107. def workstatlabel_value(self):
  108. if self.user_var.airdata_work_stat == 'working':
  109. self.workstatlabel.config(text=" 系统正在运行中...")
  110. else:
  111. self.workstatlabel.config(text=" 系统停止中...")
  112. def productstatlabel_value(self):
  113. if self.user_var.product_name_noset == '品番已设置':
  114. self.productstatlabel.config(fg='black')
  115. self.productstatlabel.config(text=self.user_var.product_name_noset)
  116. else:
  117. self.productstatlabel.config(fg='Red')
  118. self.productstatlabel.config(text=self.user_var.product_name_noset)
  119. def opcstatlabel_value(self):
  120. if self.user_var.opc_conn_stat == "PLC已连接":
  121. self.opcstatlabel.config(fg="Green")
  122. elif self.user_var.opc_conn_stat == "PLC未连接":
  123. self.opcstatlabel.config(fg="Yellow")
  124. else:
  125. self.opcstatlabel.config(fg="Red")
  126. self.opcstatlabel.config(text=self.user_var.opc_conn_stat)
  127. def socketstatlabel_value(self):
  128. if self.user_var.socket_conn_stat == True:
  129. self.socketstatlabel.config(text="打标机已连接")
  130. self.socketstatlabel.config(fg="Green")
  131. else:
  132. self.socketstatlabel.config(text="打标机未连接")
  133. self.socketstatlabel.config(fg="Red")
  134. def authstatlabel_value(self):
  135. if self.user_var.auth_stat == False:
  136. self.authlabel.config(text="不允许", fg='red')
  137. # self.team_combobox.configure(state="disabled")
  138. self.param_button.configure(state="disabled")
  139. self.print_button.configure(state="disabled")
  140. self.product_sel_button.configure(state="disabled")
  141. else:
  142. self.authlabel.config(text="允许", fg='green')
  143. # self.team_combobox.configure(state="readonly")
  144. self.param_button.configure(state="normal")
  145. self.print_button.configure(state="normal")
  146. self.product_sel_button.configure(state="normal")
  147. def airtightdev_value(self):
  148. if self.user_var.originchkok_stat == True:
  149. self.originchkoklabel.config(bg='Lime')
  150. else:
  151. self.originchkoklabel.config(bg='DarkGray')
  152. if self.user_var.upairtightok_stat == True:
  153. self.upairtightoklabel.config(bg='Lime')
  154. else:
  155. self.upairtightoklabel.config(bg='DarkGray')
  156. if self.user_var.upairtightng_stat == True:
  157. self.upairtightnglabel.config(bg='Lime')
  158. else:
  159. self.upairtightnglabel.config(bg='DarkGray')
  160. if self.user_var.upprintok_stat == True:
  161. self.upprintoklabel.config(bg='Lime')
  162. else:
  163. self.upprintoklabel.config(bg='DarkGray')
  164. if self.user_var.origindir_stat == True:
  165. self.origindirlabel.config(bg='Lime')
  166. else:
  167. self.origindirlabel.config(bg='DarkGray')
  168. if self.user_var.downairtightok_stat == True:
  169. self.downairtightoklabel.config(bg='Lime')
  170. else:
  171. self.downairtightoklabel.config(bg='DarkGray')
  172. if self.user_var.downairtightng_stat == True:
  173. self.downairtightnglabel.config(bg='Lime')
  174. else:
  175. self.downairtightnglabel.config(bg='DarkGray')
  176. if self.user_var.downprintok_stat == True:
  177. self.downprintoklabel.config(bg='Lime')
  178. else:
  179. self.downprintoklabel.config(bg='DarkGray')
  180. def motordev_value(self):
  181. if self.user_var.motororiginok_stat == True:
  182. self.motororiginoklabel.config(bg='Lime')
  183. else:
  184. self.motororiginoklabel.config(bg='DarkGray')
  185. if self.user_var.motoronup_stat == True:
  186. self.motoronuplabel.config(bg='Lime')
  187. else:
  188. self.motoronuplabel.config(bg='DarkGray')
  189. if self.user_var.motorondown_stat == True:
  190. self.motorondownlabel.config(bg='Lime')
  191. else:
  192. self.motorondownlabel.config(bg='DarkGray')
  193. if self.user_var.motorunuse_stat == True:
  194. self.motorunuselabel.config(bg='Lime')
  195. else:
  196. self.motorunuselabel.config(bg='DarkGray')
  197. def station_value(self):
  198. if self.user_var.upgages_stat == True:
  199. self.upgageslabel.config(bg='black', fg='white')
  200. else:
  201. self.upgageslabel.config(fg='black', bg='white')
  202. if self.user_var.upworks_stat == True:
  203. self.upworkslabel.config(bg='black', fg='white')
  204. else:
  205. self.upworkslabel.config(fg='black', bg='white')
  206. if self.user_var.upmpen_stat == True:
  207. self.upmpenlabel.config(bg='black', fg='white')
  208. else:
  209. self.upmpenlabel.config(fg='black', bg='white')
  210. if self.user_var.upconnect_stat == True:
  211. self.upconnectlabel.config(bg='black', fg='white')
  212. else:
  213. self.upconnectlabel.config(fg='black', bg='white')
  214. if self.user_var.downgages_stat == True:
  215. self.downgageslabel.config(bg='black', fg='white')
  216. else:
  217. self.downgageslabel.config(fg='black', bg='white')
  218. if self.user_var.downworks_stat == True:
  219. self.downworkslabel.config(bg='black', fg='white')
  220. else:
  221. self.downworkslabel.config(fg='black', bg='white')
  222. if self.user_var.downmpen_stat == True:
  223. self.downmpenlabel.config(bg='black', fg='white')
  224. else:
  225. self.downmpenlabel.config(fg='black', bg='white')
  226. if self.user_var.downconnect_stat == True:
  227. self.downconnectlabel.config(bg='black', fg='white')
  228. else:
  229. self.downconnectlabel.config(fg='black', bg='white')
  230. def bee_value(self):
  231. if self.bee_stat_change_timeout == 0:
  232. if self.user_var.bee_stat == True:
  233. self.bee_button.configure(relief=RAISED)
  234. self.bee_button.configure(state="normal")
  235. else:
  236. self.bee_button.configure(relief=SUNKEN)
  237. self.bee_button.configure(state="normal")
  238. else:
  239. self.bee_stat_change_timeout = self.bee_stat_change_timeout - 1
  240. def auth_exit(self):
  241. if self.user_var.auth_timeout > 0:
  242. self.user_var.auth_timeout = self.user_var.auth_timeout - 1
  243. else:
  244. self.user_var.auth_stat = False
  245. def windows_update(self):
  246. currentTime = time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(time.time()))
  247. self.timelabel.config(text=currentTime)
  248. self.workstatlabel_value()
  249. self.productstatlabel_value()
  250. self.opcstatlabel_value()
  251. self.socketstatlabel_value()
  252. self.authstatlabel_value()
  253. self.airtightdev_value()
  254. self.motordev_value()
  255. self.station_value()
  256. self.bee_value()
  257. self.team_sel_value()
  258. self.auth_exit()
  259. self.init_window_name.update()
  260. self.fun_timer()
  261. def fun_timer(self):
  262. self.task_user=self.init_window_name.after(1000, self.windows_update)
  263. def main_gui_init(self):
  264. self.main_frame = Frame(self.init_window_name, width=self.screen_width, height=self.screen_height)
  265. self.main_frame.pack()
  266. # 标题栏
  267. def title_canvas_init(self):
  268. self.title_canvas = Canvas(self.main_frame, width=self.screen_width - 20, height=35, bg='SeaGreen')
  269. self.mainlabel = Label(self.title_canvas, text="主页面", fg='yellow', font=("宋体", self.font_size_title),
  270. bg='SeaGreen', anchor='w')
  271. self.mainlabel.place(x=20, y=5)
  272. self.timelabel = Label(self.title_canvas, text=time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(time.time())),
  273. fg='yellow', font=("宋体", self.font_size_title), bg='SeaGreen', anchor='e')
  274. self.timelabel.place(x=self.title_canvas.winfo_reqwidth() - self.timelabel.winfo_reqwidth() - 20, y=5)
  275. self.title_canvas.create_line(self.mainlabel.winfo_reqwidth()/2+20, 32, self.title_canvas.winfo_reqwidth() -
  276. self.timelabel.winfo_reqwidth()/2 - 20, 32, fill='white')
  277. self.title_canvas.place(x=10, y=10)
  278. # 控制栏
  279. def button_canvas_init(self):
  280. self.button_canvas = Canvas(self.main_frame, width=self.screen_width - 20, height=40)
  281. self.user_button = Button(self.button_canvas, text="用户登陆", fg='white', bg='DeepSkyBlue', width=8,
  282. activebackground='white', activeforeground='DeepSkyBlue',
  283. font=("宋体", self.font_size_title, "bold"), command=self.user_button_event)
  284. self.user_button.place(x=1, y=0)
  285. self.param_button = Button(self.button_canvas, text="参数设定", fg='white', bg='DeepSkyBlue', width=8,
  286. activebackground='white', activeforeground='DeepSkyBlue', state="disabled",
  287. font=("宋体", self.font_size_title, "bold"), command=self.param_button_event)
  288. self.param_button.place(x=self.user_button.winfo_reqwidth()*2+3, y=0)
  289. self.data_button = Button(self.button_canvas, text="数据查询", fg='white', bg='DeepSkyBlue', width=8,
  290. activebackground='white', activeforeground='DeepSkyBlue',
  291. font=("宋体", self.font_size_title, "bold"), command=self.data_button_event)
  292. self.data_button.place(x=self.user_button.winfo_reqwidth() + 2, y=0)
  293. self.print_button = Button(self.button_canvas, text="手动刻印", fg='white', bg='DeepSkyBlue', width=8,
  294. activebackground='white', activeforeground='DeepSkyBlue',
  295. font=("宋体", self.font_size_title, "bold"), command=self.print_button_event)
  296. # self.print_button.place(x=self.user_button.winfo_reqwidth()*3 + 4, y=0)
  297. self.bee_button = Button(self.button_canvas, text="蜂鸣器关闭", fg='black', width=12,
  298. font=("宋体", self.font_size_text), command=self.bee_button_event)
  299. if self.user_var.bee_stat == True:
  300. self.bee_button.configure(relief=RAISED)
  301. else:
  302. self.bee_button.configure(relief=SUNKEN)
  303. self.bee_button.place(x=self.button_canvas.winfo_reqwidth() - self.bee_button.winfo_reqwidth()-5, y=5)
  304. self.button_canvas.place(x=10, y=self.screen_height - 60)
  305. # 工单栏
  306. def order_frame_init(self):
  307. self.order_frame = Frame(self.main_frame, width=self.screen_width - 20, relief=SUNKEN, borderwidth=2,
  308. height=self.screen_height - self.title_canvas.winfo_reqheight() - self.button_canvas.winfo_reqheight() - 35)
  309. # 工单栏展示
  310. self.order_frame.place(x=12, y=self.title_canvas.winfo_reqheight() + 15)
  311. # 产品信息
  312. self.product_frame = Frame(self.order_frame, width=self.order_frame.winfo_reqwidth() - 4, height=100,
  313. relief=SUNKEN, borderwidth=2)
  314. self.worklabel = Label(self.product_frame, text=" 状态信息 ", fg='black', font=("宋体", self.font_size_text), bg='PaleGreen', anchor='w')
  315. self.worklabel.place(x=1, y=1)
  316. # 系统当前状态
  317. self.workstatcanvas = Canvas(self.product_frame, bg='black', width=self.product_frame.winfo_reqwidth() - 8,
  318. height=25)
  319. self.workstatlabel = Label(self.workstatcanvas, fg='Gold', font=("宋体", self.font_size_text), bg='black',
  320. anchor='w')
  321. self.workstatlabel.place(x=2, y=5)
  322. self.productstatlabel = Label(self.workstatcanvas, fg='Red', font=("宋体", self.font_size_text), bg='black',
  323. anchor='w')
  324. self.productstatlabel.place(x=self.workstatcanvas.winfo_reqwidth() - 500, y=5)
  325. self.opcstatlabel = Label(self.workstatcanvas, fg='Red', font=("宋体", self.font_size_text), bg='black',
  326. anchor='w')
  327. self.opcstatlabel.place(x=self.workstatcanvas.winfo_reqwidth() - 250, y=5)
  328. self.socketstatlabel = Label(self.workstatcanvas, fg='Red', font=("宋体", self.font_size_text), bg='black',
  329. anchor='w')
  330. self.socketstatlabel.place(x=self.workstatcanvas.winfo_reqwidth() - 100, y=5)
  331. self.workstatcanvas.place(x=0, y=self.worklabel.winfo_reqheight() + 1)
  332. # 操作授权
  333. self.authstatframe = Frame(self.product_frame, bg='GreenYellow', width=150, height=30, relief=RAISED,
  334. borderwidth=2)
  335. self.authtitlelabel = Label(self.authstatframe, text="操作许可:", fg='black', font=("宋体", self.font_size_text),
  336. bg='GreenYellow',
  337. anchor='w')
  338. self.authtitlelabel.place(x=1, y=1)
  339. self.authlabel = Label(self.authstatframe, font=("宋体", self.font_size_text), width=6, bg='GreenYellow',
  340. anchor='w')
  341. self.authlabel.place(x=self.authtitlelabel.winfo_reqwidth(), y=1)
  342. # self.authstatlabel_value()
  343. self.authstatframe.config(height=self.authtitlelabel.winfo_reqheight()+8,
  344. width=self.authtitlelabel.winfo_reqwidth() + self.authlabel.winfo_reqwidth() + 4)
  345. self.authstatframe.place(x=1, y=self.worklabel.winfo_reqheight()+self.workstatcanvas.winfo_reqheight() + 4)
  346. # 产品编号
  347. self.product_sel_button = Button(self.product_frame, text="品番设定", fg='black', width=10,
  348. font=("宋体", self.font_size_text), command=self.produce_sel_button_event)
  349. self.product_sel_button.place(
  350. x=self.product_frame.winfo_reqwidth() - self.product_sel_button.winfo_reqwidth() - 8,
  351. y=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + 4)
  352. self.productidxlabel = Label(self.product_frame, fg='Green', font=("宋体", self.font_size_title, "bold"),
  353. bg='black', width=2,
  354. height=1, anchor='center', textvariable=self.user_var.product_idx_str)
  355. self.productstrlabel = Label(self.product_frame, fg='white', font=("宋体", self.font_size_title, "bold"),
  356. bg='black', width=30,
  357. height=1, anchor='center', textvariable=self.user_var.product_str)
  358. self.productidxlabel.place(
  359. x=self.product_frame.winfo_reqwidth() - self.product_sel_button.winfo_reqwidth() - self.productstrlabel.winfo_reqwidth() - self.productidxlabel.winfo_reqwidth() - 12,
  360. y=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + 4)
  361. self.productstrlabel.place(
  362. x=self.product_frame.winfo_reqwidth() - self.product_sel_button.winfo_reqwidth() - self.productstrlabel.winfo_reqwidth() - 10,
  363. y=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + 4)
  364. self.productnamelabel = Label(self.product_frame, text="产品\r编号", font=("宋体", self.font_size_text - 1), width=4,
  365. justify='left')
  366. self.productnamelabel.place(
  367. x=self.product_frame.winfo_reqwidth() - self.product_sel_button.winfo_reqwidth() - self.productstrlabel.winfo_reqwidth() - self.productidxlabel.winfo_reqwidth() - self.productnamelabel.winfo_reqwidth() - 14,
  368. y=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + 2)
  369. # 产品信息展示
  370. self.product_frame.config(
  371. height=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + self.authstatframe.winfo_reqheight() + 10)
  372. self.product_frame.place(x=1, y=1)
  373. # 生产数据
  374. self.order_data_frame = Frame(
  375. self.order_frame, width=self.screen_width / 4,
  376. height=self.order_frame.winfo_reqheight() - self.product_frame.winfo_reqheight() - 15,
  377. relief=SUNKEN, borderwidth=2)
  378. # 生产数据展示
  379. self.order_data_frame.place(x=1, y=self.product_frame.winfo_reqheight() + 10)
  380. self.orderdatalabel_canvas = Canvas(self.order_data_frame, bg='DeepSkyBlue',
  381. width=self.order_data_frame.winfo_reqwidth() - 10, height=25)
  382. self.orderdatalabel = Label(self.orderdatalabel_canvas, fg='black', font=("宋体", self.font_size_text),
  383. bg='DeepSkyBlue', height=1,
  384. anchor='center', text="生产数据")
  385. self.orderdatalabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 50, y=5)
  386. self.orderdatalabel_canvas.place(x=1, y=1)
  387. self.oktitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1,
  388. width=10,
  389. borderwidth=1, anchor='e', text="OK数:")
  390. self.oktitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=40)
  391. self.oklabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE,
  392. height=1, width=10,
  393. borderwidth=1, anchor='center', textvariable=self.user_var.order_ok_str)
  394. self.oklabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=40)
  395. self.ngtitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1,
  396. width=10,
  397. borderwidth=1, anchor='e', text="NG数:")
  398. self.ngtitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=80)
  399. self.nglabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE,
  400. height=1, width=10,
  401. borderwidth=1, anchor='center', textvariable=self.user_var.order_ng_str)
  402. self.nglabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=80)
  403. self.targetitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1,
  404. width=10,
  405. borderwidth=1, anchor='e', text="targe:")
  406. self.targetitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=120)
  407. self.targelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE,
  408. height=1, width=10,
  409. borderwidth=1, anchor='center', textvariable=self.user_var.order_targe_str)
  410. self.targelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=120)
  411. self.snptitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1,
  412. width=10,
  413. borderwidth=1, anchor='e', text="SNP:")
  414. self.snptitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=160)
  415. self.snplabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE,
  416. height=1, width=10,
  417. borderwidth=1, anchor='center', textvariable=self.user_var.order_snp_str)
  418. self.snplabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=160)
  419. self.yeartitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1,
  420. width=10,
  421. borderwidth=1, anchor='e', text="年份批号:")
  422. self.yeartitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=200)
  423. self.yearlabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE,
  424. height=1, width=10,
  425. borderwidth=1, anchor='center', textvariable=self.user_var.order_year_str)
  426. self.yearlabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=200)
  427. self.teamtitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1,
  428. width=10,
  429. borderwidth=1, anchor='e', text="班组选择:")
  430. self.teamtitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=240)
  431. self.team_canvas = Canvas(self.order_data_frame, bg='yellow', width=102,
  432. height=28)
  433. self.team_combobox = Combobox(self.team_canvas, font=("宋体", self.font_size_text), width=9)
  434. self.team_combobox["value"] = self.user_var.team_list
  435. # self.team_combobox.configure(state="readonly")
  436. self.team_combobox.configure(state="readonly")
  437. self.team_sel_value()
  438. self.team_combobox.bind("<<ComboboxSelected>>", self.team_combobox_sel)
  439. self.team_combobox.place(x=5, y=5)
  440. self.team_canvas.place(x=self.order_data_frame.winfo_reqwidth()/2 - 3, y=238)
  441. self.notice_canvas = Canvas(self.order_data_frame)
  442. self.noticelabel01 = Label(self.notice_canvas, fg='red', font=("宋体", self.font_size_text), anchor='center',
  443. text="注:图中")
  444. self.noticelabel01.grid(row=0, column=0)
  445. self.noticelabel02 = Label(self.notice_canvas, bg='yellow', relief=SOLID, font=("宋体", self.font_size_text - 2),
  446. anchor='center',
  447. text=" ")
  448. self.noticelabel02.grid(row=0, column=1)
  449. self.noticelabel03 = Label(self.notice_canvas, fg='red', font=("宋体", self.font_size_text), anchor='center',
  450. text="区域作业员需要选择")
  451. self.noticelabel03.grid(row=0, column=2)
  452. self.notice_canvas.place(x=3, y=self.order_data_frame.winfo_reqheight() - 25)
  453. # 气密数据
  454. self.airtightness_data_frame = Frame(
  455. self.order_frame, width=self.order_frame.winfo_reqwidth() - self.order_data_frame.winfo_reqwidth() - 8,
  456. height=160,
  457. relief=SUNKEN, borderwidth=2)
  458. # 气密数据展示
  459. self.airtightness_data_frame.place(
  460. x=self.order_data_frame.winfo_reqwidth() + 2,
  461. y=self.product_frame.winfo_reqheight() + 10)
  462. self.airtightnesstitle_canvas = Canvas(self.airtightness_data_frame, bg='DeepSkyBlue',
  463. width=self.airtightness_data_frame.winfo_reqwidth() / 3, height=25)
  464. self.airtightnesstitlelabel = Label(self.airtightnesstitle_canvas, fg='black', font=("宋体", self.font_size_text),
  465. bg='DeepSkyBlue',
  466. anchor='center', text="气密数据区")
  467. self.airtightnesstitlelabel.place(x=self.airtightnesstitle_canvas.winfo_reqwidth() / 2 - 40, y=5)
  468. self.airtightnesstitle_canvas.place(x=self.airtightness_data_frame.winfo_reqwidth() / 3, y=1)
  469. self.batchtitlelabel = Label(self.airtightness_data_frame, fg='black', font=("宋体", self.font_size_text),
  470. borderwidth=1, anchor='e', text="当前批号:", width=10)
  471. self.batchtitlelabel.place(x=10, y=40)
  472. self.batchlabel = Label(self.airtightness_data_frame, fg='black', bg='white', font=("宋体", self.font_size_text),
  473. relief=GROOVE, borderwidth=1, anchor='center', textvariable=self.user_var.batch_str,
  474. width=35, height=1)
  475. self.batchlabel.place(x=100, y=40)
  476. self.airtightness_17700titlelabel = Label(self.airtightness_data_frame, fg='black',
  477. font=("宋体", self.font_size_text),
  478. borderwidth=1, anchor='e', text="气密数据\r(17700):", width=10)
  479. self.airtightness_17700titlelabel.place(x=10, y=70)
  480. self.airtightness_17700label = Label(self.airtightness_data_frame, fg='black', bg='white',
  481. font=("宋体", self.font_size_text),
  482. relief=GROOVE,
  483. borderwidth=1, anchor='center',
  484. textvariable=self.user_var.airtightness_17700_str,
  485. width=35, height=1)
  486. self.airtightness_17700label.place(x=100, y=80)
  487. self.airtightness_17720titlelabel = Label(self.airtightness_data_frame, fg='black',
  488. font=("宋体", self.font_size_text),
  489. borderwidth=1, anchor='e', text="气密数据\r(17720):", width=10)
  490. self.airtightness_17720titlelabel.place(x=10, y=110)
  491. self.airtightness_17720label = Label(self.airtightness_data_frame, fg='black', bg='white',
  492. font=("宋体", self.font_size_text),
  493. relief=GROOVE,
  494. borderwidth=1, anchor='center',
  495. textvariable=self.user_var.airtightness_17720_str,
  496. width=35, height=1)
  497. self.airtightness_17720label.place(x=100, y=120)
  498. self.printf_numtitlelabel = Label(self.airtightness_data_frame, fg='black',
  499. font=("宋体", self.font_size_text),
  500. borderwidth=1, anchor='center', text="标签号:", width=10)
  501. self.printf_numtitlelabel.place(x=self.airtightness_data_frame.winfo_reqwidth() / 2 + 30, y=40)
  502. self.printf_numlabel = Label(self.airtightness_data_frame, fg='black', bg='white',
  503. font=("宋体", self.font_size_text),
  504. relief=GROOVE,
  505. borderwidth=1, anchor='center', textvariable=self.user_var.printf_num_str,
  506. width=25, height=1)
  507. self.printf_numlabel.place(x=self.airtightness_data_frame.winfo_reqwidth() / 2 + 120, y=40)
  508. self.serial_numtitlelabel = Label(self.airtightness_data_frame, fg='black',
  509. font=("宋体", self.font_size_text),
  510. borderwidth=1, anchor='center', text="流水号:", width=10)
  511. self.serial_numtitlelabel.place(x=self.airtightness_data_frame.winfo_reqwidth() / 2 + 30, y=80)
  512. self.serial_numlabel = Label(self.airtightness_data_frame, fg='black', bg='white',
  513. font=("宋体", self.font_size_text),
  514. relief=GROOVE,
  515. borderwidth=1, anchor='center', textvariable=self.user_var.serial_num_str,
  516. width=25, height=1)
  517. self.serial_numlabel.place(x=self.airtightness_data_frame.winfo_reqwidth() / 2 + 120, y=80)
  518. # 设备信号
  519. self.dev_signal_frame = Frame(
  520. self.order_frame, width=self.order_frame.winfo_reqwidth() - self.order_data_frame.winfo_reqwidth() - 8,
  521. height=self.order_data_frame.winfo_reqheight() - self.airtightness_data_frame.winfo_reqheight()-5,
  522. relief=SUNKEN, borderwidth=2)
  523. # 设备信号展示
  524. self.dev_signal_frame.place(
  525. x=self.order_data_frame.winfo_reqwidth() + 2,
  526. y=self.product_frame.winfo_reqheight() + self.airtightness_data_frame.winfo_reqheight() + 15)
  527. self.devsignaltitle_canvas = Canvas(self.dev_signal_frame, bg='DeepSkyBlue',
  528. width=self.dev_signal_frame.winfo_reqwidth() / 3, height=30)
  529. self.devsignaltitlelabel = Label(self.devsignaltitle_canvas, fg='black', font=("宋体", self.font_size_text),
  530. bg='DeepSkyBlue',
  531. anchor='center', text="设备信号显示区")
  532. self.devsignaltitlelabel.place(x=self.airtightnesstitle_canvas.winfo_reqwidth() / 2 - 70, y=5)
  533. self.devsignaltitle_canvas.place(x=self.airtightness_data_frame.winfo_reqwidth() / 3, y=1)
  534. self.airtightdevtitlelabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  535. anchor='center', text="气密机")
  536. self.motordevtitlelabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  537. anchor='center', text="移动电机")
  538. self.airtightdevtitlelabel.place(x=10, y=1)
  539. self.motordevtitlelabel.place(x=self.dev_signal_frame.winfo_reqwidth() - 80, y=1)
  540. self.originchkoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  541. relief=SOLID,
  542. borderwidth=1, anchor='center', text="点检OK",
  543. width=10, height=1)
  544. self.originchkoklabel.place(x=10, y=40)
  545. self.upairtightoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  546. relief=SOLID,
  547. borderwidth=1, anchor='center', text="上气密OK",
  548. width=10, height=1)
  549. self.upairtightoklabel.place(x=100, y=40)
  550. self.upairtightnglabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  551. relief=SOLID,
  552. borderwidth=1, anchor='center', text="上气密NG",
  553. width=10, height=1)
  554. self.upairtightnglabel.place(x=190, y=40)
  555. self.upprintoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  556. relief=SOLID,
  557. borderwidth=1, anchor='center', text="上刻印完成",
  558. width=10, height=1)
  559. self.upprintoklabel.place(x=280, y=40)
  560. self.origindirlabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  561. relief=SOLID,
  562. borderwidth=1, anchor='center', text="原点指示",
  563. width=10, height=1)
  564. self.origindirlabel.place(x=10, y=70)
  565. self.downairtightoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  566. relief=SOLID,
  567. borderwidth=1, anchor='center', text="下气密OK",
  568. width=10, height=1)
  569. self.downairtightoklabel.place(x=100, y=70)
  570. self.downairtightnglabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  571. relief=SOLID,
  572. borderwidth=1, anchor='center', text="下气密NG",
  573. width=10, height=1)
  574. self.downairtightnglabel.place(x=190, y=70)
  575. self.downprintoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  576. relief=SOLID,
  577. borderwidth=1, anchor='center', text="下刻印完成",
  578. width=10, height=1)
  579. self.downprintoklabel.place(x=280, y=70)
  580. self.airtightdev_value()
  581. self.motororiginoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  582. relief=SOLID,
  583. borderwidth=1, anchor='center', text="电机原点正确",
  584. width=12, height=1)
  585. self.motororiginoklabel.place(x=self.dev_signal_frame.winfo_reqwidth()-220, y=40)
  586. self.motoronuplabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  587. relief=SOLID,
  588. borderwidth=1, anchor='center', text="电机于上工位",
  589. width=12, height=1)
  590. self.motoronuplabel.place(x=self.dev_signal_frame.winfo_reqwidth()-110, y=40)
  591. self.motorunuselabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  592. relief=SOLID,
  593. borderwidth=1, anchor='center', text="未使用",
  594. width=12, height=1)
  595. self.motorunuselabel.place(x=self.dev_signal_frame.winfo_reqwidth() - 220, y=70)
  596. self.motorondownlabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  597. relief=SOLID,
  598. borderwidth=1, anchor='center', text="电机于下工位",
  599. width=12, height=1)
  600. self.motorondownlabel.place(x=self.dev_signal_frame.winfo_reqwidth() - 110, y=70)
  601. self.motordev_value()
  602. self.upstationlabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  603. anchor='center', text="上工作位",
  604. width=10, height=1)
  605. self.upstationlabel.place(x=10, y=125)
  606. self.upgages_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1,
  607. width=60, height=25)
  608. self.upgageslabel = Label(self.upgages_canvas, font=("宋体", self.font_size_text),
  609. relief=SOLID, borderwidth=1, anchor='center', text="gage-s",
  610. width=6, height=1)
  611. self.upgageslabel.place(x=6, y=6)
  612. self.upgages_canvas.place(x=100, y=120)
  613. self.upworks_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1,
  614. width=60, height=25)
  615. self.upworkslabel = Label(self.upworks_canvas, font=("宋体", self.font_size_text),
  616. relief=SOLID, borderwidth=1, anchor='center', text="work-s",
  617. width=6, height=1)
  618. self.upworkslabel.place(x=6, y=6)
  619. self.upworks_canvas.place(x=170, y=120)
  620. self.upmpen_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1,
  621. width=60, height=25)
  622. self.upmpenlabel = Label(self.upmpen_canvas, font=("宋体", self.font_size_text),
  623. relief=SOLID, borderwidth=1, anchor='center', text="M-pen",
  624. width=6, height=1)
  625. self.upmpenlabel.place(x=6, y=6)
  626. self.upmpen_canvas.place(x=240, y=120)
  627. self.upconnect_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1,
  628. width=67, height=25)
  629. self.upconnectlabel = Label(self.upconnect_canvas, font=("宋体", self.font_size_text),
  630. relief=SOLID, borderwidth=1, anchor='center', text="connect",
  631. width=7, height=1)
  632. self.upconnectlabel.place(x=6, y=6)
  633. self.upconnect_canvas.place(x=310, y=120)
  634. self.downstationlabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text),
  635. anchor='center', text="下工作位",
  636. width=10, height=1)
  637. self.downstationlabel.place(x=10, y=165)
  638. self.downgages_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1,
  639. width=60, height=25)
  640. self.downgageslabel = Label(self.downgages_canvas, font=("宋体", self.font_size_text),
  641. relief=SOLID, borderwidth=1, anchor='center', text="gage-s",
  642. width=6, height=1)
  643. self.downgageslabel.place(x=6, y=6)
  644. self.downgages_canvas.place(x=100, y=160)
  645. self.downworks_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1,
  646. width=60, height=25)
  647. self.downworkslabel = Label(self.downworks_canvas, font=("宋体", self.font_size_text),
  648. relief=SOLID, borderwidth=1, anchor='center', text="work-s",
  649. width=6, height=1)
  650. self.downworkslabel.place(x=6, y=6)
  651. self.downworks_canvas.place(x=170, y=160)
  652. self.downmpen_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1,
  653. width=60, height=25)
  654. self.downmpenlabel = Label(self.downmpen_canvas, font=("宋体", self.font_size_text),
  655. relief=SOLID, borderwidth=1, anchor='center', text="M-pen",
  656. width=6, height=1)
  657. self.downmpenlabel.place(x=6, y=6)
  658. self.downmpen_canvas.place(x=240, y=160)
  659. self.downconnect_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1,
  660. width=67, height=25)
  661. self.downconnectlabel = Label(self.downconnect_canvas, font=("宋体", self.font_size_text),
  662. relief=SOLID, borderwidth=1, anchor='center', text="connect",
  663. width=7, height=1)
  664. self.downconnectlabel.place(x=6, y=6)
  665. self.downconnect_canvas.place(x=310, y=160)
  666. class my_main(Frame):
  667. def __init__(self, init_window_name):
  668. global user_var
  669. self.init_window_name = init_window_name
  670. self.user_var = user_var
  671. self.screen_width = self.init_window_name.winfo_screenwidth()
  672. self.screen_height = self.init_window_name.winfo_screenheight()
  673. self.set_init_window()
  674. my_gui(self.init_window_name)
  675. # 设置窗口
  676. def set_init_window(self):
  677. self.init_window_name.title("气密测试") # 窗口名
  678. self.init_window_name.resizable(width=False, height=False)
  679. # self.init_window_name.geometry('%dx%d' % (self.screen_width, self.screen_height)) #定义窗口弹出时的默认展示大小和位置
  680. # self.init_window_name.state("zoomed")
  681. # self.init_window_name.overrideredirect(True)
  682. # self.init_window_name["bg"] = "black" #窗口背景色,其他背景色见:blog.csdn.net/chl0000/article/details/7657887
  683. # self.init_window_name.attributes("-alpha", 1) #虚化,值越小虚化程度越高
  684. # label.grid(row=0, column=2, rowspan=2, columnspan=2, sticky=W + E + N + S, padx=5, pady=5) # 合并两行,两列,居中,四周外延5个长度
  685. def on_closing(self):
  686. if self.user_var.auth_stat == True:
  687. message = tkinter.messagebox.askokcancel(title='提示', message='是否退出程序?')
  688. if(message == True):
  689. print("application is closed!")
  690. while self.user_var.pro_exit_stat == False:
  691. thread_work.exit()
  692. thread_opc.exit()
  693. thread_tcp.exit()
  694. time.sleep(2)
  695. init_window.destroy()
  696. sys.exit(0)
  697. else:
  698. tkinter.messagebox.showwarning(title='提示', message='请登录后操作!')
  699. def gui_start():
  700. global init_window
  701. global user_var
  702. ZMJ_PORTAL = my_main(init_window)
  703. thread_opc.start()
  704. thread_tcp.start()
  705. thread_work.start()
  706. thread_ezcad.start()
  707. # 设置根窗口默认属性
  708. ZMJ_PORTAL.set_init_window()
  709. init_window.protocol("WM_DELETE_WINDOW", ZMJ_PORTAL.on_closing)
  710. init_window.mainloop() #父窗口进入事件循环,可以理解为保持窗口运行,否则界面不展示