TK-Nodescanner_old.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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. b_scan.insert("end",cmd+"\n")
  321. os.system(cmd)
  322. cmd="screen -ls"
  323. os.system(cmd)
  324. time.sleep(1)
  325. BASE_PATH = "/opt/LibreLight/Xdesk/"
  326. cmd="_LibreLightDesk.py"
  327. cmd="tool/TK-Nodescanner.py" #&"
  328. b_scan.insert("end",cmd+"\n")
  329. arg = ""
  330. #os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
  331. global nodescan
  332. nodescan.is_running = 0 # exit all thread loop's
  333. nodescan.sock.close()
  334. time.sleep(1)
  335. nodescan.sock = nodescan.socket_warp()
  336. time.sleep(1)
  337. thread.start_new_thread(nodescan.node_cmd_recive, () )
  338. rx.loop()
  339. time.sleep(1)
  340. poll()
  341. def start_librelight(event=None):
  342. print(sys._getframe().f_code.co_name)
  343. #for i in ["CONSOLE.py","EDITOR.py","ASP"]:
  344. for i in ["ASP"]:
  345. cmd='screen -XS "{}" quit | echo ""'.format(i)
  346. print(cmd)
  347. os.system(cmd)
  348. global nodescan,rx
  349. nodescan.is_running = 0 # exit all thread loop's
  350. nodescan.sock.close()
  351. time.sleep(1)
  352. #root.quit()
  353. thread.start_new_thread(nodescan.node_cmd_recive, () )
  354. rx.loop()
  355. time.sleep(0.5)
  356. BASE_PATH = "/opt/LibreLight/Xdesk/"
  357. cmd="init/10-ASP.sh"
  358. arg = ""
  359. os.system(cmd)
  360. #os.execl("/usr/bin/sh", BASE_PATH, cmd,arg)
  361. def set_ip(event=None):
  362. print(sys._getframe().f_code.co_name)
  363. print("SET NEW IP")
  364. cur_ip=(2,0,0,94)
  365. new_ip=(2,0,0,201)
  366. new_netmask=(255,0,0,0)
  367. a = e_ip.get().replace("[","").replace("]","")
  368. b = e_ip_new.get().replace("[","").replace("]","")
  369. c = variable.get() #e_mask_new.get()
  370. new_netmask = [] #c.split(".") #list(c)
  371. for i in c.split("."):
  372. new_netmask +=[int(i)]
  373. cur_ip = []
  374. for i in a.split(","):
  375. cur_ip +=[int(i)]
  376. new_ip = []
  377. for i in b.split(","):
  378. new_ip +=[int(i)]
  379. if new_ip == cur_ip:
  380. print("neu und als IP sind gleich" )
  381. #return 0
  382. #cur_ip=(2,0,0,94)
  383. #new_ip=(2,0,0,201)
  384. print("new",[cur_ip, new_ip, new_netmask])
  385. print()
  386. nodescan.set_ip4(cur_ip,new_ip, new_netmask)
  387. poll(delay=1.5)
  388. def set_node_pin(evnet=None):
  389. print(sys._getframe().f_code.co_name)
  390. cmd = "CMD DMX=PIN"
  391. ip = get_new_ip_str()
  392. print("ip",[ip])
  393. nodescan.send_node_cmd(ip,cmd=cmd)
  394. poll(delay=1.5)
  395. def set_node_in(evnet=None):
  396. print(sys._getframe().f_code.co_name)
  397. cmd="CMD DMX=IN"
  398. ip = get_new_ip_str()
  399. nodescan.send_node_cmd(ip,cmd=cmd)
  400. poll(delay=1.5)
  401. def set_node_out(evnet=None):
  402. print(sys._getframe().f_code.co_name)
  403. cmd="CMD DMX=OUT"
  404. ip = get_new_ip_str()
  405. nodescan.send_node_cmd(ip,cmd=cmd)
  406. poll(delay=1.5)
  407. root = Tkinter.Tk()
  408. #root.geometry("900x700+100+100")
  409. root.geometry("700x600+100+100")
  410. root.title( title)
  411. fframe = Tkinter.Frame(root)
  412. fframe.pack(side="top",expand=0,fill="x")
  413. cframe = Tkinter.Frame(root)
  414. cframe.pack(side="top",expand=1,fill="both")
  415. font1 = ("Helvetica", 8)
  416. font2 = ("Helvetica", 12) # 10
  417. font3 = ("Helvetica", 12) # 16
  418. font20 = font=("Helvetica", 12) # 22
  419. font120 = font=("Helvetica", 22) # 22
  420. b_scan = Tkinter.Button(fframe,text="refresh list",width=8,command=refresh_node_list,font=font2)
  421. b_scan.pack(side="left",expand=0,fill="y")
  422. b_scan = Tkinter.Button(fframe,text="ArtNetPoll ->",width=10,command=poll,font=font2)
  423. b_scan.configure(bg="#0f0")
  424. b_scan.pack(side="left",expand=0,fill="y")
  425. #POLL ['192.168.0.255', 6454] OK ;
  426. #POLL ['192.168.0.99', 6454] OK ;
  427. #POLL ['2.255.255.255', 6454] OK ;
  428. #POLL ['2.0.0.255', 6454] OK ;
  429. #POLL ['2.255.255.255', 6454] OK ;
  430. def get_ips():
  431. local_ips = []
  432. #local_ips.append("2.0.0.255")
  433. cmd='ip a | grep " inet " | cut -d " " -f 6 | sort -h'
  434. r=os.popen(cmd)
  435. print("cmd",cmd)
  436. txt=r.readlines()
  437. for ip in txt:
  438. ip = ip.strip()
  439. print([ip])
  440. if ip.startswith("127."):
  441. continue
  442. if ip.count(".") != 3:
  443. continue
  444. if ip.endswith("/24"):
  445. ip = ip.split(".")
  446. ip = ".".join(ip[:3])+".255"
  447. elif ip.endswith("/8"):
  448. ip = ip.split(".")
  449. ip = ".".join(ip[0])+".255.255.255"
  450. else:
  451. continue
  452. print("-",ip)
  453. #if ip == "2.255.255.255":
  454. # print("- workaround -")
  455. # local_ips.append("2.0.0.255")
  456. local_ips.append(ip)
  457. return local_ips
  458. local_ips =get_ips()
  459. option_list=local_ips
  460. p_variable = Tkinter.StringVar(root)
  461. p_variable.set(option_list[0]) # default value
  462. e_poll_new = Tkinter.OptionMenu(fframe, p_variable,*option_list,)
  463. e_poll_new.configure(font=("Helvetica", 13))
  464. e_poll_new.configure(width=13)
  465. e_poll_new["bg"] = "#fff"
  466. #print(dir(e_poll_new))
  467. e_poll_new.option_add("end","") #', 'option_clear', 'option_get
  468. e_poll_new.option_add("end","215.0.0.0")
  469. e_poll_new.pack(side="left")
  470. #exit()
  471. b_scan = Tkinter.Button(fframe,text="Librelight:",font=font2,relief="flat",bg="orange")
  472. b_scan.pack(side="left",expand=0)
  473. b_scan = Tkinter.Button(fframe,text="KILL !",command=kill_librelight,width=6,font=font2,bg="red")
  474. b_scan.pack(side="left",expand=0)
  475. b_scan = Tkinter.Button(fframe,text="START ",command=start_librelight,width=6,font=font2,bg="green")
  476. b_scan.pack(side="left",expand=0)
  477. scrollbar = Tkinter.Scrollbar(cframe)
  478. scrollbar.pack(side=Tkinter.RIGHT, fill="y")
  479. #pool = Tkinter.Listbox(root,selectmode="extended",exportselection=0)
  480. li_nodes = Tkinter.Listbox(cframe,exportselection=0,width=35,font=font1)
  481. li_nodes.pack(side="left",expand=0,fill="y")
  482. li_nodes.bind("<ButtonRelease-1>",fill_form )
  483. li_nodes.config(yscrollcommand=scrollbar.set)
  484. scrollbar.config(command=li_nodes.yview)
  485. eframe = Tkinter.Frame(cframe)
  486. eframe.pack(side="left",expand=0,fill="y")
  487. eframe1 = Tkinter.Frame(cframe)
  488. eframe1.pack(side="left",expand=0,fill="y")
  489. # ----------------------------------------------
  490. line_frame = Tkinter.Frame(eframe)
  491. line_frame.pack(side="top",expand=0,fill="x")
  492. x=Tkinter.Label(line_frame,text=" ",font=font2,width=6)
  493. c= Tkinter.Label(line_frame,text=" ",font=font1,width=30,anchor="w")
  494. c.pack(side="left",expand=0,fill="y")
  495. # ----------------------------------------------
  496. # ----------------------------------------------
  497. line_frame = Tkinter.Frame(eframe)
  498. line_frame.pack(side="top",expand=0,fill="x")
  499. x=Tkinter.Label(line_frame,text="MSG:",font=font3,width=6)
  500. x.pack(side="left",expand=0,fill="y")
  501. x.configure(bg="darkgrey")
  502. MSG = Tkinter.Label(line_frame,text="xxx",font=font1,width=30,anchor="w")
  503. MSG.pack(side="left",expand=0,fill="y")
  504. MSG.configure(bg="darkgrey")
  505. #msg["bg"] = "lightgrey"
  506. #msg.pack(side="left")
  507. # ----------------------------------------------
  508. line_frame = Tkinter.Frame(eframe)
  509. line_frame.pack(side="top",expand=0,fill="x")
  510. c= Tkinter.Label(line_frame,text=" ",font=font120,width=30,anchor="w")
  511. c.pack(side="left",expand=0,fill="y")
  512. # ----------------------------------------------
  513. line_frame = Tkinter.Frame(eframe)
  514. line_frame.pack(side="top",expand=0,fill="x")
  515. Tkinter.Label(line_frame,text="OLD IP:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  516. e_ip = Tkinter.Entry(line_frame,font=font20,width=26,state="disabled")
  517. e_ip["bg"] = "lightgrey"
  518. e_ip.pack(side="left")
  519. b_scan = Tkinter.Button(line_frame,text="clean",font=font2,relief="flat",command=clear_form)
  520. b_scan.pack(side="left",expand=0)
  521. #b_scan = Tkinter.Button(line_frame,width=14,font=font3)
  522. #b_scan.pack(side="left",expand=1)
  523. # ----------------------------------------------
  524. line_frame = Tkinter.Frame(eframe)
  525. line_frame.pack(side="top",expand=0,fill="x")
  526. e_ip_label = Tkinter.Label(line_frame,text=" IP:",font=font3,width=6)
  527. e_ip_label.pack(side="left",expand=0,fill="y")
  528. e_ip_new = Tkinter.Entry(line_frame,font=font20,width=26)
  529. e_ip_new.bind("<Return>", set_ip )
  530. e_ip_new.bind("<KP_Enter>", set_ip)
  531. #e_ip_new.bind("<Tab>", update_name)
  532. e_ip_new.bind("<ISO_Left_Tab>", set_ip)
  533. e_ip_new.pack(side="left")
  534. #-------------------------------------------- line
  535. line_frame = Tkinter.Frame(eframe)
  536. line_frame.pack(side="top",expand=0,fill="x")
  537. variable = Tkinter.StringVar(root)
  538. variable.set("255.0.0.0") # default value
  539. Tkinter.Label(line_frame,text="MASK:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  540. e_mask_new = Tkinter.OptionMenu(line_frame, variable,"255.255.255.0","255.0.0.0") #,width=10)
  541. e_mask_new.configure(font=("Helvetica", 12))
  542. e_mask_new.configure(width=12)
  543. e_mask_new["bg"] = "#fff"
  544. #heigh=1,font=("Helvetica", 20)
  545. e_mask_new.pack(side="left")
  546. e=Tkinter.Label(line_frame,text="")
  547. e.configure(width=11)
  548. e.pack(side="left")
  549. #e_mask_new.insert("end","255.0.0.0")
  550. #e_mask_new.insert("end","255.255.255.0")
  551. b_scan = Tkinter.Button(line_frame,text="SEND TO NODE",command=set_ip,width=14,font=font1)
  552. b_scan.pack(side="left",expand=0)
  553. #-------------------------------------------- line
  554. line_frame = Tkinter.Frame(eframe)
  555. line_frame.pack(side="top",expand=0,fill="x")
  556. Tkinter.Label(line_frame,text="MAC:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  557. e_mac = Tkinter.Entry(line_frame,width=23,font=font20)
  558. e_mac.pack(side="left")
  559. e_mac["bg"] = "lightgrey"
  560. e_mac2 = Tkinter.Entry(line_frame,width=3,font=font20)
  561. e_mac2.pack(side="left")
  562. e_mac2.bind("<Return>", send_mac )
  563. e_mac2.bind("<KP_Enter>", send_mac)
  564. Tkinter.Button(line_frame,text="SEND TO NODE",command=send_mac,width=14,font=font1).pack(side="left",expand=0)
  565. # ----------------------------------------------
  566. line_frame = Tkinter.Frame(eframe)
  567. line_frame.pack(side="top",expand=0,fill="x")
  568. c= Tkinter.Label(line_frame,text=" ",font=font120,width=30,anchor="w")
  569. c.pack(side="left",expand=0,fill="y")
  570. # ----------------------------------------------
  571. #-------------------------------------------- line
  572. #b_scan = Tkinter.Button(eframe1,width=14,font=font3)
  573. #b_scan.pack(side="top",expand=0)
  574. line_frame = Tkinter.Frame(eframe)
  575. line_frame.pack(side="top",expand=0,fill="x")
  576. Tkinter.Label(line_frame,text="DMX:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  577. b_set_node_pin = Tkinter.Button(line_frame,text="HW-PIN",command=set_node_pin,width=6,font=font3)
  578. b_set_node_pin.pack(side="left",expand=0)
  579. b_set_node_in = Tkinter.Button(line_frame,text="IN",command=set_node_in,width=6,font=font3)
  580. b_set_node_in.pack(side="left",expand=0)
  581. b_set_node_out = Tkinter.Button(line_frame,text="OUT",command=set_node_out,width=6,font=font3)
  582. b_set_node_out.pack(side="left",expand=0)
  583. #-------------------------------------------- line
  584. line_frame = Tkinter.Frame(eframe)
  585. line_frame.pack(side="top",expand=0,fill="x")
  586. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  587. e_cmd = Tkinter.Entry(line_frame,font=font3,width=26)
  588. e_cmd.bind("<Return>", send_cmd )
  589. e_cmd.pack(side="left")
  590. #-------------------------------------------- line
  591. line_frame = Tkinter.Frame(eframe)
  592. line_frame.pack(side="top",expand=0,fill="x")
  593. Tkinter.Label(line_frame,text="LName",font=font3,width=6).pack(side="left",expand=0,fill="y")
  594. e_lname = Tkinter.Entry(line_frame,font=font3,width=26)
  595. e_lname.pack(side="left")
  596. #-------------------------------------------- line
  597. line_frame = Tkinter.Frame(eframe)
  598. line_frame.pack(side="top",expand=0,fill="x")
  599. Tkinter.Label(line_frame,text="SName",font=font3,width=6).pack(side="left",expand=0,fill="y")
  600. e_sname = Tkinter.Entry(line_frame,font=font3,width=26)
  601. e_sname.pack(side="left")
  602. #-------------------------------------------- line
  603. line_frame = Tkinter.Frame(eframe)
  604. line_frame.pack(side="top",expand=0,fill="x")
  605. Tkinter.Label(line_frame,text="ArtNet",font=font3,width=6).pack(side="left",expand=0,fill="y")
  606. Tkinter.Label(line_frame,text="SUB:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  607. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4,state="disabled")
  608. e_artnet_uni1.pack(side="left")
  609. Tkinter.Label(line_frame,text="NET:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  610. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4,state="disabled")
  611. e_artnet_uni1.pack(side="left")
  612. Tkinter.Label(line_frame,text="UNI:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  613. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4)
  614. e_artnet_uni1.pack(side="left")
  615. Tkinter.Button(line_frame,text="send ArtAddr",command=send_artaddr,width=14,font=font1).pack(side="left",expand=0)
  616. #-------------------------------------------- line
  617. b_scan = Tkinter.Text(eframe,width=20,font=font2)
  618. b_scan.pack(side="top",expand=1,fill="x")
  619. #-------------------------------------------- line
  620. line_frame = Tkinter.Frame(eframe1)
  621. line_frame.pack(side="top",expand=0,fill="x")
  622. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  623. e_cmd2 = Tkinter.Entry(line_frame,font=font3,width=16)
  624. e_cmd2.insert("end","DMX ERASE ")
  625. e_cmd2.bind("<Return>", send_cmd2 )
  626. e_cmd2.pack(side="left")
  627. #-------------------------------------------- line
  628. line_frame = Tkinter.Frame(eframe1)
  629. line_frame.pack(side="top",expand=0,fill="x")
  630. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  631. e_cmd3 = Tkinter.Entry(line_frame,font=font3,width=16)
  632. e_cmd3.insert("end","DMX OUT STORE ")
  633. e_cmd3.bind("<Return>", send_cmd3 )
  634. e_cmd3.pack(side="left")
  635. #-------------------------------------------- line
  636. line_frame = Tkinter.Frame(eframe1)
  637. line_frame.pack(side="top",expand=0,fill="x")
  638. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  639. e_cmd4 = Tkinter.Entry(line_frame,font=font3,width=16)
  640. e_cmd4.insert("end","DMX OUT SET 2")
  641. e_cmd4.bind("<Return>", send_cmd4 )
  642. e_cmd4.pack(side="left")
  643. #-------------------------------------------- line
  644. line_frame = Tkinter.Frame(eframe1)
  645. line_frame.pack(side="top",expand=0,fill="x")
  646. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  647. e_cmd5 = Tkinter.Entry(line_frame,font=font3,width=16)
  648. e_cmd5.insert("end","REBOOT ")
  649. e_cmd5.bind("<Return>", send_cmd5 )
  650. e_cmd5.pack(side="left")
  651. nodescan.bind_cmd_node()
  652. def network_listenet():
  653. print(sys._getframe().f_code.co_name)
  654. b_scan.insert("end", "log:\n" )
  655. while 1:
  656. if nodescan.node_cmd_buf_list:
  657. msg = str(nodescan.node_cmd_buf_list)
  658. print("read_cmd_buf msg",msg)
  659. nodescan.node_cmd_buf_list = []
  660. stamp = str(time.time())+"\n"
  661. stamp = time.strftime("%Y-%m-%d %X\n")
  662. b_scan.insert("end",stamp)
  663. b_scan.insert("end", msg +"\n")
  664. b_scan.see("end")
  665. time.sleep(0.1)
  666. def update_idletask():
  667. print(sys._getframe().f_code.co_name)
  668. while 1:
  669. time.sleep(1)
  670. root.update_idletasks()
  671. #print(nodescan.sock)
  672. #print(dir(nodescan.sock))
  673. #print(nodescan.sock.getsockopt())
  674. if nodescan.sock.connected == 0:
  675. MSG["text"] = "Nodescanner not Connected !"
  676. MSG["bg"] = "red"
  677. else:
  678. MSG["text"] = ""
  679. MSG["bg"] = "grey"
  680. def main():
  681. print(sys._getframe().f_code.co_name)
  682. thread.start_new_thread(scan, () )
  683. thread.start_new_thread(nodescan.node_cmd_recive, () )
  684. thread.start_new_thread(network_listenet, () )
  685. thread.start_new_thread(update_idletask, () )
  686. main()
  687. root.mainloop()