TK-Nodescanner.py 24 KB

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