TK-Nodescanner.py 22 KB

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