TK-Nodescanner.py 25 KB

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