TK-Nodescanner.py 27 KB

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