TK-Nodescanner.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Valid-License-Identifier: GPL-2.0-only
  5. SPDX-URL: https://spdx.org/licenses/GPL-2.0-only.html
  6. (c) 2012 micha@librelight.de
  7. """
  8. import os
  9. import time
  10. import struct
  11. import sys
  12. import tkinter as Tkinter
  13. import _thread as thread
  14. import nodescan
  15. #import nodescan2 #as nodescaner
  16. title = "TK-ArtNet-Nodscaner"
  17. sys.stdout.write("\x1b]2;"+title+"\x07")
  18. #lock.acquire()
  19. #lock.release()
  20. class LOCK_BUF():
  21. def __init__(self):
  22. self.data = []
  23. self.lock = thread.allocate_lock()
  24. def append(self,data):
  25. try:
  26. self.lock.acquire()
  27. self.data.append(data)
  28. finally:
  29. self.lock.release()
  30. def set(self,data):
  31. try:
  32. self.lock.acquire()
  33. self.data = data[:]
  34. finally:
  35. self.lock.release()
  36. def get(self):
  37. out = []
  38. try:
  39. self.lock.acquire()
  40. out = self.data[:]
  41. finally:
  42. self.lock.release()
  43. return out
  44. node_list = LOCK_BUF() #[]
  45. def fill_form(event=None):
  46. print(sys._getframe().f_code.co_name)
  47. global node_list
  48. clear_form()
  49. node_list2 = node_list.get()
  50. sel=0
  51. try:
  52. csel = li_nodes.curselection()[0]
  53. except Exception as e:
  54. print("ERR no node selected in node-list:",e)
  55. return 0
  56. print("+++",[csel,len(node_list2)])
  57. try:
  58. sel = int(li_nodes.get(csel).split()[0])-1
  59. except:
  60. print("ERR no leeding number in Listbox.line" )
  61. return 0
  62. if not node_list2:
  63. return 0
  64. print("INFO: sel,node_list2",sel,len(node_list2))
  65. e_ip.configure(state='normal')
  66. e_ip.insert("end",node_list2[sel]["IP"].replace("[","").replace("]",""))
  67. #e_ip.configure(state='readonly')
  68. e_ip_new.insert("end",node_list2[sel]["IP"].replace("[","").replace("]",""))
  69. e_mac.delete("0","end")
  70. e_mac.insert("end",node_list2[sel]["MAC"].replace("[","").replace("]",""))
  71. e_mac2.delete("0","end")
  72. e_mac2.insert("end",node_list2[sel]["MAC"].split(":")[-1])
  73. print("load",node_list2[sel])
  74. e_lname.delete("0","end")
  75. e_lname.insert("end",node_list2[sel]["lname"])
  76. e_sname.delete("0","end")
  77. e_sname.insert("end",node_list2[sel]["sname"])
  78. e_artnet_uni1.delete("0","end")
  79. univ = "0"
  80. try:
  81. if node_list2[sel]["PortTypes"][0] == "@":
  82. univ = ord(node_list2[sel]["SwIn"][0])
  83. else:
  84. univ = ord(node_list2[sel]["SwOut"][0])
  85. except Exception as e:
  86. print("load Exception",e)
  87. MSG["text"] = e
  88. MSG["bg"] = "red"
  89. e_artnet_uni1.insert("end",univ)
  90. def clear_form():
  91. print(sys._getframe().f_code.co_name)
  92. e_ip.configure(state='normal')
  93. e_ip.delete("0","end")
  94. e_ip.configure(state='readonly')
  95. e_ip_new.delete("0","end")
  96. e_mac.delete("0","end")
  97. e_mac2.delete("0","end")
  98. e_lname.delete("0","end")
  99. e_sname.delete("0","end")
  100. e_artnet_uni1.delete("0","end")
  101. def clear_node_list():
  102. print(sys._getframe().f_code.co_name)
  103. li_nodes.delete("0","end")
  104. def poll(delay=1,ip=""):
  105. print(sys._getframe().f_code.co_name)
  106. if not ip:
  107. ip = p_variable.get()
  108. b_scan.insert("end", "ArtNetPoll -> "+str(ip)+"\n")
  109. nodescan.ArtNet_poll(ip)
  110. time.sleep(1)
  111. fill_form()
  112. def clear(event= None):
  113. print(sys._getframe().f_code.co_name)
  114. clear_node_list()
  115. clear_form()
  116. def poll_loop():
  117. print(sys._getframe().f_code.co_name)
  118. time.sleep(1)
  119. while 1:
  120. poll()
  121. time.sleep(1)
  122. old_tick = 0
  123. rx = nodescan.ArtNetNodes()
  124. #rx = nodescan2
  125. def scan():
  126. print(sys._getframe().f_code.co_name)
  127. global rx,node_list,old_tick,Scrollbar
  128. print("get node from cache " )
  129. li_nodes.insert("end",str("----"))
  130. rx.loop()
  131. while 1:
  132. try:
  133. _scan()
  134. except Exception as e:
  135. print("_scan Exception as",e,e.argv[0])
  136. MSG["text"] = e
  137. MSG["bg"] = "red"
  138. time.sleep(0.3)
  139. def _scan():
  140. #print(sys._getframe().f_code.co_name)
  141. global rx,node_list,old_tick,Scrollbar
  142. tick = rx.tick()
  143. if tick == old_tick:
  144. return 0
  145. old_tick=tick
  146. nodes = rx.get()
  147. rx.clear()
  148. ok=0
  149. for n in nodes:
  150. if n not in node_list.get():
  151. node_list.append(n)
  152. ok=1
  153. if ok:
  154. refresh_node_list()
  155. def refresh_node_list():
  156. print(sys._getframe().f_code.co_name)
  157. #aprint(len(nodes))
  158. li_node_scroll = li_nodes.yview()
  159. li_nodes.delete("0","end")
  160. node_nr = 1
  161. nodesB = {}
  162. for node in node_list.get(): #nodes:
  163. k = node["MAC"]
  164. nodesB[k] = node
  165. print("k",nodesB.keys())
  166. k_sort = list(nodesB.keys())
  167. k_sort.sort()
  168. node_list.set([]) # =[]
  169. for k in k_sort:
  170. node_list.append(nodesB[k])
  171. print("k sort",k_sort)
  172. for k in k_sort:
  173. node = nodesB[k]
  174. li_nodes.insert("end",str(node_nr).rjust(3," ") +" "+ node["lname"])
  175. bg = "lightgrey"
  176. color = li_nodes.itemconfig("end", bg=bg)
  177. ip = str(node_nr).rjust(3," ") +" "+ node["IP"]
  178. bg = ""
  179. if "PortTypes" in node:
  180. if not node["PortTypes"]:
  181. pass
  182. if node["PortTypes"][0] == "@":
  183. ip += " DMX-in"
  184. bg ="yellow"
  185. else:
  186. ip += " DMX-out"
  187. bg ="lightgreen"
  188. if bg:
  189. color = li_nodes.itemconfig("end", bg=bg)
  190. li_nodes.insert("end",str(node_nr).rjust(3," ") +" short Name:"+ node["sname"])
  191. li_nodes.insert("end",ip)
  192. if bg:
  193. color = li_nodes.itemconfig("end", bg=bg)
  194. inout = " UNIVERS OUT="+ str(ord(node["SwOut"][0]))+" IN="+ str(ord(node["SwIn"][0]))
  195. li_nodes.insert("end",str(node_nr).rjust(3," ") + inout)
  196. li_nodes.insert("end",str(node_nr).rjust(3," ") +" MAC:"+ node["MAC"])
  197. last_change=time.time()-float(node["UPDATESTAMP"])
  198. timeline = ""
  199. timeline += " LASTCHANGE:%0.1f"% (last_change)
  200. REFRESHSTAMP = time.time()-float(node["REFRESHSTAMP"])
  201. timeline +=" LASTPING:%0.1f"% REFRESHSTAMP
  202. li_nodes.insert("end",str(node_nr).rjust(3," ") +timeline )
  203. if last_change > 10:
  204. color = li_nodes.itemconfig("end", bg="ORANGE")
  205. if node["BOOT"]:
  206. BOOT = time.time()-float(node["BOOT"])
  207. else:
  208. BOOT = 0
  209. timeline =" BOOT:%0.1f"% BOOT
  210. li_nodes.insert("end",str(node_nr).rjust(3," ") +timeline +" sec" )
  211. bg = ""
  212. if bg:
  213. li_nodes.itemconfig("end", bg=bg)
  214. li_nodes.insert("end","*"*60)
  215. node_nr += 1
  216. #node_list += [node]
  217. print("scroll:",li_node_scroll)
  218. def get_new_ip(event=None):
  219. print(sys._getframe().f_code.co_name)
  220. b = e_ip_new.get().replace("[","").replace("]","")
  221. return b
  222. def get_new_ip_str(event=None):
  223. print(sys._getframe().f_code.co_name)
  224. x = get_new_ip()
  225. #x = x[1:-1]
  226. x = x.strip()
  227. #x = x.replace(",",".")
  228. x = x.replace(" ","")
  229. x = x.split(",")
  230. print( "get_new_ip_str",x)
  231. return x
  232. def send_artaddr(event=None):
  233. print(sys._getframe().f_code.co_name)
  234. ln = e_lname.get()
  235. sn = e_sname.get()
  236. ip = e_ip_new.get()
  237. ip = ip.replace(" ","")
  238. ip = ip.replace(",",".")
  239. univ = e_artnet_uni1.get()
  240. print("SEND ArtAddress:",[ln,sn,ip,univ])
  241. if ln and sn and ip and univ:
  242. nodescan.ArtAddress(ip=ip ,ShortName=sn, LongName=ln,Port="",Universes=univ)
  243. time.sleep(1)
  244. poll()
  245. def send_none(event=None):
  246. print(sys._getframe().f_code.co_name)
  247. pass
  248. def send_mac(event=None):
  249. print(sys._getframe().f_code.co_name)
  250. #new_mac = "CMD MAC6 " + hex(e_mac2.get()) #)
  251. #new_mac = "CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16))).decode()
  252. new_mac = b"CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16)))
  253. a = e_ip.get().replace("[","").replace("]","")
  254. cur_ip = []
  255. for i in a.split(","):
  256. cur_ip +=[int(i)]
  257. print("SEND MAC:",cur_ip,new_mac)
  258. nodescan.send_node_cmd(cur_ip,cmd=new_mac)
  259. #poll(delay=1.5)
  260. def send_dmx_store(event=None):
  261. print(sys._getframe().f_code.co_name)
  262. cmd = "CMD DMX STORE "
  263. a = e_ip.get().replace("[","").replace("]","")
  264. cur_ip = []
  265. for i in a.split(","):
  266. cur_ip +=[int(i)]
  267. print("SEND:",cur_ip,cmd)
  268. nodescan.send_node_cmd(cur_ip,cmd)
  269. poll(delay=1.5)
  270. def send_cmd(event=None):
  271. print(sys._getframe().f_code.co_name)
  272. cmd = e_cmd.get() #"CMD DMX STORE "
  273. _send_cmd(cmd=cmd)
  274. def send_cmd2(event=None):
  275. print(sys._getframe().f_code.co_name)
  276. cmd = e_cmd2.get() #"CMD DMX STORE "
  277. _send_cmd(cmd=cmd)
  278. def send_cmd3(event=None):
  279. print(sys._getframe().f_code.co_name)
  280. cmd = e_cmd3.get() #"CMD DMX STORE "
  281. _send_cmd(cmd=cmd)
  282. def send_cmd4(event=None):
  283. print(sys._getframe().f_code.co_name)
  284. cmd = e_cmd4.get() #"CMD DMX STORE "
  285. _send_cmd(cmd=cmd)
  286. def send_cmd5(event=None):
  287. print(sys._getframe().f_code.co_name)
  288. cmd = e_cmd5.get() #"CMD DMX STORE "
  289. _send_cmd(cmd=cmd)
  290. def _send_cmd(event=None,cmd=""):
  291. print(sys._getframe().f_code.co_name)
  292. #cmd = e_cmd.get() #"CMD DMX STORE "
  293. cmd = cmd.split(" ")
  294. value = cmd[-1]
  295. try:
  296. value = struct.pack("<B",int(value))
  297. except:pass
  298. cmd = cmd[:-1] #.append(value)
  299. cmd.append(value)
  300. print("_send_cmd:",cmd)
  301. cmd=" ".join(map(str,cmd) )
  302. a = e_ip.get().replace("[","").replace("]","")
  303. cur_ip = []
  304. sep = "xx"
  305. if "," in a:
  306. sep = ","
  307. if "." in a:
  308. sep = "."
  309. for i in a.split(sep):
  310. cur_ip +=[int(i)]
  311. print("SEND:",cur_ip,cmd)
  312. nodescan.send_node_cmd(cur_ip,cmd)
  313. #poll(delay=1.5)
  314. def kill_librelight(event=None):
  315. print(sys._getframe().f_code.co_name)
  316. #for i in ["CONSOLE.py","EDITOR.py","ASP"]:
  317. for i in ["ASP"]:
  318. cmd='screen -XS "{}" quit | echo ""'.format(i)
  319. print(cmd)
  320. os.system(cmd)
  321. cmd="screen -ls"
  322. os.system(cmd)
  323. time.sleep(1)
  324. BASE_PATH = "/opt/LibreLight/Xdesk/"
  325. cmd="_LibreLightDesk.py"
  326. cmd="tool/TK-Nodescanner.py" #&"
  327. arg = ""
  328. os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
  329. def start_librelight(event=None):
  330. print(sys._getframe().f_code.co_name)
  331. #for i in ["CONSOLE.py","EDITOR.py","ASP"]:
  332. for i in ["ASP"]:
  333. cmd='screen -XS "{}" quit | echo ""'.format(i)
  334. print(cmd)
  335. os.system(cmd)
  336. nodescan.is_running = 0 # exit all thread loop's
  337. root.quit()
  338. time.sleep(0.5)
  339. BASE_PATH = "/opt/LibreLight/Xdesk/"
  340. cmd="init/10-ASP.sh"
  341. arg = ""
  342. os.system(cmd)
  343. #os.execl("/usr/bin/sh", BASE_PATH, cmd,arg)
  344. def set_ip(event=None):
  345. print(sys._getframe().f_code.co_name)
  346. print("SET NEW IP")
  347. cur_ip=(2,0,0,94)
  348. new_ip=(2,0,0,201)
  349. new_netmask=(255,0,0,0)
  350. a = e_ip.get().replace("[","").replace("]","")
  351. b = e_ip_new.get().replace("[","").replace("]","")
  352. c = variable.get() #e_mask_new.get()
  353. new_netmask = [] #c.split(".") #list(c)
  354. for i in c.split("."):
  355. new_netmask +=[int(i)]
  356. cur_ip = []
  357. for i in a.split(","):
  358. cur_ip +=[int(i)]
  359. new_ip = []
  360. for i in b.split(","):
  361. new_ip +=[int(i)]
  362. if new_ip == cur_ip:
  363. print("neu und als IP sind gleich" )
  364. return 0
  365. #cur_ip=(2,0,0,94)
  366. #new_ip=(2,0,0,201)
  367. print("new",[cur_ip, new_ip, new_netmask])
  368. print()
  369. nodescan.set_ip4(cur_ip,new_ip, new_netmask)
  370. poll(delay=1.5)
  371. def set_node_pin(evnet=None):
  372. print(sys._getframe().f_code.co_name)
  373. cmd = "CMD DMX=PIN"
  374. ip = get_new_ip_str()
  375. print("ip",[ip])
  376. nodescan.send_node_cmd(ip,cmd=cmd)
  377. poll(delay=1.5)
  378. def set_node_in(evnet=None):
  379. print(sys._getframe().f_code.co_name)
  380. cmd="CMD DMX=IN"
  381. ip = get_new_ip_str()
  382. nodescan.send_node_cmd(ip,cmd=cmd)
  383. poll(delay=1.5)
  384. def set_node_out(evnet=None):
  385. print(sys._getframe().f_code.co_name)
  386. cmd="CMD DMX=OUT"
  387. ip = get_new_ip_str()
  388. nodescan.send_node_cmd(ip,cmd=cmd)
  389. poll(delay=1.5)
  390. root = Tkinter.Tk()
  391. #root.geometry("900x700+100+100")
  392. root.geometry("700x600+100+100")
  393. root.title( title)
  394. fframe = Tkinter.Frame(root)
  395. fframe.pack(side="top",expand=0,fill="x")
  396. cframe = Tkinter.Frame(root)
  397. cframe.pack(side="top",expand=1,fill="both")
  398. font1 = ("Helvetica", 8)
  399. font2 = ("Helvetica", 12) # 10
  400. font3 = ("Helvetica", 12) # 16
  401. font20 = font=("Helvetica", 12) # 22
  402. font120 = font=("Helvetica", 22) # 22
  403. b_scan = Tkinter.Button(fframe,text="refresh list",width=8,command=refresh_node_list,font=font2)
  404. b_scan.pack(side="left",expand=0,fill="y")
  405. b_scan = Tkinter.Button(fframe,text="ArtNetPoll ->",width=10,command=poll,font=font2)
  406. b_scan.configure(bg="#0f0")
  407. b_scan.pack(side="left",expand=0,fill="y")
  408. #POLL ['192.168.0.255', 6454] OK ;
  409. #POLL ['192.168.0.99', 6454] OK ;
  410. #POLL ['2.255.255.255', 6454] OK ;
  411. #POLL ['2.0.0.255', 6454] OK ;
  412. #POLL ['2.255.255.255', 6454] OK ;
  413. def get_ips():
  414. local_ips = []
  415. #local_ips.append("2.0.0.255")
  416. cmd='ip a | grep " inet " | cut -d " " -f 6 | sort -h'
  417. r=os.popen(cmd)
  418. print("cmd",cmd)
  419. txt=r.readlines()
  420. for ip in txt:
  421. ip = ip.strip()
  422. print([ip])
  423. if ip.startswith("127."):
  424. continue
  425. if ip.count(".") != 3:
  426. continue
  427. if ip.endswith("/24"):
  428. ip = ip.split(".")
  429. ip = ".".join(ip[:3])+".255"
  430. elif ip.endswith("/8"):
  431. ip = ip.split(".")
  432. ip = ".".join(ip[0])+".255.255.255"
  433. else:
  434. continue
  435. print("-",ip)
  436. if ip == "2.255.255.255":
  437. print("- workaround -")
  438. local_ips.append("2.0.0.255")
  439. local_ips.append(ip)
  440. return local_ips
  441. local_ips =get_ips()
  442. option_list=local_ips
  443. p_variable = Tkinter.StringVar(root)
  444. p_variable.set(option_list[0]) # default value
  445. e_poll_new = Tkinter.OptionMenu(fframe, p_variable,*option_list,)
  446. e_poll_new.configure(font=("Helvetica", 13))
  447. e_poll_new.configure(width=13)
  448. e_poll_new["bg"] = "#fff"
  449. #print(dir(e_poll_new))
  450. e_poll_new.option_add("end","") #', 'option_clear', 'option_get
  451. e_poll_new.option_add("end","215.0.0.0")
  452. e_poll_new.pack(side="left")
  453. #exit()
  454. b_scan = Tkinter.Button(fframe,text="Librelight:",font=font2,relief="flat",bg="orange")
  455. b_scan.pack(side="left",expand=0)
  456. b_scan = Tkinter.Button(fframe,text="KILL !",command=kill_librelight,width=6,font=font2,bg="red")
  457. b_scan.pack(side="left",expand=0)
  458. b_scan = Tkinter.Button(fframe,text="START ",command=start_librelight,width=6,font=font2,bg="green")
  459. b_scan.pack(side="left",expand=0)
  460. scrollbar = Tkinter.Scrollbar(cframe)
  461. scrollbar.pack(side=Tkinter.RIGHT, fill="y")
  462. #pool = Tkinter.Listbox(root,selectmode="extended",exportselection=0)
  463. li_nodes = Tkinter.Listbox(cframe,exportselection=0,width=35,font=font1)
  464. li_nodes.pack(side="left",expand=0,fill="y")
  465. li_nodes.bind("<ButtonRelease-1>",fill_form )
  466. li_nodes.config(yscrollcommand=scrollbar.set)
  467. scrollbar.config(command=li_nodes.yview)
  468. eframe = Tkinter.Frame(cframe)
  469. eframe.pack(side="left",expand=0,fill="y")
  470. eframe1 = Tkinter.Frame(cframe)
  471. eframe1.pack(side="left",expand=0,fill="y")
  472. # ----------------------------------------------
  473. line_frame = Tkinter.Frame(eframe)
  474. line_frame.pack(side="top",expand=0,fill="x")
  475. x=Tkinter.Label(line_frame,text=" ",font=font2,width=6)
  476. c= Tkinter.Label(line_frame,text=" ",font=font1,width=30,anchor="w")
  477. c.pack(side="left",expand=0,fill="y")
  478. # ----------------------------------------------
  479. # ----------------------------------------------
  480. line_frame = Tkinter.Frame(eframe)
  481. line_frame.pack(side="top",expand=0,fill="x")
  482. x=Tkinter.Label(line_frame,text="MSG:",font=font3,width=6)
  483. x.pack(side="left",expand=0,fill="y")
  484. x.configure(bg="darkgrey")
  485. MSG = Tkinter.Label(line_frame,text="xxx",font=font1,width=30,anchor="w")
  486. MSG.pack(side="left",expand=0,fill="y")
  487. MSG.configure(bg="darkgrey")
  488. #msg["bg"] = "lightgrey"
  489. #msg.pack(side="left")
  490. # ----------------------------------------------
  491. line_frame = Tkinter.Frame(eframe)
  492. line_frame.pack(side="top",expand=0,fill="x")
  493. c= Tkinter.Label(line_frame,text=" ",font=font120,width=30,anchor="w")
  494. c.pack(side="left",expand=0,fill="y")
  495. # ----------------------------------------------
  496. line_frame = Tkinter.Frame(eframe)
  497. line_frame.pack(side="top",expand=0,fill="x")
  498. Tkinter.Label(line_frame,text="OLD IP:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  499. e_ip = Tkinter.Entry(line_frame,font=font20,width=26,state="disabled")
  500. e_ip["bg"] = "lightgrey"
  501. e_ip.pack(side="left")
  502. b_scan = Tkinter.Button(line_frame,text="clean",font=font2,relief="flat",command=clear_form)
  503. b_scan.pack(side="left",expand=0)
  504. #b_scan = Tkinter.Button(line_frame,width=14,font=font3)
  505. #b_scan.pack(side="left",expand=1)
  506. # ----------------------------------------------
  507. line_frame = Tkinter.Frame(eframe)
  508. line_frame.pack(side="top",expand=0,fill="x")
  509. e_ip_label = Tkinter.Label(line_frame,text=" IP:",font=font3,width=6)
  510. e_ip_label.pack(side="left",expand=0,fill="y")
  511. e_ip_new = Tkinter.Entry(line_frame,font=font20,width=26)
  512. e_ip_new.bind("<Return>", set_ip )
  513. e_ip_new.bind("<KP_Enter>", set_ip)
  514. #e_ip_new.bind("<Tab>", update_name)
  515. e_ip_new.bind("<ISO_Left_Tab>", set_ip)
  516. e_ip_new.pack(side="left")
  517. #-------------------------------------------- line
  518. line_frame = Tkinter.Frame(eframe)
  519. line_frame.pack(side="top",expand=0,fill="x")
  520. variable = Tkinter.StringVar(root)
  521. variable.set("255.0.0.0") # default value
  522. Tkinter.Label(line_frame,text="MASK:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  523. e_mask_new = Tkinter.OptionMenu(line_frame, variable,"255.255.255.0","255.0.0.0") #,width=10)
  524. e_mask_new.configure(font=("Helvetica", 12))
  525. e_mask_new.configure(width=12)
  526. e_mask_new["bg"] = "#fff"
  527. #heigh=1,font=("Helvetica", 20)
  528. e_mask_new.pack(side="left")
  529. e=Tkinter.Label(line_frame,text="")
  530. e.configure(width=11)
  531. e.pack(side="left")
  532. #e_mask_new.insert("end","255.0.0.0")
  533. #e_mask_new.insert("end","255.255.255.0")
  534. b_scan = Tkinter.Button(line_frame,text="SEND TO NODE",command=set_ip,width=14,font=font1)
  535. b_scan.pack(side="left",expand=0)
  536. #-------------------------------------------- line
  537. line_frame = Tkinter.Frame(eframe)
  538. line_frame.pack(side="top",expand=0,fill="x")
  539. Tkinter.Label(line_frame,text="MAC:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  540. e_mac = Tkinter.Entry(line_frame,width=23,font=font20)
  541. e_mac.pack(side="left")
  542. e_mac["bg"] = "lightgrey"
  543. e_mac2 = Tkinter.Entry(line_frame,width=3,font=font20)
  544. e_mac2.pack(side="left")
  545. e_mac2.bind("<Return>", send_mac )
  546. e_mac2.bind("<KP_Enter>", send_mac)
  547. Tkinter.Button(line_frame,text="SEND TO NODE",command=send_mac,width=14,font=font1).pack(side="left",expand=0)
  548. # ----------------------------------------------
  549. line_frame = Tkinter.Frame(eframe)
  550. line_frame.pack(side="top",expand=0,fill="x")
  551. c= Tkinter.Label(line_frame,text=" ",font=font120,width=30,anchor="w")
  552. c.pack(side="left",expand=0,fill="y")
  553. # ----------------------------------------------
  554. #-------------------------------------------- line
  555. #b_scan = Tkinter.Button(eframe1,width=14,font=font3)
  556. #b_scan.pack(side="top",expand=0)
  557. line_frame = Tkinter.Frame(eframe)
  558. line_frame.pack(side="top",expand=0,fill="x")
  559. Tkinter.Label(line_frame,text="DMX:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  560. b_set_node_pin = Tkinter.Button(line_frame,text="HW-PIN",command=set_node_pin,width=6,font=font3)
  561. b_set_node_pin.pack(side="left",expand=0)
  562. b_set_node_in = Tkinter.Button(line_frame,text="IN",command=set_node_in,width=6,font=font3)
  563. b_set_node_in.pack(side="left",expand=0)
  564. b_set_node_out = Tkinter.Button(line_frame,text="OUT",command=set_node_out,width=6,font=font3)
  565. b_set_node_out.pack(side="left",expand=0)
  566. #-------------------------------------------- line
  567. line_frame = Tkinter.Frame(eframe)
  568. line_frame.pack(side="top",expand=0,fill="x")
  569. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  570. e_cmd = Tkinter.Entry(line_frame,font=font3,width=26)
  571. e_cmd.bind("<Return>", send_cmd )
  572. e_cmd.pack(side="left")
  573. #-------------------------------------------- line
  574. line_frame = Tkinter.Frame(eframe)
  575. line_frame.pack(side="top",expand=0,fill="x")
  576. Tkinter.Label(line_frame,text="LName",font=font3,width=6).pack(side="left",expand=0,fill="y")
  577. e_lname = Tkinter.Entry(line_frame,font=font3,width=26)
  578. e_lname.pack(side="left")
  579. #-------------------------------------------- line
  580. line_frame = Tkinter.Frame(eframe)
  581. line_frame.pack(side="top",expand=0,fill="x")
  582. Tkinter.Label(line_frame,text="SName",font=font3,width=6).pack(side="left",expand=0,fill="y")
  583. e_sname = Tkinter.Entry(line_frame,font=font3,width=26)
  584. e_sname.pack(side="left")
  585. #-------------------------------------------- line
  586. line_frame = Tkinter.Frame(eframe)
  587. line_frame.pack(side="top",expand=0,fill="x")
  588. Tkinter.Label(line_frame,text="ArtNet",font=font3,width=6).pack(side="left",expand=0,fill="y")
  589. Tkinter.Label(line_frame,text="SUB:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  590. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4,state="disabled")
  591. e_artnet_uni1.pack(side="left")
  592. Tkinter.Label(line_frame,text="NET:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  593. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4,state="disabled")
  594. e_artnet_uni1.pack(side="left")
  595. Tkinter.Label(line_frame,text="UNI:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  596. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4)
  597. e_artnet_uni1.pack(side="left")
  598. Tkinter.Button(line_frame,text="send ArtAddr",command=send_artaddr,width=14,font=font1).pack(side="left",expand=0)
  599. #-------------------------------------------- line
  600. b_scan = Tkinter.Text(eframe,width=20,font=font2)
  601. b_scan.pack(side="top",expand=1,fill="x")
  602. #-------------------------------------------- line
  603. line_frame = Tkinter.Frame(eframe1)
  604. line_frame.pack(side="top",expand=0,fill="x")
  605. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  606. e_cmd2 = Tkinter.Entry(line_frame,font=font3,width=16)
  607. e_cmd2.insert("end","DMX ERASE ")
  608. e_cmd2.bind("<Return>", send_cmd2 )
  609. e_cmd2.pack(side="left")
  610. #-------------------------------------------- line
  611. line_frame = Tkinter.Frame(eframe1)
  612. line_frame.pack(side="top",expand=0,fill="x")
  613. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  614. e_cmd3 = Tkinter.Entry(line_frame,font=font3,width=16)
  615. e_cmd3.insert("end","DMX OUT STORE ")
  616. e_cmd3.bind("<Return>", send_cmd3 )
  617. e_cmd3.pack(side="left")
  618. #-------------------------------------------- line
  619. line_frame = Tkinter.Frame(eframe1)
  620. line_frame.pack(side="top",expand=0,fill="x")
  621. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  622. e_cmd4 = Tkinter.Entry(line_frame,font=font3,width=16)
  623. e_cmd4.insert("end","DMX OUT SET 2")
  624. e_cmd4.bind("<Return>", send_cmd4 )
  625. e_cmd4.pack(side="left")
  626. #-------------------------------------------- line
  627. line_frame = Tkinter.Frame(eframe1)
  628. line_frame.pack(side="top",expand=0,fill="x")
  629. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  630. e_cmd5 = Tkinter.Entry(line_frame,font=font3,width=16)
  631. e_cmd5.insert("end","REBOOT ")
  632. e_cmd5.bind("<Return>", send_cmd5 )
  633. e_cmd5.pack(side="left")
  634. nodescan.bind_cmd_node()
  635. def network_listenet():
  636. print(sys._getframe().f_code.co_name)
  637. b_scan.insert("end", "log:\n" )
  638. while 1:
  639. if nodescan.node_cmd_buf_list:
  640. msg = str(nodescan.node_cmd_buf_list)
  641. print("read_cmd_buf msg",msg)
  642. nodescan.node_cmd_buf_list = []
  643. stamp = str(time.time())+"\n"
  644. stamp = time.strftime("%Y-%m-%d %X\n")
  645. b_scan.insert("end",stamp)
  646. b_scan.insert("end", msg +"\n")
  647. b_scan.see("end")
  648. time.sleep(0.1)
  649. def update_idletask():
  650. print(sys._getframe().f_code.co_name)
  651. while 1:
  652. time.sleep(1)
  653. root.update_idletasks()
  654. def main():
  655. print(sys._getframe().f_code.co_name)
  656. thread.start_new_thread(scan, () )
  657. thread.start_new_thread(nodescan.node_cmd_recive, () )
  658. thread.start_new_thread(network_listenet, () )
  659. thread.start_new_thread(update_idletask, () )
  660. main()
  661. root.mainloop()