TK-Nodescanner.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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 traceback
  16. from cprint import cprint
  17. import nodescan
  18. _file_path = "/opt/LibreLight/Xdesk/"
  19. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  20. title = "TK-ArtNet-Nodscaner"
  21. sys.stdout.write("\x1b]2;"+title+"\x07")
  22. def connect_mc():
  23. mc = None
  24. try:
  25. import memcache
  26. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  27. #mc.set("dmx-1", [1]*512)
  28. except Exception as e:
  29. cprint("Exception",e,color="red")
  30. return mc
  31. mc = connect_mc()
  32. class LOCK_BUF():
  33. def __init__(self):
  34. self.data = []
  35. self.lock = thread.allocate_lock()
  36. def append(self,data):
  37. try:
  38. self.lock.acquire()
  39. self.data.append(data)
  40. finally:
  41. self.lock.release()
  42. def set(self,data):
  43. try:
  44. self.lock.acquire()
  45. self.data = data[:]
  46. finally:
  47. self.lock.release()
  48. def get(self):
  49. out = []
  50. try:
  51. self.lock.acquire()
  52. out = self.data[:]
  53. finally:
  54. self.lock.release()
  55. return out
  56. node_list = LOCK_BUF() #[]
  57. def fill_form(event=None):
  58. cprint(sys._getframe().f_code.co_name,color="yellow")
  59. global node_list
  60. clear_form()
  61. node_list2 = node_list.get()
  62. sel=0
  63. try:
  64. csel = li_nodes.curselection()[0]
  65. except Exception as e:
  66. cprint("ERR no node selected in node-list:",e,color="red")
  67. return 0
  68. print("+++",[csel,len(node_list2)])
  69. try:
  70. sel = int(li_nodes.get(csel).split()[0])-1
  71. except:
  72. cprint("ERR no leeding number in Listbox.line" ,color="red")
  73. return 0
  74. if not node_list2:
  75. return 0
  76. print("INFO: sel,node_list2",sel,len(node_list2))
  77. e_ip.configure(state='normal')
  78. e_ip.insert("end",node_list2[sel]["IP"].replace("[","").replace("]",""))
  79. #e_ip.configure(state='readonly')
  80. e_ip_new.insert("end",node_list2[sel]["IP"].replace("[","").replace("]",""))
  81. e_mac.delete("0","end")
  82. e_mac.insert("end",node_list2[sel]["MAC"].replace("[","").replace("]",""))
  83. e_mac2.delete("0","end")
  84. e_mac2.insert("end",node_list2[sel]["MAC"].split(":")[-1])
  85. print("load",node_list2[sel])
  86. e_lname.delete("0","end")
  87. e_lname.insert("end",node_list2[sel]["lname"])
  88. e_sname.delete("0","end")
  89. e_sname.insert("end",node_list2[sel]["sname"])
  90. e_artnet_uni1.delete("0","end")
  91. univ = "0"
  92. try:
  93. if node_list2[sel]["PortTypes"][0] == "@":
  94. univ = ord(node_list2[sel]["SwIn"][0:1])
  95. else:
  96. univ = ord(node_list2[sel]["SwOut"][0:1])
  97. except Exception as e:
  98. cprint("load Exception",e,color="red")
  99. MSG["text"] = e
  100. MSG["bg"] = "red"
  101. e_artnet_uni1.insert("end",univ)
  102. def clear_form():
  103. cprint(sys._getframe().f_code.co_name,color="yellow")
  104. e_ip.configure(state='normal')
  105. e_ip.delete("0","end")
  106. e_ip.configure(state='readonly')
  107. e_ip_new.delete("0","end")
  108. e_mac.delete("0","end")
  109. e_mac2.delete("0","end")
  110. e_lname.delete("0","end")
  111. e_sname.delete("0","end")
  112. e_artnet_uni1.delete("0","end")
  113. def main_loop():
  114. while 1:
  115. try:
  116. poll()
  117. except Exception as e:
  118. print()
  119. cprint("Err main()",e,color="red")
  120. cprint(traceback.format_exc(),color="red")
  121. cprint("="*20,color="red")
  122. time.sleep(3)
  123. def poll(delay=1,ip=""):
  124. print()
  125. cprint(sys._getframe().f_code.co_name,"="*30,color="yellow")
  126. ip = "2.255.255.255"
  127. if not ip:
  128. cprint("err poll() no ip !",color="red")
  129. return
  130. b_scan.insert("end", "ArtNetPoll -> "+str(ip)+"\n")
  131. b_scan.yview("end")
  132. nodescan2.ArtPoll(ip=ip)
  133. nodes = load_node_list()
  134. refresh_node_list(nodes)
  135. import nodescan2
  136. def load_node_list():
  137. cprint(sys._getframe().f_code.co_name,"------------",color="yellow")
  138. global node_list,Scrollbar,mc
  139. li_nodes.delete("0","end")
  140. ips = nodescan2.os_list_ip() #example
  141. nodes = []
  142. if not mc:
  143. cprint("mc (memcached) is none",color="red")
  144. mc = connect_mc()
  145. return
  146. nodes = []
  147. artpoll = mc.get("index-artpoll")
  148. if not artpoll:
  149. cprint("mc.get('index-artpoll') is none ",color="red")
  150. mc = connect_mc()
  151. return
  152. for k in artpoll:
  153. data = mc.get(k)
  154. opcode= nodescan2.artnet_get_opcode(data)
  155. if "ArtPollReplay" in opcode: # != '0x2100': #OpPollReplay
  156. node = nodescan2.ArtNet_decode_pollreplay(data)
  157. s = artpoll[k][1]
  158. s = datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S')
  159. s = s.timestamp()
  160. node["UPDATESTAMP"] = s
  161. node["BOOT"] = 0
  162. node["REFRESHSTAMP"] = s
  163. node["LASTPING"] = 0
  164. #node1 = nodescan2.ArtNet_decode_pollreplay(data)
  165. nodes.append(node)
  166. ok=0
  167. for n in nodes:
  168. if n not in node_list.get():
  169. node_list.append(n)
  170. ok=1
  171. return node_list
  172. def refresh_node_list(nodes):
  173. cprint(sys._getframe().f_code.co_name,color="yellow")
  174. li_nodes.delete("0","end")
  175. li_nodes.insert("end"," - none -")
  176. node_nr = 1
  177. nodesB = {}
  178. for node in node_list.get(): #nodes:
  179. k = node["MAC"]
  180. nodesB[k] = node
  181. k_sort = list(nodesB.keys())
  182. k_sort.sort()
  183. node_list.set([]) # =[]
  184. for k in k_sort:
  185. node_list.append(nodesB[k])
  186. out = []
  187. for k in k_sort:
  188. print(" ",k)
  189. node = nodesB[k]
  190. txt = " "*5 + "="*30
  191. bg=""
  192. out.append({"txt":txt,"bg":bg})
  193. bg = "lightgrey"
  194. txt = str(node_nr).rjust(3," ") +" "+ node["lname"]
  195. out.append({"txt":txt,"bg":bg})
  196. ip = str(node_nr).rjust(3," ") +" "+ node["IP"]
  197. bg = ""
  198. if "PortTypes" in node:
  199. if not node["PortTypes"]:
  200. pass
  201. if node["PortTypes"][0] == "@":
  202. ip += " DMX-in"
  203. bg ="yellow"
  204. else:
  205. ip += " DMX-out"
  206. bg ="lightgreen"
  207. txt = str(node_nr).rjust(3," ") +" short Name:"+ node["sname"]
  208. out.append({"txt":txt,"bg":bg})
  209. txt=ip
  210. bg = ""
  211. out.append({"txt":txt,"bg":bg})
  212. inout = " UNIVERS OUT="+ str(ord(node["SwOut"][0:1]))+" IN="+ str(ord(node["SwIn"][0:1]))
  213. txt = str(node_nr).rjust(3," ") + inout
  214. bg = ""
  215. out.append({"txt":txt,"bg":bg})
  216. txt = str(node_nr).rjust(3," ") +" MAC:"+ node["MAC"]
  217. bg = ""
  218. out.append({"txt":txt,"bg":bg})
  219. txt = ""
  220. bg = ""
  221. try:
  222. last_change=time.time()-float(node["UPDATESTAMP"])
  223. timeline = ""
  224. timeline += " CHANGE:%0.1f"% (last_change)
  225. REFRESHSTAMP = time.time()-float(node["REFRESHSTAMP"])
  226. timeline +=" PING:%0.1f"% REFRESHSTAMP
  227. txt = str(node_nr).rjust(3," ") +timeline
  228. if last_change > 20:
  229. bg="ORANGE"
  230. except Exception as e:
  231. txt = str(e)+"\n"
  232. bg = "red"
  233. out.append({"txt":txt,"bg":bg})
  234. txt=""
  235. bg = ""
  236. try:
  237. if node["BOOT"]:
  238. BOOT = time.time()-float(node["BOOT"])
  239. else:
  240. BOOT = 0
  241. timeline =" BOOT:%0.1f"% BOOT
  242. txt = str(node_nr).rjust(3," ") +timeline +" sec"
  243. bg = ""
  244. except Exception as e:
  245. txt = str(e)+"\n"
  246. bg = "red"
  247. out.append({"txt":txt,"bg":bg})
  248. node_nr += 1
  249. out.append({"txt":"","bg":"white"})
  250. # insert nodes in listbox
  251. if out:
  252. li_node_scroll = li_nodes.yview()
  253. li_nodes.delete("0","end")
  254. for i in out:
  255. #print("list:",i)
  256. li_nodes.insert("end",i["txt"])
  257. bg=i["bg"]
  258. if not bg:
  259. bg = "lightgrey"
  260. bg = "#ddd"
  261. li_nodes.itemconfig("end", bg=bg)
  262. def get_form(event=None):
  263. cprint(sys._getframe().f_code.co_name,color="yellow")
  264. x = e_ip_new.get().replace("[","").replace("]","")
  265. x = x.strip()
  266. x = x.replace(" ","")
  267. x = x.split(",")
  268. ip2 = ".".join(x)
  269. ip = e_ip.get()
  270. ip = ip.replace(" ","")
  271. ip = ip.replace(",",".")
  272. MASK = variable.get() #e_mask_new.get()
  273. #new_mac = b"CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16)))
  274. mac = e_mac.get()
  275. mac_new = e_mac2.get()
  276. ln = e_lname.get()
  277. sn = e_sname.get()
  278. univ = e_artnet_uni1.get()
  279. data={}
  280. data["IP"] = ip
  281. data["IP2"] = ip2
  282. data["sname"] = sn
  283. data["lname"] = ln
  284. data["netmask"] = MASK
  285. data["mac"] = mac
  286. data["mac_new"] = mac_new
  287. data["univ"] = univ
  288. print("FORM:")
  289. for k,v in data.items():
  290. print(" ",[k,v])
  291. return data
  292. def send_artaddr(event=None):
  293. cprint(sys._getframe().f_code.co_name,color="yellow")
  294. get_form()
  295. ln = e_lname.get()
  296. sn = e_sname.get()
  297. ip = e_ip_new.get()
  298. ip = ip.replace(" ","")
  299. ip = ip.replace(",",".")
  300. univ = e_artnet_uni1.get()
  301. print("SEND ArtAddress:",[ln,sn,ip,univ])
  302. if ln and sn and ip and univ:
  303. nodescan2.ArtAddress(ip=ip ,ShortName=sn, LongName=ln,Port="",Universes=univ)
  304. def send_none(event=None):
  305. cprint(sys._getframe().f_code.co_name,color="yellow")
  306. pass
  307. def send_mac(event=None):
  308. cprint(sys._getframe().f_code.co_name,color="yellow")
  309. #new_mac = "CMD MAC6 " + hex(e_mac2.get()) #)
  310. #new_mac = "CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16))).decode()
  311. new_mac = b"CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16)))
  312. a = e_ip.get().replace("[","").replace("]","")
  313. cur_ip = []
  314. for i in a.split(","):
  315. cur_ip +=[int(i)]
  316. print("SEND MAC:",cur_ip,new_mac)
  317. nodescan2.send_node_cmd(cur_ip,cmd=new_mac)
  318. def SEND_CMD(cmd="NIX",entry=None):
  319. cprint(sys._getframe().f_code.co_name,color="yellow")
  320. def cb(event=None):
  321. cprint(sys._getframe().f_code.co_name,color="yellow")
  322. _cmd=cmd
  323. if entry:
  324. _cmd = entry.get() #"CMD DMX STORE "
  325. print(" SEND_CMD.cb()",[_cmd])
  326. if not _cmd:
  327. cprint(" SEND_CMD: no cmd",color="red")
  328. #_send_cmd(cmd=_cmd)
  329. port = 7600
  330. form = get_form()
  331. if form["IP2"]:
  332. _cmd2 = []
  333. for i in _cmd:
  334. try:
  335. _cmd2.append(ord(i) )
  336. except:
  337. _cmd2.append(ord(" ") )
  338. print(" _cmd2",_cmd2)
  339. for i in range(31):
  340. if len(_cmd2) < i:
  341. _cmd2.append(0)
  342. for i in _cmd2:
  343. print(" ",i,i,hex(i))
  344. _cmd2 = bytes(_cmd2)
  345. print(" _cmd2",_cmd2)
  346. sock = nodescan2.UDP_Socket()
  347. sock.sendto(_cmd2 ,(form["IP2"],port))
  348. return cb
  349. def send_artdmx(val=127):
  350. def cb():
  351. form = get_form()
  352. print(form)
  353. import lib.ArtNetNode as an
  354. if form["IP2"] and form["univ"]:
  355. #artnet = an.ArtNetNode(to=form["netmask"],univ=form["univ"],port=4566)
  356. b_scan.insert("end", "ArtDMX -> "+str(form["IP2"])+" univ:"+str(form["univ"])+" v="+ str(val)+"\n")
  357. b_scan.yview("end")
  358. artnet = an.ArtNetNode(to=form["IP2"],univ=form["univ"],port=4566)
  359. artnet.send([val]*512,port=6454)
  360. print(artnet._data)
  361. return cb
  362. def _send_cmd(event=None,cmd=""):
  363. cprint(sys._getframe().f_code.co_name,color="yellow")
  364. #cmd = e_cmd.get() #"CMD DMX STORE "
  365. cmd = cmd.split(" ")
  366. value = cmd[-1]
  367. try:
  368. value = struct.pack("<B",int(value))
  369. except:pass
  370. cmd = cmd[:-1] #.append(value)
  371. cmd.append(value)
  372. print("_send_cmd:",[cmd])
  373. cmd=" ".join(map(str,cmd) )
  374. a = e_ip.get()
  375. if not a:
  376. cprint(" NO NODE-IP SELECTED",color="red")
  377. return
  378. a = a.replace("[","").replace("]","")
  379. cur_ip = []
  380. sep = "xx"
  381. if "," in a:
  382. sep = ","
  383. if "." in a:
  384. sep = "."
  385. for i in a.split(sep):
  386. cur_ip +=[int(i)]
  387. cprint("_cmd_send:",cur_ip ,"CMD:",[cmd],color="yellow")
  388. nodescan2.send_node_cmd(cur_ip,cmd)
  389. def ip_to_byte(ip):
  390. x = ip.strip()
  391. if "." in x:
  392. x = x.split(".")
  393. print(x)
  394. elif ":" in x:
  395. x = x.replace(":","")
  396. print(x)
  397. x = bytes.fromhex(x)
  398. else:
  399. return [0,0,0,0]
  400. y = []
  401. for i in x:
  402. y.append(int(i))
  403. return y
  404. def set_ip(event=None):
  405. print("SET NEW IP")
  406. d=get_form()
  407. cur_ip = ip_to_byte(d["IP"])
  408. new_ip = ip_to_byte(d["IP2"])
  409. #new_netmask = ip_to_byte( d["mac"])
  410. new_netmask = ip_to_byte( d["netmask"])
  411. print("new",[cur_ip, new_ip, new_netmask])
  412. if new_ip == cur_ip:
  413. cprint("ERR set_ip() neu und als IP sind gleich" ,color="red" )
  414. return 0
  415. print("new",[cur_ip, new_ip, new_netmask])
  416. print()
  417. nodescan2.set_ip4(cur_ip,new_ip, new_netmask)
  418. def set_node_pin(evnet=None):
  419. cprint(sys._getframe().f_code.co_name,color="yellow")
  420. cmd = "CMD DMX=PIN"
  421. ip = get_form()["IP"]
  422. print("ip",[ip])
  423. nodescan2.send_node_cmd(ip,cmd=cmd)
  424. def set_node_in(evnet=None):
  425. cprint(sys._getframe().f_code.co_name,color="yellow")
  426. cmd="CMD DMX=IN"
  427. ip = get_form()["IP"]
  428. nodescan2.send_node_cmd(ip,cmd=cmd)
  429. def set_node_out(evnet=None):
  430. cprint(sys._getframe().f_code.co_name,color="yellow")
  431. cmd="CMD DMX=OUT"
  432. ip = get_form()["IP"]
  433. nodescan2.send_node_cmd(ip,cmd=cmd)
  434. # ----------------------------------------------
  435. # TK-WINDOW
  436. # ----------------------------------------------
  437. root = Tkinter.Tk()
  438. root.geometry("700x600+100+100")
  439. root.title( title)
  440. fframe = Tkinter.Frame(root)
  441. fframe.pack(side="top",expand=0,fill="x")
  442. cframe = Tkinter.Frame(root)
  443. cframe.pack(side="top",expand=1,fill="both")
  444. font1 = ("Helvetica", 8)
  445. font2 = ("Helvetica", 12) # 10
  446. font3 = ("Helvetica", 12) # 16
  447. font20 = font=("Helvetica", 12) # 22
  448. font120 = font=("Helvetica", 22) # 22
  449. b_scan = Tkinter.Button(fframe,text="refresh",width=8,command=poll,font=font2)
  450. b_scan.pack(side="left",expand=0,fill="y")
  451. b_scan = Tkinter.Button(fframe,text="ArtNetPoll ->",width=10,command=poll,font=font2)
  452. b_scan.configure(bg="#0f0")
  453. scrollbar = Tkinter.Scrollbar(cframe)
  454. scrollbar.pack(side=Tkinter.RIGHT, fill="y")
  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. # TK-FORM
  472. # ----------------------------------------------
  473. line_frame = Tkinter.Frame(eframe)
  474. line_frame.pack(side="top",expand=0,fill="x")
  475. x=Tkinter.Label(line_frame,text="MSG:",font=font3,width=6)
  476. x.pack(side="left",expand=0,fill="y")
  477. x.configure(bg="darkgrey")
  478. MSG = Tkinter.Label(line_frame,text="xxx",font=font1,width=60,anchor="w")
  479. MSG.pack(side="left",expand=0,fill="y")
  480. MSG.configure(bg="darkgrey")
  481. # ----------------------------------------------
  482. line_frame = Tkinter.Frame(eframe)
  483. line_frame.pack(side="top",expand=0,fill="x")
  484. c= Tkinter.Label(line_frame,text=" ",font=font120,width=30,anchor="w")
  485. c.pack(side="left",expand=0,fill="y")
  486. # ----------------------------------------------
  487. line_frame = Tkinter.Frame(eframe)
  488. line_frame.pack(side="top",expand=0,fill="x")
  489. Tkinter.Label(line_frame,text="OLD IP:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  490. e_ip = Tkinter.Entry(line_frame,font=font20,width=26,state="disabled")
  491. e_ip["bg"] = "lightgrey"
  492. e_ip.pack(side="left")
  493. b_scan = Tkinter.Button(line_frame,text="clean",font=font2,relief="flat",command=clear_form)
  494. b_scan.pack(side="left",expand=0)
  495. #b_scan = Tkinter.Button(line_frame,width=14,font=font3)
  496. #b_scan.pack(side="left",expand=1)
  497. # ----------------------------------------------
  498. line_frame = Tkinter.Frame(eframe)
  499. line_frame.pack(side="top",expand=0,fill="x")
  500. e_ip_label = Tkinter.Label(line_frame,text=" IP:",font=font3,width=6)
  501. e_ip_label.pack(side="left",expand=0,fill="y")
  502. e_ip_new = Tkinter.Entry(line_frame,font=font20,width=26)
  503. e_ip_new.bind("<Return>", set_ip )
  504. e_ip_new.bind("<KP_Enter>", set_ip)
  505. e_ip_new.bind("<ISO_Left_Tab>", set_ip)
  506. e_ip_new.pack(side="left")
  507. #-------------------------------------------- line
  508. line_frame = Tkinter.Frame(eframe)
  509. line_frame.pack(side="top",expand=0,fill="x")
  510. variable = Tkinter.StringVar(root)
  511. variable.set("255.0.0.0") # default value
  512. Tkinter.Label(line_frame,text="MASK:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  513. e_mask_new = Tkinter.OptionMenu(line_frame, variable,"255.255.255.0","255.0.0.0") #,width=10)
  514. e_mask_new.configure(font=("Helvetica", 12))
  515. e_mask_new.configure(width=12)
  516. e_mask_new["bg"] = "#fff"
  517. e_mask_new.pack(side="left")
  518. e=Tkinter.Label(line_frame,text="")
  519. e.configure(width=11)
  520. e.pack(side="left")
  521. b_scan = Tkinter.Button(line_frame,text="SEND TO NODE",command=set_ip,width=14,font=font1)
  522. b_scan.pack(side="left",expand=0)
  523. #-------------------------------------------- line
  524. line_frame = Tkinter.Frame(eframe)
  525. line_frame.pack(side="top",expand=0,fill="x")
  526. Tkinter.Label(line_frame,text="MAC:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  527. e_mac = Tkinter.Entry(line_frame,width=23,font=font20)
  528. e_mac.pack(side="left")
  529. e_mac["bg"] = "lightgrey"
  530. e_mac2 = Tkinter.Entry(line_frame,width=3,font=font20)
  531. e_mac2.pack(side="left")
  532. e_mac2.bind("<Return>", send_mac )
  533. e_mac2.bind("<KP_Enter>", send_mac)
  534. Tkinter.Button(line_frame,text="SEND TO NODE",command=send_mac,width=14,font=font1).pack(side="left",expand=0)
  535. # ----------------------------------------------
  536. line_frame = Tkinter.Frame(eframe)
  537. line_frame.pack(side="top",expand=0,fill="x")
  538. c= Tkinter.Label(line_frame,text=" ",font=font120,width=30,anchor="w")
  539. c.pack(side="left",expand=0,fill="y")
  540. #-------------------------------------------- line
  541. line_frame = Tkinter.Frame(eframe)
  542. line_frame.pack(side="top",expand=0,fill="x")
  543. Tkinter.Label(line_frame,text="DMX:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  544. b_set_node_pin = Tkinter.Button(line_frame,text="HW-PIN",command=set_node_pin,width=6,font=font3)
  545. b_set_node_pin.pack(side="left",expand=0)
  546. b_set_node_in = Tkinter.Button(line_frame,text="IN",command=set_node_in,width=6,font=font3)
  547. b_set_node_in.pack(side="left",expand=0)
  548. b_set_node_out = Tkinter.Button(line_frame,text="OUT",command=set_node_out,width=6,font=font3)
  549. b_set_node_out.pack(side="left",expand=0)
  550. #-------------------------------------------- line
  551. line_frame = Tkinter.Frame(eframe)
  552. line_frame.pack(side="top",expand=0,fill="x")
  553. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  554. e_cmd = Tkinter.Entry(line_frame,font=font3,width=26)
  555. CMD="" #DMX OUT STORE"
  556. c=SEND_CMD(CMD,entry=e_cmd)
  557. e_cmd.bind("<Return>", c )
  558. e_cmd.pack(side="left")
  559. #-------------------------------------------- line
  560. line_frame = Tkinter.Frame(eframe)
  561. line_frame.pack(side="top",expand=0,fill="x")
  562. Tkinter.Label(line_frame,text="LName",font=font3,width=6).pack(side="left",expand=0,fill="y")
  563. e_lname = Tkinter.Entry(line_frame,font=font3,width=26)
  564. e_lname.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="SName",font=font3,width=6).pack(side="left",expand=0,fill="y")
  569. e_sname = Tkinter.Entry(line_frame,font=font3,width=26)
  570. e_sname.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="ArtNet",font=font3,width=6).pack(side="left",expand=0,fill="y")
  575. Tkinter.Label(line_frame,text="SUB:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  576. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4,state="disabled")
  577. e_artnet_uni1.pack(side="left")
  578. Tkinter.Label(line_frame,text="NET:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  579. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4,state="disabled")
  580. e_artnet_uni1.pack(side="left")
  581. Tkinter.Label(line_frame,text="UNI:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  582. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4)
  583. e_artnet_uni1.pack(side="left")
  584. Tkinter.Button(line_frame,text="send ArtAddr",command=send_artaddr,width=14,font=font1).pack(side="left",expand=0)
  585. #-------------------------------------------- line
  586. b_scan = Tkinter.Text(eframe,width=20,font=font2)
  587. b_scan.pack(side="top",expand=1,fill="x")
  588. #-------------------------------------------- line
  589. line_frame = Tkinter.Frame(eframe1)
  590. line_frame.pack(side="top",expand=0,fill="x")
  591. e = Tkinter.Button(line_frame,text="DMX:0",font=font3,width=16,command=send_artdmx(0),bg="orange")
  592. e.pack(side="left")
  593. line_frame = Tkinter.Frame(eframe1)
  594. line_frame.pack(side="top",expand=0,fill="x")
  595. e = Tkinter.Button(line_frame,text="DMX:127",font=font3,width=16,command=send_artdmx(127),bg="orange")
  596. e.pack(side="left")
  597. line_frame = Tkinter.Frame(eframe1)
  598. line_frame.pack(side="top",expand=0,fill="x")
  599. e = Tkinter.Button(line_frame,text="DMX:255",font=font3,width=16,command=send_artdmx(255),bg="orange")
  600. e.pack(side="left")
  601. line_frame = Tkinter.Frame(eframe1)
  602. line_frame.pack(side="top",expand=0,fill="x")
  603. e = Tkinter.Label(line_frame,text="",width=16)
  604. e.pack(side="left")
  605. line_frame = Tkinter.Frame(eframe1)
  606. line_frame.pack(side="top",expand=0,fill="x")
  607. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  608. e_cmd2 = Tkinter.Entry(line_frame,font=font3,width=16)
  609. CMD="- DMX ERASE"
  610. c=SEND_CMD(CMD)
  611. e_cmd2.insert("end",CMD)
  612. e_cmd2.bind("<Return>", c )
  613. e_cmd2.pack(side="left")
  614. #-------------------------------------------- line
  615. line_frame = Tkinter.Frame(eframe1)
  616. line_frame.pack(side="top",expand=0,fill="x")
  617. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  618. e_cmd3 = Tkinter.Entry(line_frame,font=font3,width=16)
  619. CMD="DMX OUT STORE"
  620. c=SEND_CMD(CMD)
  621. e_cmd3.insert("end",CMD)
  622. e_cmd3.bind("<Return>", c )
  623. e_cmd3.pack(side="left")
  624. #-------------------------------------------- line
  625. line_frame = Tkinter.Frame(eframe1)
  626. line_frame.pack(side="top",expand=0,fill="x")
  627. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  628. e_cmd4 = Tkinter.Entry(line_frame,font=font3,width=16)
  629. CMD="DMX OUT SET 2"
  630. c=SEND_CMD(CMD)
  631. e_cmd4.insert("end",CMD)
  632. e_cmd4.bind("<Return>", c )
  633. e_cmd4.pack(side="left")
  634. #-------------------------------------------- line
  635. line_frame = Tkinter.Frame(eframe1)
  636. line_frame.pack(side="top",expand=0,fill="x")
  637. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  638. e_cmd5 = Tkinter.Entry(line_frame,font=font3,width=16)
  639. CMD="REBOOT"
  640. c=SEND_CMD(CMD)
  641. e_cmd5.insert("end",CMD)
  642. e_cmd5.bind("<Return>", c )
  643. e_cmd5.pack(side="left")
  644. def network_listenet():
  645. cprint(sys._getframe().f_code.co_name,color="yellow")
  646. b_scan.insert("end", "log:\n" )
  647. while 1:
  648. #print(".")
  649. if nodescan2.node_cmd_buf_list:
  650. msg = str(nodescan2.node_cmd_buf_list)
  651. print("read_cmd_buf msg",msg)
  652. nodescan2.node_cmd_buf_list = []
  653. stamp = str(time.time())+"\n"
  654. stamp = time.strftime("%Y-%m-%d %X\n")
  655. b_scan.insert("end",stamp)
  656. b_scan.insert("end", msg +"\n")
  657. b_scan.see("end")
  658. time.sleep(0.1)
  659. def tk_loop():
  660. while 1:
  661. root.update_idletasks()
  662. time.sleep(1)
  663. def main():
  664. cprint(sys._getframe().f_code.co_name,color="yellow")
  665. thread.start_new_thread(main_loop, () )
  666. #thread.start_new_thread(nodescan.node_cmd_recive, () )
  667. #thread.start_new_thread(network_listenet, () )
  668. thread.start_new_thread(tk_loop, () )
  669. thread.start_new_thread(nodescan2.ArtNet_Server,())
  670. #nodescan.bind_cmd_node()
  671. main()
  672. root.mainloop()