TK-Nodescanner.py 27 KB

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