TK-Nodescanner.py 24 KB

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