jsbc.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/python3
  2. import time
  3. import traceback
  4. import json
  5. import __main__ as MAIN
  6. from lib.cprint import *
  7. import lib.fixlib as fixlib
  8. def JSCB(x,sock=None):
  9. # REMOTE KEY EVENT's
  10. i = ""
  11. msg = ""
  12. msgs = []
  13. try:
  14. #print("JSCB",sock)
  15. for i in x:
  16. #print("i",[i])
  17. msgs = json.loads(i)
  18. #print(" JSCB",msgs) #,sock)
  19. if type(msgs) is not list:
  20. continue
  21. for msg in msgs:
  22. OK = 0
  23. #print(" msg",msg)
  24. if "event" not in msg:
  25. continue
  26. if "FIXTURES" == msg["event"]:
  27. FIX=0
  28. VAL=""
  29. ATTR=""
  30. if "FIX" in msg:
  31. FIX=msg["FIX"]
  32. if "VAL" in msg:
  33. VAL=msg["VAL"]
  34. if "ATTR" in msg:
  35. ATTR=msg["ATTR"]
  36. print(" MAIN.tk_event",FIX,VAL,ATTR)
  37. #cb = MAIN.tk_event(fix=FIX,elem=None,attr=ATTR,mode="ENCODER",data=[]) #data)
  38. fixlib.encoder(MAIN.FIXTURES.fixtures,str(FIX),ATTR,xval=VAL,xfade=0,xdelay=0)#,blind=0)
  39. #print(dir(cb))
  40. #event.num = enum
  41. #cb.cb(event)
  42. OK = 1
  43. if "CLEAR" == msg["event"]:
  44. #MAIN.FIXTURES.clear()
  45. fixlib.clear(MAIN.FIXTURES.fixtures)
  46. MAIN.modes.val("REC",0)
  47. #MAIN.master.xcb("CLEAR",1)
  48. OK = 1
  49. elif "REC" == msg["event"]:
  50. MAIN.modes.val("REC",1)
  51. OK = 1
  52. elif "EDIT" == msg["event"]:
  53. MAIN.modes.val("EDIT",1)
  54. OK = 1
  55. elif "BLIND" == msg["event"]:
  56. MAIN.modes.val("BLIND",1)
  57. OK = 1
  58. elif "FLASH" == msg["event"]:
  59. MAIN.modes.val("FLASH",1)
  60. OK = 1
  61. elif "CFG-BTN" == msg["event"]:
  62. MAIN.modes.val("CFG-BTN",1)
  63. OK = 1
  64. elif "LABEL" == msg["event"]:
  65. MAIN.modes.val("LABEL",1)
  66. OK = 1
  67. elif "REC" == msg["event"]:
  68. MAIN.modes.val("REC",1)
  69. OK = 1
  70. elif "FX-OFF" == msg["event"]:
  71. MAIN.modes.val("FX-OFF",1)
  72. #OK = 1
  73. elif "SAVE\nSHOW" == msg["event"]:
  74. MAIN.save_show()
  75. OK = 1
  76. elif "RESTART" == msg["event"]:
  77. print("OK OK")
  78. MAIN.LOAD_SHOW_AND_RESTART("").cb(force=1)
  79. OK = 1
  80. elif "REC-FX" == msg["event"]:
  81. MAIN.modes.val("REC-FX",1)
  82. OK = 1
  83. elif "EXEC" == msg["event"]:
  84. print(" EXEC EXEC")
  85. val = -1
  86. exec_nr = -1
  87. try:
  88. if "VAL" in msg:
  89. val = int(msg["VAL"])
  90. if "EXEC" in msg:
  91. exec_nr = int(msg["EXEC"])
  92. if val >= 0 and exec_nr > 0:
  93. print("EXEC_GOOO",exec_nr,val)
  94. s = time.time()
  95. MAIN.master.exec_go(exec_nr-1,xfade=None,val=val)
  96. e = time.time()
  97. #print("time:",e-s,e)
  98. #print("TIME:",int((e-s)*1000),int(e*10)-1_703_800_000)
  99. #print("TIME:",int((e-s)*1000),int(e*10)/10)
  100. print("EXE TIME:","{:0.02f}".format(e-s),int(e*100)/100)
  101. print()
  102. OK = 1
  103. except Exception as e:
  104. print("EXEC ERR:",e)
  105. if OK:
  106. cprint(" remote-key:",msg ,color="green")
  107. else:
  108. cprint(" remote-key:",msg ,color="red")
  109. except Exception as e:
  110. cprint("exception JSCB:",e,color="red")
  111. cprint("- i:",i,color="red")
  112. cprint("- msg:",msgs,color="red")
  113. cprint(traceback.format_exc(),color="red")
  114. if sock:
  115. msg = ["Notice: Exception on JSCB-SERVER: ",str(e)]
  116. msg = json.dumps(msg)
  117. msg = bytes(msg,"utf8")
  118. cprint(msg,color="red")
  119. #chat._send(sock,msg)
  120. #time.sleep(1/60)