_LibreLightDesk.py 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. (c) 2012 micha@librelight.de
  5. SPDX-License-Identifier: GPL-2.0-only
  6. """
  7. import random
  8. import subprocess
  9. import string
  10. import copy
  11. import traceback
  12. import json
  13. import time
  14. import sys
  15. import os
  16. import _thread as thread
  17. for i in range(30):
  18. print() # boot space
  19. IS_GUI = 0
  20. if __name__ == "__main__":
  21. IS_GUI = 1
  22. import tool.movewin as movewin
  23. import lib.fixlib as fixlib
  24. import lib.libwin as libwin
  25. import lib.libtk as libtk
  26. import lib.libconfig as libconfig
  27. rnd_id = str(random.randint(100,900))
  28. rnd_id += " beta"
  29. rnd_id2 = ""
  30. rnd_id3 = ""
  31. _ENCODER_WINDOW = None
  32. __run_main = 0
  33. if __name__ == "__main__":
  34. __run_main = 1
  35. else:
  36. import __main__
  37. if "unittest" not in dir(__main__):
  38. __run_main = 1
  39. import tool.git as git
  40. rnd_id += git.get_all()
  41. try:
  42. xtitle = __file__
  43. except:
  44. xtitle = "__file__"
  45. if "/" in xtitle:
  46. xtitle = xtitle.split("/")[-1]
  47. sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title
  48. HOME = os.getenv('HOME')
  49. space_font = None
  50. INIT_OK = 0
  51. _global_short_key = 1
  52. path = "/home/user/LibreLight/"
  53. #os.chdir(path)
  54. f = open(path+"init.txt","r")
  55. lines=f.readlines()
  56. f.close()
  57. out = []
  58. for line in lines:
  59. if line != "EASY\n":
  60. out.append(line)
  61. f = open(path+"init.txt","w")
  62. f.writelines(out)
  63. f.close()
  64. if "--easy" in sys.argv:
  65. f = open(path+"init.txt","a")
  66. f.write("EASY\n")
  67. f.close()
  68. if not os.path.isdir(path+"show/EASY"):
  69. cmd = "cp -vrf '/opt/LibreLight/Xdesk/home/LibreLight/show/EASY' '{}/show/EASY' ".format(path)
  70. print(cmd)
  71. #input()
  72. os.system(cmd)
  73. # check if EASY show exist !
  74. from lib.cprint import cprint
  75. cprint("________________________________")
  76. def cb(**args):
  77. cprint("MAIN.cb DUMMY",**args,color="red")
  78. import lib.zchat as chat
  79. import lib.motion as motion
  80. from collections import OrderedDict
  81. _FIX_FADE_ATTR = ["PAN","TILT","DIM","RED","GREEN","BLUE","WHITE","CYAN","YELLOW","MAGENTA","FOCUS","ZOOM","FROST"]
  82. CUES = OrderedDict()
  83. groups = OrderedDict()
  84. class Modes():
  85. def __init__(self):
  86. self.modes = {}
  87. self.__cfg = {}
  88. self.__cb = None
  89. def val(self,mode,value=None): #like jquery
  90. if value is not None:
  91. return self.set(mode,value)
  92. elif mode in self.modes:
  93. return self.modes[mode]
  94. def list(self,_filter="all"): # actvie
  95. _modes = []
  96. for m in self.modes:
  97. v = self.val(m)
  98. if _filter == "active" and v:
  99. _modes.append(m)
  100. if _filter == "all":
  101. _modes.append(m)
  102. return _modes
  103. def info(self):
  104. for m in self.modes:
  105. print("modes",m,self.val(m))
  106. def get(self,mode,value=None):
  107. return self.val(mode,value)
  108. def __check(self,mode):
  109. if mode not in self.modes:
  110. self.modes[mode] = 0
  111. self.__cfg[mode] = 0
  112. def cfg(self,mode,data={}):
  113. self.__check(mode)
  114. if type(data) is dict:
  115. for k in data:
  116. v = data[k]
  117. if v not in self.__cfg:
  118. self.__cfg[k] = v
  119. return 1
  120. elif type(data) is str:
  121. if data in self.__cfg:
  122. return self.__cfg[data]
  123. def clear(self,protect=[]):
  124. protected = ["BLIND"]
  125. protected.extend(protect)
  126. for m in self.modes:
  127. if m in protected:
  128. continue
  129. self.modes[m] = 0
  130. def set(self,mode,value):
  131. protected = ["BLIND","CLEAR","REC-FX"]
  132. self.__check(mode)
  133. if mode == "CLEAR":
  134. return 1
  135. elif mode == "ESC":
  136. for m in self.modes:
  137. cprint("ESC",m)
  138. if m == "COPY":
  139. EXEC.clear_copy()
  140. if m == "MOVE":
  141. EXEC.clear_move()
  142. if m != "BLIND":
  143. self.modes[m] = 0
  144. self.callback(m)
  145. return 1
  146. if value:
  147. for m in self.modes:
  148. if m not in protected and mode not in protected and m != mode:
  149. #cprint("-#-# clear mode",mode,m,value,color="red")
  150. if self.modes[m]:
  151. self.modes[m]= 0
  152. self.callback(m)
  153. if self.modes[mode] and value == 1:
  154. if modes == "MOVE":
  155. EXEC.clear_move()
  156. if modes == "COPY":
  157. EXEC.clear_copy()
  158. self.modes[mode] = 0 # value
  159. else:
  160. self.modes[mode] = value #1 #value
  161. else:
  162. self.modes[mode] = 0 #value
  163. if modes == "COPY":
  164. EXEC.clear_copy()
  165. if modes == "MOVE":
  166. EXEC.clear_move()
  167. self.callback(mode)
  168. return value
  169. def set_cb(self,cb):
  170. if cb:
  171. self.__cb = cb
  172. def callback(self,mode):
  173. if self.__cb is not None and mode in self.modes:
  174. value = self.modes[mode]
  175. self.__cb(mode=mode,value=value)
  176. modes = Modes()
  177. #modes.val("BLIND", 0)
  178. #modes.modes["BLIND"] = 0
  179. modes.modes["ESC"] = 0
  180. modes.modes["REC"] = 0
  181. modes.modes["EDIT"] = 0
  182. modes.modes["MOVE"] = 0
  183. modes.modes["FLASH"] = 0
  184. modes.modes["GO"] = 0
  185. modes.modes["DEL"] = 0
  186. modes.modes["REC-FX"] = 0
  187. modes.modes["SELECT"] = 0
  188. modes.modes["CFG-BTN"] = 0
  189. modes.modes["LABEL"] = 0
  190. POS = ["PAN","TILT","MOTION"]
  191. COLOR = ["RED","GREEN","BLUE","COLOR"]
  192. BEAM = ["GOBO","G-ROT","PRISMA","P-ROT","FOCUS","SPEED"]
  193. INT = ["DIM","SHUTTER","STROBE","FUNC"]
  194. #client = chat.tcp_sender(port=50001)
  195. def set_exec_fader_cfg(nr,val,label="",color=""):
  196. exec_wing = window_manager.get_obj(name="EXEC-WING")
  197. if not exec_wing:
  198. return
  199. try:
  200. if len(exec_wing.fader_elem) > nr:
  201. exec_wing.fader_elem[nr].attr["text"] = label
  202. cfg = get_exec_btn_cfg(nr+80)
  203. exec_wing.fader_elem[nr].attr["bg"] = cfg["bg"]
  204. exec_wing.fader_elem[nr].attr["fg"] = cfg["fg"]
  205. #exec_wing.fader_elem[nr].attr["fx"] = cfg["fx"]
  206. except Exception as e:
  207. cprint(" set_exec_fader_cfg err:",e,color="red")
  208. print(" ",nr,val,label)
  209. raise e
  210. def set_exec_fader(nr,val,label="",color="",info="info",change=0):
  211. exec_wing = window_manager.get_obj(name="EXEC-WING")
  212. if not exec_wing:
  213. return
  214. try:
  215. exec_wing.set_fader(nr,val,color=color,info=info,change=change)
  216. except Exception as e:
  217. cprint(" - set_exec_fader err:",e,color="red")
  218. print(" ",nr,val,label)
  219. raise e
  220. def set_exec_fader_all():
  221. print()
  222. cprint( "set_exec_fader_all()",color="green")
  223. for nr in range(10):
  224. _label = EXEC.label_exec[nr+80] # = label
  225. print(" set_exec_fader_all._label =",_label)
  226. set_exec_fader(nr,0,label=_label)
  227. set_exec_fader_cfg(nr,0,label=_label)
  228. def refresh_exec_fader_cfg():
  229. cprint( "set_exec_fader_all()",color="green")
  230. for nr in range(10):
  231. _label = EXEC.label_exec[nr+80] # = label
  232. #print("_label",_label)
  233. set_exec_fader_cfg(nr,0,label=_label)
  234. # remote input - start (memcached)
  235. def JCB(x,sock=None):
  236. for i in x:
  237. jv = x[i]
  238. try:
  239. jv = json.loads(jv)
  240. jv = jv[0]
  241. #print(jv)
  242. v = jv["iVAL"]
  243. #exec_wing.set_fader(0,v)
  244. set_exec_fader(0,v)
  245. set_exec_fader(1,200-v)
  246. set_exec_fader(2,int(v/2+10))
  247. except Exception as e:
  248. cprint("exception",e)
  249. print(sys.exc_info()[2])
  250. #print("remote in:",round(time.time(),0),"x",i,v)
  251. if __name__ == "__main__":
  252. r1_server = chat.Server(port=30002)
  253. def server1_loop():
  254. while 1:
  255. r1_server.poll(cb=JCB)
  256. time.sleep(1/90)
  257. thread.start_new_thread(server1_loop,()) # SERVER
  258. import lib.jsbc as JSBC
  259. if __name__ == "__main__":
  260. r_server = chat.Server(port=30003,cb=JSBC.JSCB)
  261. def server_loop():
  262. while 1:
  263. r_server.poll(cb=JSBC.JSCB)
  264. thread.start_new_thread(server_loop,()) # SERVER
  265. import lib.fifo as FIFO
  266. if __name__ == "__main__":
  267. f_server = FIFO.read_loop() #chat.Server(port=30003,cb=JSBC.JSCB)
  268. f_server.loop(sleep=1)
  269. def f_server_read_loop():
  270. time.sleep(10)
  271. print("FIFO read_loop() __ ")
  272. while 1:
  273. try:
  274. data = f_server.read()
  275. for jdata in data:
  276. # JSCB [{'event': 'EXEC', 'EXEC': 161, 'VAL': 0, 'NR-KEY': 1}]
  277. print("FIFO:",jdata)
  278. ok=1
  279. for i in ["event","VAL","EXEC"]:
  280. if i not in jdata:
  281. ok=0
  282. if ok:
  283. if jdata["event"] != "EXEC":
  284. continue
  285. if "EXEC" in jdata:
  286. exec_nr = jdata["EXEC"]
  287. if "VAL" in jdata:
  288. val = jdata["VAL"]
  289. master.exec_go(exec_nr-1,xfade=None,val=val)
  290. else:
  291. time.sleep(0.02)
  292. except KeyboardInterrupt as e:
  293. raise e
  294. except Exception as e:
  295. print("FIFO ERR1",e)
  296. thread.start_new_thread(f_server_read_loop,()) # SERVER
  297. # read memcachd
  298. memcache = None
  299. try:
  300. import memcache
  301. except Exception as e:
  302. cprint("Exception IMPORT ERROR",e)
  303. class MC_FIX():
  304. def __init__(self,server="127.0.0.1",port=11211):
  305. cprint("MC.init() ----------" ,server,port,color="red")
  306. try:
  307. self.mc = memcache.Client(['{}:{}'.format(server,port)], debug=0)
  308. except Exception as e:
  309. cprint("-- Exception",e)
  310. def set(self,index="fix",data=[]):
  311. index = self.mc.get("index")
  312. self.mc.set("fix", data)
  313. class MC():
  314. def __init__(self,server="127.0.0.1",port=11211):
  315. cprint("MC.init() ----------" ,server,port,color="red")
  316. try:
  317. #self.mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  318. self.mc = memcache.Client(['{}:{}'.format(server,port)], debug=0)
  319. #self.init()
  320. except Exception as e:
  321. cprint("-- Exception",e)
  322. # def init(self):
  323. data = {}
  324. start = time.time()
  325. delta = start
  326. index = self.mc.get("index")
  327. if index:
  328. for i in index:
  329. print(" key",i)
  330. self.last_fader_val = [-1]*512
  331. self.fader_map = []
  332. for i in range(30+1):
  333. self.fader_map.append({"UNIV":0,"DMX":0})
  334. try:
  335. fname = HOME + "/LibreLight/fader.json"
  336. f = open(fname)
  337. lines = f.readlines()
  338. cprint("FADER MAP",fname)
  339. for i,line in enumerate(lines):
  340. jdata = json.loads(line)
  341. print(" fader_map ->>",i,jdata)
  342. self.fader_map[i] = jdata
  343. except Exception as e:
  344. cprint("-- Except Fader_map",e)
  345. #exit()
  346. def ok(self):
  347. if self.mc:
  348. return 1
  349. return 0
  350. def test(self):
  351. if not self.ok():
  352. return
  353. self.mc.set("some_key", "Some value")
  354. self.value = mc.get("some_key")
  355. self.mc.set("another_key", 3)
  356. self.mc.delete("another_key")
  357. def loop(self):
  358. thread.start_new_thread(self._loop,())
  359. if not self.ok():
  360. return
  361. def _exec_fader_loop(self,x):
  362. for i, line in enumerate(self.fader_map):
  363. try:
  364. #print(i,line)
  365. dmx = int(line["DMX"])
  366. if dmx > 0:
  367. val = x[dmx-1]
  368. #print("mc val",val)
  369. #print("dmx_in change:",[i,val])
  370. change = 0
  371. if i < len(self.last_fader_val):
  372. if self.last_fader_val[i] != val:
  373. self.last_fader_val[i] = val
  374. print("dmx_in change:",[i,val])
  375. change = 1
  376. set_exec_fader(nr=i,val=val,color="#aaa",info="dmx_in",change=change)
  377. except Exception as e:
  378. cprint("MC exc:",e,color="red")
  379. traceback.print_exc()
  380. pass
  381. def _loop(self):
  382. time.sleep(20)
  383. cprint("++++++++++ start.memcachd read loop",self )
  384. ip = libconfig.load_remote_ip()
  385. print("IP:",ip)
  386. input()
  387. while 1:
  388. send = 0
  389. #print("+")
  390. try:
  391. #ip="10.10.10.13:0"
  392. #ip="ltp-out:0"
  393. #print(ip)
  394. x=self.mc.get(ip)
  395. if x:
  396. #print(ip,x)
  397. #val = x[501-1]
  398. #val = x[141-1]
  399. self._exec_fader_loop(x)
  400. time.sleep(1/10)
  401. except Exception as e:
  402. cprint("exc", e)
  403. time.sleep(1)
  404. _mc=MC()
  405. _mc.loop()
  406. def message_buss_loop():
  407. while 1:
  408. try:
  409. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  410. break
  411. except Exception as e:
  412. cprint("--1 message_buss_loop Exc",[e])
  413. time.sleep(2)
  414. while 1:
  415. try:
  416. key="MODES"
  417. cfg = {}
  418. for k,v in modes.modes.items():
  419. if v:
  420. cfg[k] = v
  421. cfg["S-KEY"] = _global_short_key
  422. mc.set(key,json.dumps(cfg))
  423. except Exception as e:
  424. cprint("--2 message_buss_loop Exc:",[e])
  425. time.sleep(2)
  426. time.sleep(0.2)
  427. thread.start_new_thread(message_buss_loop,())
  428. console = chat.Client() #port=50001)
  429. def jclient_send(data):
  430. t_start = time.time()
  431. jtxt = data
  432. jdatas = []
  433. for jdata in data:
  434. if "CMD" in jdata:
  435. try:
  436. jdatas.append(jdata)
  437. except Exception as e:
  438. cprint("jclient_send, Exception DMX ",color="red")
  439. cprint("",jdata,color="red")
  440. cprint("-----",color="red")
  441. elif "DMX" in jdata:
  442. try:
  443. jdata["DMX"] = int(jdata["DMX"])
  444. dmx = jdata["DMX"]
  445. if "ATTR" not in jdata:
  446. # for fx off
  447. jdatas.append(jdata)
  448. else:
  449. fix = "00000"
  450. attr = "00000"
  451. if "FIX" in jdata:
  452. fix = jdata["FIX"]
  453. if "ATTR" in jdata:
  454. attr = jdata["ATTR"]
  455. dmx_fine = fixlib.get_dmx(FIXTURES.fixtures,fix,attr+"-FINE")
  456. if jdata["DMX"] != dmx_fine and dmx > 0 and dmx_fine > 0:
  457. jdata["DMX-FINE"] = dmx_fine
  458. if "DMX-FINE" in jdata:
  459. if jdata["DMX-FINE"] <= 0:
  460. del jdata["DMX-FINE"]
  461. if jdata["ATTR"].startswith("_"):
  462. pass # ignore attr._ACTIVE
  463. else:#
  464. jdata["time"] = t_start
  465. jdatas.append(jdata)
  466. #cprint("-- ",jdata,color="red")
  467. except Exception as e:
  468. cprint("jclient_send, Exception DMX ",color="red")
  469. cprint("",jdata,color="red")
  470. cprint(e,color="red")
  471. cprint("-----",color="red")
  472. jtxt = jdatas
  473. jtxt = json.dumps(jtxt)
  474. jtxt = jtxt.encode()
  475. console.send( jtxt ) #b"\00 ")
  476. cprint("{:0.04} sec.".format(time.time()-t_start),color="yellow")
  477. cprint("{:0.04} tick".format(time.time()),color="yellow")
  478. def _highlight(fix,_attr="DIM"):
  479. " patch test button "
  480. cprint("highlight",fix,"1")
  481. if fix not in FIXTURES.fixtures:
  482. return None
  483. d = FIXTURES.fixtures[fix]
  484. #for k,v in d.items():
  485. # cprint("-",k,v)
  486. DMX = d["DMX"] + d["UNIVERS"]*512
  487. if "ATTRIBUT" in d:
  488. ATTR= d["ATTRIBUT"]
  489. data = {"VALUE":200,"DMX":1}
  490. attr = ""
  491. if _attr in ATTR:
  492. attr = _attr
  493. else:
  494. return #stop
  495. cprint(attr,ATTR[attr])
  496. old_val = ATTR[attr]["VALUE"]
  497. data["DMX"] = DMX + ATTR[attr]["NR"]-1
  498. cprint(attr,ATTR[attr])
  499. cprint(data)
  500. for i in range(3):
  501. cprint("highlight",fix,"0")
  502. data["VALUE"] = 100
  503. jclient_send([data])
  504. time.sleep(0.1)
  505. cprint("highlight",fix,"1")
  506. data["VALUE"] = 234
  507. jclient_send([data])
  508. time.sleep(0.3)
  509. cprint("highlight",fix,"0")
  510. data["VALUE"] = old_val
  511. jclient_send([data])
  512. def highlight2(fix,attr="DIM"):
  513. def x():
  514. highlight(fix,attr=attr)
  515. return x
  516. def highlight(fix):
  517. cprint("highlight",fix)
  518. thread.start_new_thread(_highlight,(fix,"DIM"))
  519. thread.start_new_thread(_highlight,(fix,"RED"))
  520. thread.start_new_thread(_highlight,(fix,"GREEN"))
  521. thread.start_new_thread(_highlight,(fix,"BLUE"))
  522. class ValueBuffer():
  523. def __init__(self,_min=0,_max=255):
  524. self._value = 2
  525. self._on = 1
  526. self._min=_min
  527. self._max=_max
  528. def check(self):
  529. if self._value < self._min:
  530. self._value = self._min
  531. elif self._value > self._max:
  532. self._value = self._max
  533. def inc(self,value=None):
  534. if value is not None:
  535. if type(value) is float:
  536. self._value += round(value,4)
  537. else:
  538. self._value += value
  539. self.check()
  540. return self._value
  541. def val(self,value=None):
  542. if value is not None:
  543. if type(value) is float:
  544. self._value = round(value,4)
  545. else:
  546. self._value = value
  547. self.check()
  548. return self._value
  549. def on(self):
  550. self._on = 1
  551. def off(self):
  552. self._on = 0
  553. def _is(self):
  554. if self._on:
  555. return 1
  556. return 0
  557. FADE = ValueBuffer() #2 #0.1 #1.13
  558. FADE.val(2.0)
  559. FADE_move = ValueBuffer() #2 #0.1 #1.13
  560. FADE_move.val(4.0)
  561. DELAY = ValueBuffer() #2 #0.1 #1.13
  562. DELAY.off()
  563. DELAY.val(0.2)
  564. fx_prm_main = {}
  565. fx_prm_move = {"SIZE":40,"SPEED":8,"OFFSET":100,"BASE":"0","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":0,"WING":2,"WIDTH":100}
  566. fx_color = {"A":"red","B":"blue"}
  567. fx_prm = {"SIZE":255,"SPEED":10,"OFFSET":100,"BASE":"-","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":1,"SHUFFLE":0,"WING":2,"WIDTH":25,"2D-X":1,"2D:MODE":0}
  568. fx_x_modes = ["spiral","left","right","up","down","left_right","up_down"]
  569. fx_modes = ["RED","GREEN","BLUE","MAG","YELLOW","CYAN"]
  570. fx_mo = ["fade","on","rnd","ramp","ramp2","cosinus","sinus","static"]
  571. class FX_handler():
  572. def __init__():
  573. pass
  574. class dummy_event():
  575. def __init__(self):
  576. self.num =0
  577. self.type = 4 #press 5 release
  578. self.set_value=-1
  579. from lib import matrix
  580. import lib.fxlib as fxlib
  581. def process_matrix(xfixtures):
  582. fx_x = fx_prm["2D-X"]
  583. fx_mod = fx_x_modes[fx_prm["2D:MODE"]]
  584. r = _process_matrix(xfixtures,fx_x,fx_mod)
  585. return r
  586. def _process_matrix(xfixtures,fx_x,fx_mod):
  587. fix_count = len(xfixtures)
  588. cprint("----",fx_x,fx_mod)
  589. if fx_x > 1 and fix_count > fx_x:
  590. try:
  591. w=fx_x
  592. h=int(fix_count/fx_x)
  593. if fx_mod == "spiral":
  594. _map = matrix.spiral(w,h)
  595. elif fx_mod == "up_down":
  596. _map = matrix.up_down(w,h)
  597. elif fx_mod == "left_right":
  598. _map = matrix.left_right(w,h)
  599. elif fx_mod == "left":
  600. _map = matrix.left(w,h)
  601. elif fx_mod == "right":
  602. _map = matrix.right(w,h)
  603. elif fx_mod == "up":
  604. _map = matrix.up(w,h)
  605. elif fx_mod == "down":
  606. _map = matrix.down(w,h)
  607. else:
  608. return xfixtures # do nothing
  609. matrix.mprint(xfixtures,w,h)
  610. out = ["0"]*(w*h)
  611. for i,f in enumerate(xfixtures):
  612. if i < w*h:
  613. j = int(_map[i])
  614. cprint(["i:",i,"f:",f,"j:",j])
  615. out[j] = f
  616. matrix.mprint(out,w,h)
  617. xfixtures = out
  618. except Exception as e:
  619. cprint("matrix exception",e)
  620. return xfixtures
  621. def save_show(fpath=None,new=0):
  622. if fpath:
  623. a=EXEC.backup_exec(save_as=fpath,new=new)
  624. b=FIXTURES.backup_patch(save_as=fpath,new=new)
  625. c=libwin.save_window_position(save_as=fpath)
  626. d=movewin.store_all_sdl()
  627. else:
  628. print()
  629. print()
  630. cprint("SAVE SHOW ..",color="yellow")
  631. a=EXEC.backup_exec()
  632. b=FIXTURES.backup_patch()
  633. c=libwin.save_window_position()
  634. d=movewin.store_all_sdl()
  635. if a and b and d: # and c
  636. cprint("SAVE SHOW OK",[fpath,new],[a,b,c,d],color="green")
  637. print()
  638. print()
  639. print()
  640. return 1
  641. cprint("SAVE SHOW FAIL",[fpath,new],[a,b,c,d],color="red")
  642. print()
  643. print()
  644. print()
  645. def save_show_as(fname,new=0):
  646. print()
  647. print()
  648. fpath = showlib.generate_show_path(fname)
  649. info = "SAVE SHOW AS"
  650. if new:
  651. info = "SAVE (NEW) SHOW AS"
  652. cprint(info,fpath,fname,color="green")
  653. if showlib.create_new_show_path(fpath):
  654. return save_show(fpath,new)
  655. import lib.showlib as showlib
  656. class cb():
  657. def __init__(self,win):
  658. self.win = win
  659. def _callback(self,event):
  660. clobj=event.widget
  661. ## undermouse=find_withtag(master.CURRENT)
  662. undermouse=self.win.find_closest(self.win.CURRENT)
  663. cprint( repr(undermouse))
  664. def callback(self,event):
  665. cprint(__file__,self,"callback",event)
  666. cnv = self.win
  667. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  668. tags = cnv.gettags(item)
  669. #cnv.itemconfigure(self.tag, text=tags[0])
  670. cprint(tags,item)
  671. color = cnv.itemcget(item, "fill")
  672. cnv.itemconfig("all", width=1)#filla="green")
  673. cnv.itemconfig(item, width=3)#filla="green")
  674. cprint(color)
  675. cprint( hex_to_rgb(color[1:]))
  676. import copy
  677. def get_exec_btn_cfg(nr):
  678. k = nr
  679. if 1:
  680. _bg = "grey"
  681. _ba = "grey"
  682. _fg = "lightgrey"
  683. _text = "N/V"
  684. txt = "None/nNone"
  685. txt1 = "None/nNone"
  686. if nr >= 0:
  687. if nr != k:
  688. return #continue
  689. label = ""
  690. if k in EXEC.label_exec:
  691. label = EXEC.label_exec[k]
  692. ifval = 0
  693. fx_only = 0
  694. fx_color = 0
  695. if k in EXEC.val_exec and len(EXEC.val_exec[k]) :
  696. sdata = EXEC.val_exec[k]
  697. have_fx = 0
  698. have_val = 0
  699. fix_count = 0
  700. BTN="go"
  701. if "CFG" in sdata:#["BUTTON"] = "GO"
  702. if "BUTTON" in sdata["CFG"]:
  703. BTN = sdata["CFG"]["BUTTON"]
  704. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  705. _text = txt
  706. if len(sdata) > 1:
  707. ifval = 1
  708. val_color = 0
  709. for fix in sdata:
  710. if fix == "CFG":
  711. continue
  712. fix_count += 1
  713. for attr in sdata[fix]:
  714. if attr.startswith("_"):
  715. continue
  716. if "FX2" in sdata[fix][attr]:
  717. if sdata[fix][attr]["FX2"]:
  718. fx_color = 1
  719. have_fx += 1
  720. if "FX" in sdata[fix][attr]:
  721. if sdata[fix][attr]["FX"]:
  722. fx_color = 1
  723. have_fx += 1
  724. if "VALUE" in sdata[fix][attr]:
  725. if sdata[fix][attr]["VALUE"] is not None:
  726. val_color = 1
  727. have_val += 1
  728. #if val_color:
  729. # have_val += 1
  730. #if fx_color:
  731. # have_fx += 1
  732. if val_color:
  733. _bg = "gold"
  734. _ba = "#ffaa55"
  735. if fx_color:
  736. _fg = "blue"
  737. else:
  738. if fx_color:
  739. fx_only = 1
  740. else:
  741. _bg = "grey"
  742. _ba = "#aaa"
  743. sdata["CFG"]["HAVE-FX"] = have_fx
  744. sdata["CFG"]["HAVE-VAL"] = have_val
  745. sdata["CFG"]["FIX-COUNT"] = fix_count
  746. if "\n" in txt:
  747. txt1 = txt.split("\n")[0]
  748. _fg = "black"
  749. if ifval:
  750. if fx_only:
  751. _bg = "cyan"
  752. _ba = "#55d4ff"
  753. if "SEL" in txt1:
  754. _bg = "#77f"
  755. else:
  756. _bg = "grey"
  757. _fg = "darkgrey"
  758. if "SEL" in txt1:
  759. _fg = "blue"
  760. elif "ON" in txt1:
  761. _fg = "#040"
  762. elif "GO" in txt1:
  763. _fg = "#555"
  764. if "FL" in txt1:
  765. _fg = "#00e"
  766. out = {} # default
  767. out["fx"] = ""
  768. out["bg"] = "lightgrey"
  769. out["ba"] = "grey"
  770. out["fg"] = "grey"
  771. out["text"] = "?"
  772. out["fx"] = fx_color
  773. out["bg"] = _bg
  774. out["ba"] = _ba
  775. out["fg"] = _fg
  776. out["text"] = _text
  777. return out
  778. class Elem_Container():
  779. def __init__(self):
  780. self.commands = []
  781. self.val = {}
  782. self.elem = {}
  783. import lib.execlib as execlib
  784. class MASTER():
  785. def __init__(self):
  786. self.base = showlib.Base ()
  787. self.load()
  788. self._XX = 0
  789. self.all_attr =["DIM","PAN","TILT"]
  790. self.elem_attr = {}
  791. self.setup_elem = {} # Elem_Container()
  792. self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI","PRO\nMODE"]
  793. self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","PRO\nMODE"]
  794. self.fx_main = Elem_Container()
  795. self.fx_main.commands =["REC-FX","FX OFF","\n"]
  796. self.fx_moves = Elem_Container()
  797. self.fx_moves.commands =[
  798. "FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  799. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  800. ]
  801. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  802. self.fx = Elem_Container()
  803. self.fx.commands =[
  804. "FX:DIM"," ", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  805. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","2D-X:\n-","2D:MODE"
  806. ]
  807. self.fx_generic = Elem_Container()
  808. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","FX:STATIC"]
  809. self.fx_color = Elem_Container()
  810. self.fx_color.commands =["FX:RED","FX-C:A","FX-C:B"]
  811. self.commands = Elem_Container()
  812. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  813. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  814. ,"BLIND","CLEAR","REC","EDIT","COPY",".","\n"
  815. ]
  816. for i in range(8*8*8):
  817. if i not in EXEC.val_exec:
  818. name = "Preset:"+str(i+1)+":\nXYZ"
  819. #self.exec[i] = [i]
  820. EXEC.val_exec[i] = OrderedDict() # FIX
  821. EXEC.val_exec[i]["CFG"] = OrderedDict() # CONFIG
  822. EXEC.label_exec[i] = "-"
  823. modes.set_cb(self.xcb)
  824. def jclient_send(self,data):
  825. # namespace wraper
  826. if not modes.val("BLIND"):
  827. jclient_send(data)
  828. def button_refresh(self,name,color,color2=None,text="",fg=None):
  829. #cprint("button_refresh",name,color)
  830. if color2 is None:
  831. color2 = color
  832. if text:
  833. text = "\n"+str(text)
  834. elem=None
  835. for elem in [self.commands.elem,self.fx.elem,self.fx_main.elem,self.fx_moves.elem]:
  836. try:
  837. if name in elem:
  838. #print(" in xx.elem OK ",[name,color,name,text,color2])
  839. if name in ["BLIND","CLEAR"] and color == "lightgrey":
  840. color = "grey"
  841. color2 = "grey"
  842. elem[name]["bg"] = color
  843. elem[name]["text"] = name+ text
  844. elem[name].config(activebackground=color2)
  845. if fg:
  846. elem[name]["fg"] = fg
  847. except Exception as e:
  848. cprint(" master.button_refresh",self,e)
  849. cprint(" ",elem)
  850. def dialog_cfg_return(self,nr):
  851. # buffer nr
  852. def _cb(data):
  853. cfg = EXEC._btn_cfg(nr)
  854. button = EXEC.btn_cfg(nr)
  855. label = EXEC.label(nr)
  856. if not data:
  857. cprint("err443",self,"_cb",data)
  858. return None
  859. cprint("btn_cfg._cb()",data)
  860. if data:
  861. if "Button" in data and type(data["Button"]) is str:
  862. txt = data["Button"]
  863. EXEC.btn_cfg(nr,txt)
  864. if "Label" in data and type(data["Label"]) is str:
  865. txt = data["Label"]
  866. EXEC.label(nr,txt)
  867. if "Delay" in data and type(data["Delay"]) is str:
  868. txt = data["Delay"]
  869. try:
  870. txt = float(txt)
  871. if "DELAY" in cfg:
  872. cfg["DELAY"] = round(txt,2)
  873. except e as Exception:
  874. print("DELAY Exception",e)
  875. if "in-Fade" in data and type(data["in-Fade"]) is str:
  876. txt = data["in-Fade"]
  877. try:
  878. txt = float(txt)
  879. if "FADE" in cfg:
  880. cfg["FADE"] = round(txt,2)
  881. except e as Exception:
  882. print("in-Fade Exception",e)
  883. if "out-Fade" in data and type(data["out-Fade"]) is str:
  884. txt = data["out-Fade"]
  885. try:
  886. txt = float(txt)
  887. cfg["OUT-FADE"] = round(txt,2)
  888. except e as Exception:
  889. print("out-Fade Exception",e)
  890. modes.val("CFG-BTN",0)
  891. master._refresh_exec(nr=nr)
  892. return _cb
  893. def btn_cfg(self,nr,testing=0):
  894. cfg = EXEC._btn_cfg(nr)
  895. button = EXEC.btn_cfg(nr)
  896. label = EXEC.label(nr)
  897. dialog._cb = self.dialog_cfg_return(nr) # return cb()
  898. if 1: # testing:
  899. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  900. else:
  901. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  902. def label(self,nr):
  903. txt = EXEC.label(nr)
  904. def _cb(data):
  905. if not data:
  906. cprint("err443",self,"_cb",data)
  907. return None
  908. txt = data["Value"]
  909. cprint("label._cb()",nr,txt)
  910. if txt:
  911. EXEC.label(nr,txt)
  912. modes.val("LABEL", 0)
  913. master._refresh_exec(nr=nr)
  914. dialog._cb= _cb #_x(nr)
  915. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  916. def button_clear(self):
  917. modes.clear()
  918. txt=""
  919. for m in modes.modes:
  920. if not modes.modes[m]:
  921. self.button_refresh(m,color="lightgrey",text=txt)
  922. def xcb(self,mode,value=None):
  923. cprint(" Master.xcb mode:",str(mode).rjust(10," "),value,color="yellow",end="")
  924. if value:
  925. cprint("===== ON ======",color="green")
  926. txt = ""
  927. if mode == "REC-FX":
  928. modes.modes["REC"] = 1 # HACK !
  929. self.button_refresh("REC",color="red",text=txt)#,fg="blue")
  930. self.button_refresh(mode,color="red",text=txt)#,fg="blue")
  931. if value == 2:
  932. if mode in ["MOVE","COPY"]:
  933. txt="to"
  934. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  935. else:
  936. if mode in ["MOVE","COPY"]:
  937. txt="from"
  938. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  939. else:
  940. cprint("===== OFF ======",color="red")
  941. if mode == "REC":
  942. modes.val("REC-FX",0)
  943. if mode == "REC-FX":
  944. modes.modes["REC"] = 0 # HACK !
  945. self.button_refresh("REC",color="lightgrey")#,fg="black")
  946. self.button_refresh(mode,color="lightgrey")#,fg="black")
  947. #modes.info()
  948. def load(self,fname=""):
  949. pass
  950. def exit(self):
  951. cprint("__del__",self)
  952. def refresh_exec(self):
  953. refresher_exec.reset() # = tkrefresh.Refresher()
  954. def _refresh_exec(self,nr=-1):
  955. s = time.time()
  956. cprint("EXEC.refresh_exec()")
  957. refresher_exec.reset() # = tkrefresh.Refresher()
  958. self._XX +=1
  959. self._nr_ok = 0
  960. ERR=""
  961. for nr in EXEC.val_exec:
  962. cfg = get_exec_btn_cfg(nr)
  963. time.sleep(0.01)
  964. def refresh_fix(self):
  965. refresher_fix.reset() # = tkrefresh.Refresher()
  966. def _refresh_fix(self):
  967. cprint("_refresh_fix")
  968. s=time.time(); _XXX=0
  969. menu_buff = {"DIM":0,"DIM-SUB":0,"FIX":0,"FIX-SUB":0}
  970. elem_buffer = []
  971. for fix in FIXTURES.fixtures:
  972. sdata = FIXTURES.fixtures[fix]
  973. elem_attr_fix = None
  974. if fix in self.elem_attr:
  975. elem_attr_fix = self.elem_attr[fix]
  976. if "DIM" in sdata["ATTRIBUT"] and "_ACTIVE" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 2:
  977. KEY = "DIM-SUB"
  978. else:
  979. KEY = "FIX-SUB"
  980. FIX = 0
  981. DIM = 0
  982. for attr in sdata["ATTRIBUT"]:
  983. _buff = {}
  984. row = sdata["ATTRIBUT"][attr]
  985. if attr.endswith("-FINE"):
  986. continue
  987. b_attr = attr
  988. if b_attr == "_ACTIVE":
  989. b_attr = "S"
  990. elem = None
  991. if elem_attr_fix:
  992. if b_attr not in elem_attr_fix:
  993. continue
  994. elem = elem_attr_fix[b_attr]
  995. if not elem:
  996. continue
  997. if "elem" not in _buff:
  998. _buff["elem"] = elem
  999. if not attr.startswith("_"):
  1000. v2 = row["VALUE"]
  1001. #_text = "{} {}".format(str(attr).rjust(4,"0"),str(v2).rjust(4,"0")) # ~0.2 sec
  1002. _text = "{} {}".format(attr,v2)
  1003. _buff["text"] = _text
  1004. if row["ACTIVE"]:
  1005. _buff["bg"] = "yellow"
  1006. _buff["abg"] = "yellow"
  1007. menu_buff[KEY] += 1
  1008. if b_attr == "S":
  1009. if KEY == "DIM-SUB":
  1010. DIM =1
  1011. else:
  1012. FIX =1
  1013. else:
  1014. _buff["bg"] = "grey"
  1015. _buff["abg"] = "grey"
  1016. if "FX" not in row: # insert FX2 excetption
  1017. row["FX"] = "" #OrderedDict()
  1018. if "FX2" not in row: # insert FX2 excetption
  1019. row["FX2"] = {} #OrderedDict()
  1020. #print("row",fix,row)
  1021. if row["FX"]:
  1022. _buff["fg"] = "blue"
  1023. elif row["FX2"]:
  1024. _buff["fg"] = "red"
  1025. else:
  1026. _buff["fg"] = "black"
  1027. elem_buffer.append(_buff)
  1028. menu_buff["FIX"] += FIX
  1029. menu_buff["DIM"] += DIM
  1030. try:
  1031. for row in elem_buffer:
  1032. elem = row["elem"]
  1033. if not elem:
  1034. continue
  1035. for e in row:
  1036. if e == "elem":
  1037. continue
  1038. v = row[e]
  1039. if e == "abg":
  1040. elem.config(activebackground=v)
  1041. else:
  1042. elem[e] = v
  1043. w = window_manager.get_win("FIXTURES")
  1044. if w:
  1045. w.update_idle_task()
  1046. except Exception as e:
  1047. cprint("exc434",e,color="red")
  1048. cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
  1049. cprint(gui_menu)
  1050. menu_buff["FIX-SUB"] -= menu_buff["FIX"]
  1051. if menu_buff["FIX-SUB"]:
  1052. gui_menu.config("FIXTURES","bg","yellow")
  1053. gui_menu.config("FIXTURES","activebackground","yellow")
  1054. elif menu_buff["FIX"]:
  1055. gui_menu.config("FIXTURES","bg","orange")
  1056. gui_menu.config("FIXTURES","activebackground","orange")
  1057. else:
  1058. gui_menu.config("FIXTURES","bg","")
  1059. gui_menu.config("FIXTURES","activebackground","")
  1060. gui_menu.update("FIXTURES","{} : {}".format(menu_buff["FIX"],menu_buff["FIX-SUB"]))
  1061. menu_buff["DIM-SUB"] -= menu_buff["DIM"]
  1062. if menu_buff["DIM-SUB"]:
  1063. gui_menu.config("DIMMER","bg","yellow")
  1064. gui_menu.config("DIMMER","activebackground","yellow")
  1065. elif menu_buff["DIM"]:
  1066. gui_menu.config("DIMMER","bg","orange")
  1067. gui_menu.config("DIMMER","activebackground","orange")
  1068. else:
  1069. gui_menu.config("DIMMER","bg","")
  1070. gui_menu.config("DIMMER","activebackground","")
  1071. gui_menu.update("DIMMER","{} : {}".format(menu_buff["DIM"],menu_buff["DIM-SUB"]))
  1072. cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
  1073. def exec_rec(self,nr):
  1074. cprint("Master.exec_rec","-- EXEC RECORD ------------------------------")
  1075. _filter=""
  1076. if modes.val("REC-FX"):
  1077. _filter="ONLY-FX"
  1078. data = fixlib.get_active(FIXTURES.fixtures,_filter=_filter)
  1079. EXEC.rec(nr,data)
  1080. sdata=data
  1081. EXEC.val_exec[nr] = sdata
  1082. modes.val("REC-FX",0)
  1083. modes.val("REC",0)
  1084. cfg = get_exec_btn_cfg(nr)
  1085. #master._refresh_exec()
  1086. return 1
  1087. def exec_edit(self,nr):
  1088. cprint("Master.exec_edit","-- EXEC EDIT ------------------------------")
  1089. fixlib.clear(MAIN.FIXTURES.fixtures)
  1090. self.exec_select(nr)
  1091. event=None
  1092. self.exec_go(nr,xfade=0,event=event,val=255,button="go")
  1093. modes.val("EDIT", 0)
  1094. master.refresh_fix()
  1095. refresher_fix.reset() # = tkrefresh.Refresher()
  1096. def exec_select(self,nr):
  1097. cprint("Master.exec_select","-- EXEC SELECT ------------------------------")
  1098. sdata = EXEC.val_exec[nr]
  1099. cmd = ""
  1100. for fix in sdata:
  1101. if fix == "CFG":
  1102. continue
  1103. for attr in sdata[fix]:
  1104. #v2 = sdata[fix][attr]["VALUE"]
  1105. #v2_fx = sdata[fix][attr]["FX"]
  1106. #print( self.data.elem_attr)
  1107. #if fix in self.elem_attr:
  1108. # if attr in self.elem_attr[fix]:
  1109. # elem = self.elem_attr[fix][attr]
  1110. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  1111. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  1112. #elem["bg"] = "yellow"
  1113. def exec_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  1114. s=time.time()
  1115. t_start = time.time()
  1116. if xfade is None and FADE._is():
  1117. xfade = FADE.val()
  1118. if ptfade is None and FADE_move._is():
  1119. ptfade = FADE_move.val()
  1120. print()
  1121. cprint("Master.exec_go","-- EXEC GO FADE -----",nr,val)
  1122. rdata = EXEC.get_raw_map(nr)
  1123. if not rdata:
  1124. return 0
  1125. cfg = EXEC.get_cfg(nr)
  1126. if not cfg:
  1127. cprint(" NO CFG",cfg,nr)
  1128. return 0
  1129. xFLASH = 0
  1130. value=None
  1131. cprint(" exec_go",nr,cfg)
  1132. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  1133. self.exec_select(nr)
  1134. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  1135. xFLASH = 1
  1136. xfade = 0
  1137. if type(val) is not type(None) and val == 0 :
  1138. value = "off"
  1139. xfade=0
  1140. if "OUT-FADE" in cfg:
  1141. xfade=cfg["OUT-FADE"]
  1142. if event:
  1143. if str(event.type) == "ButtonRelease" or event.type == '5' :
  1144. value = "off"
  1145. xfade=0
  1146. if "OUT-FADE" in cfg:
  1147. xfade=cfg["OUT-FADE"]
  1148. cprint(" exec_go() FLUSH",value,color="red")
  1149. #print(";",rdata)
  1150. print(" cfg:",cfg)
  1151. fcmd = FIXTURES.update_raw(rdata,update=0)
  1152. #print(":",fcmd) # raw dmx
  1153. self._exec_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  1154. elif not val:
  1155. cprint("exec_go() STOP",value,color="red")
  1156. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  1157. fcmd = FIXTURES.update_raw(rdata)
  1158. self._exec_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  1159. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  1160. fcmd = FIXTURES.update_raw(rdata)
  1161. e=time.time()
  1162. #print("_GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
  1163. self._exec_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  1164. e=time.time()
  1165. #print("GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
  1166. return
  1167. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  1168. self.refresh_exec()
  1169. self.refresh_fix()
  1170. cprint("exec_go",time.time()-t_start)
  1171. def _exec_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  1172. if xfade is None and FADE._is():
  1173. xfade = FADE.val()
  1174. if ptfade is None and FADE_move._is():
  1175. ptfade = FADE_move.val()
  1176. cprint("EXEC._exec_go() len=",len(rdata),cfg)
  1177. if xfade is None:
  1178. xfade = cfg["FADE"]
  1179. if ptfade is None:
  1180. ptfade = cfg["FADE"]
  1181. #vcmd = reshape_exec( rdata ,value,[],xfade=xfade,fx=1)
  1182. #cprint(rdata,color="red")
  1183. vcmd = execlib.reshape_exec( rdata ,value,xfade=xfade,ptfade=ptfade)
  1184. cmd = []
  1185. delay=0
  1186. for i,v in enumerate(fcmd):
  1187. #print("go",i,v)
  1188. if xFLASH:
  1189. vcmd[i]["FLASH"] = 1
  1190. DMX = fcmd[i]["DMX"]
  1191. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  1192. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  1193. if value is not None:
  1194. vcmd[i]["VALUE"] = value
  1195. if value == "off":
  1196. if "FX2" in vcmd:
  1197. vcmd[i]["FX2"]["TYPE"] = value
  1198. if "FIX" in fcmd:
  1199. vcmd[i]["FIX"] = fcmd["FIX"]
  1200. if DMX and vcmd[i]:
  1201. vcmd[i]["DMX"] = DMX
  1202. if type(nr) is not type(None):
  1203. vcmd[i]["EXEC"] = str(int(nr)+1)
  1204. cmd.append(vcmd[i])
  1205. if cmd and not modes.val("BLIND"):
  1206. jclient_send(cmd)
  1207. def render(self):
  1208. #Xroot.bind("<Key>",tk_event(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  1209. #self.draw_input()
  1210. pass
  1211. ##draw_sub_dim
  1212. import tkgui.dialog as dialoglib
  1213. dialog = dialoglib.Dialog()
  1214. from tkgui.draw import *
  1215. from tkgui.GUI import *
  1216. class LOAD_SHOW_AND_RESTART():
  1217. def __init__(self,fname=""):
  1218. self.fname=fname
  1219. self.base = showlib.Base()
  1220. def cb(self,event=None,force=0):
  1221. print()
  1222. print()
  1223. print()
  1224. cprint("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname),color="red" )
  1225. if not self.fname and not force:
  1226. return 0
  1227. if self.base.show_name == self.fname and not force:
  1228. cprint("filename is the same",self.fname)
  1229. return 0
  1230. if not force:
  1231. self.base._set(self.fname)
  1232. cprint("LOAD SHOW:",event,self.fname)
  1233. BASE_PATH = "/opt/LibreLight/Xdesk/"
  1234. cmd="_LibreLightDesk.py"
  1235. arg = ""
  1236. print("fork",[BASE_PATH,cmd,arg])
  1237. if "--easy" in sys.argv:
  1238. arg = "--easy"
  1239. movewin.process_kill(BASE_PATH+"tksdl/")
  1240. os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
  1241. sys.exit()
  1242. lf_nr = 0
  1243. from tkinter import PhotoImage
  1244. _shift_key = 0
  1245. class WindowManager():
  1246. def __init__(self):
  1247. self.windows = {}
  1248. self.obj = {}
  1249. self.nr= 0
  1250. self.first=""
  1251. self.window_init_buffer = {}
  1252. def update(self,w,name="",obj=None):
  1253. name = str(name)
  1254. for k in self.windows:
  1255. if k == name:
  1256. self.windows[str(name)] = w
  1257. self.obj[str(name)] = obj
  1258. def new(self,w,name="",obj=None,wcb=None):
  1259. name = str(name)
  1260. if wcb and name:
  1261. self.window_init_buffer[name] = wcb
  1262. if not self.first:
  1263. if name:
  1264. self.first = name
  1265. else:
  1266. self.first = str(self.nr)
  1267. if w:
  1268. w.tk.state(newstate='normal')
  1269. w.tk.attributes('-topmost',True)
  1270. if name:
  1271. self.windows[str(name)] = w
  1272. self.obj[str(name)] = obj
  1273. else:
  1274. self.windows[str(self.nr)] = w
  1275. self.obj[str(self.nr)] = obj
  1276. self.nr+=1
  1277. def mainloop(self):
  1278. self.windows[self.first].mainloop()
  1279. def get_win(self,name):
  1280. #cprint(".get_win(name) =",name)
  1281. name = str(name)
  1282. if name in self.windows:
  1283. out = self.windows[name]
  1284. #cprint(out)
  1285. return out
  1286. def get(self,name):
  1287. return get_win(name)
  1288. def get_obj(self,name):
  1289. name = str(name)
  1290. if name in self.windows:
  1291. out = self.obj[name]
  1292. return out
  1293. def create(self,name):
  1294. #cprint( "create WindowContainer",name)
  1295. if name in self.window_init_buffer:
  1296. c = self.window_init_buffer[name]
  1297. w,obj,cb_ok = c.create()
  1298. window_manager.update(w,name,obj)
  1299. if cb_ok:
  1300. cb_ok()
  1301. resize = 1
  1302. if "resize" in c.args:
  1303. if not c.args["resize"]:
  1304. resize = 0
  1305. #if resize:
  1306. libwin.get_window_position(_filter=name,win=w)
  1307. if name in ["ENCODER"]:
  1308. global _ENCODER_WINDOW
  1309. _ENCODER_WINDOW = w
  1310. if name in ["DIMMER","FIXTURES"]:
  1311. refresher_fix.reset() # = tkrefresh.Refresher()
  1312. def _check_window_is_open(self,name):
  1313. try:
  1314. win = self.windows[name]
  1315. if "tk" not in dir(win):
  1316. return 0
  1317. return win.tk.winfo_exists()
  1318. except Exception as e:
  1319. cprint("_check_window_is_open err",e,color="red")
  1320. def top(self,name):
  1321. name = str(name)
  1322. if name not in self.windows:
  1323. cprint(name," not in self.windows",self.windows.keys())
  1324. return
  1325. if not self._check_window_is_open(name):
  1326. cprint(" ",name," window is closed ! ")
  1327. self.create(name)
  1328. w = self.windows[name]
  1329. if not str(type(w)).startswith("<class 'function'>"):
  1330. w.tk.attributes('-topmost',True)
  1331. w.tk.attributes('-topmost',False)
  1332. w.tk.update_idletasks()
  1333. else:
  1334. print(" 2.2-",w)
  1335. w()
  1336. class Console():
  1337. def __init__(self):
  1338. pass
  1339. def flash_off(self,fix):
  1340. pass
  1341. def fx_off(self,fix):
  1342. cprint("Console.fx_off()",fix)
  1343. if not fix or fix == "all":
  1344. j = []
  1345. if 0:
  1346. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  1347. j.append(jdata)
  1348. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  1349. j.append(jdata)
  1350. else:
  1351. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  1352. j.append(jdata)
  1353. if not modes.val("BLIND"):
  1354. jclient_send(j)
  1355. return 0
  1356. window_manager = WindowManager()
  1357. CONSOLE = Console()
  1358. EXEC = execlib.EXEC()
  1359. def refresh_exec_mc():
  1360. time.sleep(10)
  1361. while 1:
  1362. try:
  1363. pass#
  1364. execlib.exec_set_mc(EXEC.label_exec,EXEC.val_exec)
  1365. except Exception as e:
  1366. print("refresh_exec_mc ERR",e)
  1367. time.sleep(5) # extra time
  1368. time.sleep(3) # refresh time
  1369. thread.start_new_thread(refresh_exec_mc,())
  1370. FIXTURES = fixlib.Fixtures()
  1371. FIXTURES.gui = GUIHandler()
  1372. def LOAD_SHOW():
  1373. EXEC.load_exec()
  1374. FIXTURES.load_patch()
  1375. LOAD_SHOW()
  1376. master = MASTER()
  1377. print("main",__name__)
  1378. import lib.tkrefresh as tkrefresh
  1379. refresher_fix = tkrefresh.Refresher()
  1380. refresher_fix.time_delta = 0.50
  1381. refresher_fix.name = "fix"
  1382. refresher_fix.reset()
  1383. refresher_fix.cb = master._refresh_fix
  1384. refresher_exec = tkrefresh.Refresher()
  1385. refresher_exec.time_delta = 10 #0
  1386. refresher_exec.name = "exec"
  1387. refresher_exec.reset()
  1388. refresher_exec.cb = master._refresh_exec
  1389. refresher_exec = tkrefresh.Refresher()
  1390. refresher_exec.time_delta = 10 #0
  1391. refresher_exec.name = "exec-fader"
  1392. refresher_exec.reset()
  1393. refresher_exec.cb = refresh_exec_fader_cfg
  1394. def loops(**args):
  1395. time.sleep(5) # wait until draw all window's
  1396. cprint("-> run loops")
  1397. thread.start_new_thread(refresher_fix.loop,())
  1398. thread.start_new_thread(refresher_exec.loop,())
  1399. thread.start_new_thread(loops,())
  1400. class window_create_sdl_buffer():
  1401. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  1402. self.args = args.copy()
  1403. self.cls = cls
  1404. self.cb_ok = cb_ok
  1405. self.data = data
  1406. self.scroll = scroll
  1407. self.gui = gui
  1408. def create(self,hidde=0):
  1409. cprint()
  1410. return [self.cls,self.cls,None] #w,obj,cb_ok
  1411. def open_sdl_window():
  1412. cprint("open_sdl_window ... delay 1sec",color="yellow")
  1413. time.sleep(1)
  1414. if "--easy" not in sys.argv:
  1415. movewin.startup_all_sdl()
  1416. thread.start_new_thread(open_sdl_window,())
  1417. mc_fix = MC_FIX()
  1418. def mc_fix_loop():
  1419. global master
  1420. time.sleep(5)
  1421. c=0
  1422. while 1:
  1423. try:
  1424. if c >= 1:
  1425. #master._refresh_exec()
  1426. c=0
  1427. for nr in EXEC.val_exec:
  1428. cfg = get_exec_btn_cfg(nr)
  1429. except Exception as e:
  1430. print("MC_FIX EXCEPTION",e)
  1431. #raise e
  1432. c+=1
  1433. try:
  1434. data = FIXTURES.fixtures
  1435. mc_fix.set(index="fix",data=data)
  1436. except Exception as e:
  1437. print("MC_FIX EXCEPTION",e)
  1438. time.sleep(1/10)
  1439. thread.start_new_thread(mc_fix_loop,())
  1440. if __run_main:
  1441. cprint("main")
  1442. TOP = libtk._POS_TOP + 15
  1443. L0 = libtk._POS_LEFT
  1444. L1 = libtk._POS_LEFT + 95
  1445. L2 = libtk._POS_LEFT + 920
  1446. W1 = 810
  1447. H1 = 550
  1448. HTB = 23 # hight of the titlebar from window manager
  1449. pos_list = libwin.read_window_position()
  1450. #geo = libwin.split_window_position(pos_list,name)
  1451. #args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  1452. #geo = libwin.split_window_position(pos_list,name)
  1453. #if geo:
  1454. # args.update(geo)
  1455. data = []
  1456. #data.append({"text":"COMMAND"})
  1457. #data.append({"text":"CONFIG"})
  1458. data.append({"text":"PATCH"})
  1459. data.append({"text":"DIMMER"})
  1460. data.append({"text":"FIXTURES"})
  1461. data.append({"text":"FIX-LIST"})
  1462. #data.append({"text":"EXEC-BTN","name":"EXEC-BTN"})
  1463. data.append({"text":"EXEC-BTN","name":"EXEC-BTN"})
  1464. data.append({"text":"EXEC-WING"})
  1465. data.append({"text":"---"})
  1466. data.append({"text":"SETUP"})
  1467. data.append({"text":"COMMAND"})
  1468. data.append({"text":"LIVE"})
  1469. data.append({"text":"FX"})
  1470. data.append({"text":"ENCODER"})
  1471. data.append({"text":"COLORPICKER","name":"COLOR"})
  1472. data.append({"text":"---"})
  1473. data.append({"text":"FIXTURE-EDITOR","name":"FIX-EDIT"})
  1474. data.append({"text":"CONFIG"})
  1475. data.append({"text":"SDL-MIDI"})
  1476. data.append({"text":"CLOCK"})
  1477. data.append({"text":"RAY-DMX"})
  1478. data.append({"text":"SDL-DMX"})
  1479. data.append({"text":"SDL-VPU"})
  1480. data.append({"text":"SDL-OSZI"})
  1481. data.append({"text":"---"})
  1482. data.append({"text":"---"})
  1483. data.append({"text":"- DEMO -"})
  1484. data.append({"text":"---"})
  1485. #data.append({"text":"TK-EXEC"})
  1486. #data.append({"text":"EXEC-BTN","name":"EXEC-BTN"})
  1487. data.append({"text":"SDL-STAGE"})
  1488. data.append({"text":"SDL-Shader"})
  1489. data.append({"text":"TABLE"})
  1490. #data.append({"text":"MASTER-WING"})
  1491. name="MAIN"
  1492. args = {"title":"MAIN","master":1,"width":80,"height":H1,"left":L0,"top":TOP,"resize":1}
  1493. geo = libwin.split_window_position(pos_list,name)
  1494. if geo:
  1495. args.update(geo)
  1496. cls = GUI_menu
  1497. cb_ok = None
  1498. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1499. window_manager.new(None,name,wcb=c)
  1500. window_manager.top(name)
  1501. gui_menu_gui = window_manager.get_win(name)
  1502. gui_menu = window_manager.get_obj(name)
  1503. master._refresh_fix()
  1504. # =======================================================================
  1505. if 0:
  1506. name="EXEC-BTN"
  1507. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1508. geo = libwin.split_window_position(pos_list,name)
  1509. if geo:
  1510. args.update(geo)
  1511. data = EXEC
  1512. cls = draw_exec #GUI_ExecWingLayout
  1513. cb_ok = None #set_exec_fader_all
  1514. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1515. window_manager.new(None,name,wcb=c)
  1516. if libwin.split_window_show(pos_list,_filter=name):
  1517. window_manager.top(name)
  1518. #print(dir(cls))
  1519. #print(cls)
  1520. #sys.exit()
  1521. # =======================================================================
  1522. name="SDL-MIDI"
  1523. def sdl_config():
  1524. cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/midi.py &"
  1525. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/midi.py " #&"
  1526. print(cmd)
  1527. #os.popen(cmd)
  1528. def xyz123(cmd):
  1529. os.system(cmd)
  1530. thread.start_new_thread(xyz123,(cmd,))
  1531. return [None,None,None]
  1532. #class window_create_sdl_buffer():
  1533. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1534. geo = libwin.split_window_position(pos_list,name)
  1535. if geo:
  1536. args.update(geo)
  1537. data = []
  1538. cls = sdl_config #: None #GUI_CONF
  1539. cb_ok = None
  1540. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1541. window_manager.new(None,name,wcb=c)
  1542. if libwin.split_window_show(pos_list,_filter=name):
  1543. window_manager.top(name)
  1544. # =======================================================================
  1545. name="SDL-VPU"
  1546. def sdl_config():
  1547. cmd="python3 /opt/LibreLight/Xdesk/vpu/watchdog_vpu.py -single"
  1548. print(cmd)
  1549. def xyz123(cmd):
  1550. os.system(cmd)
  1551. thread.start_new_thread(xyz123,(cmd,))
  1552. return [None,None,None]
  1553. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1554. geo = libwin.split_window_position(pos_list,name)
  1555. if geo:
  1556. args.update(geo)
  1557. data = []
  1558. cls = sdl_config #: None #GUI_CONF
  1559. cb_ok = None
  1560. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1561. window_manager.new(None,name,wcb=c)
  1562. if libwin.split_window_show(pos_list,_filter=name):
  1563. window_manager.top(name)
  1564. # =======================================================================
  1565. name="SDL-OSZI"
  1566. def sdl_config():
  1567. cmd="python3 /opt/LibreLight/ASP/monitor/oszi_grid.py"
  1568. print(cmd)
  1569. def xyz123(cmd):
  1570. os.system(cmd)
  1571. thread.start_new_thread(xyz123,(cmd,))
  1572. return [None,None,None]
  1573. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1574. geo = libwin.split_window_position(pos_list,name)
  1575. if geo:
  1576. args.update(geo)
  1577. data = []
  1578. cls = sdl_config #: None #GUI_CONF
  1579. cb_ok = None
  1580. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1581. window_manager.new(None,name,wcb=c)
  1582. if libwin.split_window_show(pos_list,_filter=name):
  1583. window_manager.top(name)
  1584. # =======================================================================
  1585. name="SDL-DMX"
  1586. def sdl_config():
  1587. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/dmx.py " #&"
  1588. print(cmd)
  1589. def xyz123(cmd):
  1590. os.system(cmd)
  1591. thread.start_new_thread(xyz123,(cmd,))
  1592. return [None,None,None]
  1593. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1594. geo = libwin.split_window_position(pos_list,name)
  1595. if geo:
  1596. args.update(geo)
  1597. data = []
  1598. cls = sdl_config #: None #GUI_CONF
  1599. cb_ok = None
  1600. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1601. window_manager.new(None,name,wcb=c)
  1602. if libwin.split_window_show(pos_list,_filter=name):
  1603. window_manager.top(name)
  1604. # =======================================================================
  1605. name="RAY-DMX"
  1606. def sdl_config():
  1607. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tkray/dmx.py " #&"
  1608. print(cmd)
  1609. def xyz123(cmd):
  1610. os.system(cmd)
  1611. thread.start_new_thread(xyz123,(cmd,))
  1612. return [None,None,None]
  1613. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1614. geo = libwin.split_window_position(pos_list,name)
  1615. if geo:
  1616. args.update(geo)
  1617. data = []
  1618. cls = sdl_config #: None #GUI_CONF
  1619. cb_ok = None
  1620. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1621. window_manager.new(None,name,wcb=c)
  1622. if libwin.split_window_show(pos_list,_filter=name):
  1623. window_manager.top(name)
  1624. # =======================================================================
  1625. name="EXEC-BTN" #"TK-EXEC"
  1626. def sdl_config():
  1627. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tkgui/EXEC-BTN.py " #&"
  1628. print(cmd)
  1629. def xyz123(cmd):
  1630. os.system(cmd)
  1631. thread.start_new_thread(xyz123,(cmd,))
  1632. return [None,None,None]
  1633. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1634. geo = libwin.split_window_position(pos_list,name)
  1635. if geo:
  1636. args.update(geo)
  1637. data = []
  1638. cls = sdl_config #: None #GUI_CONF
  1639. cb_ok = None
  1640. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1641. window_manager.new(None,name,wcb=c)
  1642. if libwin.split_window_show(pos_list,_filter=name):
  1643. window_manager.top(name)
  1644. # =======================================================================
  1645. name="SDL-STAGE"
  1646. def sdl_config():
  1647. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk//3d/stage_3d.py " #&"
  1648. print(cmd)
  1649. def xyz123(cmd):
  1650. os.system(cmd)
  1651. thread.start_new_thread(xyz123,(cmd,))
  1652. return [None,None,None]
  1653. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1654. geo = libwin.split_window_position(pos_list,name)
  1655. if geo:
  1656. args.update(geo)
  1657. data = []
  1658. cls = sdl_config #: None #GUI_CONF
  1659. cb_ok = None
  1660. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1661. window_manager.new(None,name,wcb=c)
  1662. if libwin.split_window_show(pos_list,_filter=name):
  1663. window_manager.top(name)
  1664. # =======================================================================
  1665. name="SDL-Shader"
  1666. def sdl_config():
  1667. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk//3d/demo_shaders.py " #&"
  1668. print(cmd)
  1669. #os.popen(cmd)
  1670. def xyz123(cmd):
  1671. os.system(cmd)
  1672. thread.start_new_thread(xyz123,(cmd,))
  1673. return [None,None,None]
  1674. #class window_create_sdl_buffer():
  1675. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1676. geo = libwin.split_window_position(pos_list,name)
  1677. if geo:
  1678. args.update(geo)
  1679. data = []
  1680. cls = sdl_config #: None #GUI_CONF
  1681. cb_ok = None
  1682. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1683. window_manager.new(None,name,wcb=c)
  1684. if libwin.split_window_show(pos_list,_filter=name):
  1685. window_manager.top(name)
  1686. # =======================================================================
  1687. name="FIX-LIST"
  1688. def sdl_config():
  1689. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/fix.py " #&"
  1690. print(cmd)
  1691. #os.popen(cmd)
  1692. def xyz123(cmd):
  1693. os.system(cmd)
  1694. thread.start_new_thread(xyz123,(cmd,))
  1695. return [None,None,None]
  1696. #class window_create_sdl_buffer():
  1697. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1698. geo = libwin.split_window_position(pos_list,name)
  1699. if geo:
  1700. args.update(geo)
  1701. data = []
  1702. cls = sdl_config #: None #GUI_CONF
  1703. cb_ok = None
  1704. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1705. window_manager.new(None,name,wcb=c)
  1706. if libwin.split_window_show(pos_list,_filter=name):
  1707. window_manager.top(name)
  1708. # =======================================================================
  1709. name="CONFIG"
  1710. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1711. geo = libwin.split_window_position(pos_list,name)
  1712. if geo:
  1713. args.update(geo)
  1714. data = []
  1715. cls = GUI_CONF
  1716. cb_ok = None
  1717. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1718. window_manager.new(None,name,wcb=c)
  1719. if libwin.split_window_show(pos_list,_filter=name):
  1720. window_manager.top(name)
  1721. # =======================================================================
  1722. name="DIMMER"
  1723. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1724. geo = libwin.split_window_position(pos_list,name)
  1725. if geo:
  1726. args.update(geo)
  1727. cls = GUI_DIM
  1728. data = FIXTURES
  1729. ok_cb=None
  1730. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1731. window_manager.new(None,name,wcb=c)
  1732. if libwin.split_window_show(pos_list,_filter=name):
  1733. window_manager.top(name)
  1734. # =======================================================================
  1735. name="FIXTURES"
  1736. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1737. geo = libwin.split_window_position(pos_list,name)
  1738. if geo:
  1739. args.update(geo)
  1740. cls = GUI_FIX
  1741. ok_cb=None
  1742. data = FIXTURES
  1743. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1744. window_manager.new(None,name,wcb=c)
  1745. if libwin.split_window_show(pos_list,_filter=name):
  1746. window_manager.top(name)
  1747. # =======================================================================
  1748. name="FIXTURE-EDITOR"
  1749. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1750. geo = libwin.split_window_position(pos_list,name)
  1751. if geo:
  1752. args.update(geo)
  1753. data=[]
  1754. for i in range(12*6):
  1755. data.append({"text"+str(i):"test"})
  1756. import tkgui.fix as guifix
  1757. cls = guifix.GUI_FixtureEditor
  1758. cb_ok = None
  1759. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1760. window_manager.new(None,name,wcb=c)
  1761. # =======================================================================
  1762. name="MASTER-WING"
  1763. args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220,"resize":0}
  1764. geo = libwin.split_window_position(pos_list,name)
  1765. if geo:
  1766. args.update(geo)
  1767. data=[]
  1768. for i in range(2):
  1769. data.append({"MASTER"+str(i):"MASTER"})
  1770. cls = GUI_MasterWingLayout #(w1,data)
  1771. cb_ok = None
  1772. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1773. window_manager.new(None,name,wcb=c)
  1774. if libwin.split_window_show(pos_list,_filter=name):
  1775. window_manager.top(name)
  1776. # =======================================================================
  1777. name="EXEC-WING"
  1778. args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
  1779. geo = libwin.split_window_position(pos_list,name)
  1780. if geo:
  1781. args.update(geo)
  1782. data=[]
  1783. for i in range(10*3):
  1784. data.append({"EXEC"+str(i):"EXEC"})
  1785. cls = GUI_ExecWingLayout
  1786. cb_ok = set_exec_fader_all
  1787. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1788. window_manager.new(None,name,wcb=c)
  1789. if libwin.split_window_show(pos_list,_filter=name):
  1790. window_manager.top(name)
  1791. # =======================================================================
  1792. name="ENCODER"
  1793. args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
  1794. geo = libwin.split_window_position(pos_list,name)
  1795. if geo:
  1796. args.update(geo)
  1797. cls = draw_enc #(master,w.tk)#Xroot)
  1798. cb_ok = None
  1799. data = FIXTURES #master
  1800. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1801. window_manager.new(None,name,wcb=c)
  1802. if libwin.split_window_show(pos_list,_filter=name):
  1803. window_manager.top(name)
  1804. # =======================================================================
  1805. name = "SETUP"
  1806. args = {"title":name +" SHOW:"+master.base.show_name,
  1807. "master":0,"width":445,"height":42,"left":L1+10+W1,"top":TOP,"resize":10}
  1808. args["title"] = "SETUP SHOW:"+master.base.show_name
  1809. geo = libwin.split_window_position(pos_list,name)
  1810. try:
  1811. geo["width"] = args["width"]
  1812. geo["height"] = args["height"]
  1813. except:pass
  1814. if geo:
  1815. args.update(geo)
  1816. cls = draw_setup #(master,w.tk)
  1817. data = []
  1818. cb_ok = None
  1819. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1820. window_manager.new(None,name,wcb=c)
  1821. if libwin.split_window_show(pos_list,_filter=name):
  1822. window_manager.top(name)
  1823. # =======================================================================
  1824. name = "COMMAND"
  1825. args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":10}
  1826. geo = libwin.split_window_position(pos_list,name)
  1827. if geo:
  1828. args.update(geo)
  1829. cls = draw_command #(master,w.tk)
  1830. data = []
  1831. cb_ok = None
  1832. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1833. window_manager.new(None,name,wcb=c)
  1834. if libwin.split_window_show(pos_list,_filter=name):
  1835. window_manager.top(name)
  1836. # =======================================================================
  1837. name = "LIVE"
  1838. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":10}
  1839. geo = libwin.split_window_position(pos_list,name)
  1840. if geo:
  1841. args.update(geo)
  1842. cls = draw_live #(master,w.tk)
  1843. data = []
  1844. cb_ok = None
  1845. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1846. window_manager.new(None,name,wcb=c)
  1847. if libwin.split_window_show(pos_list,_filter=name):
  1848. window_manager.top(name)
  1849. # =======================================================================
  1850. name = "CLOCK"
  1851. args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
  1852. geo = libwin.split_window_position(pos_list,name)
  1853. if geo:
  1854. args.update(geo)
  1855. cclock = X_CLOCK()
  1856. cls = cclock.draw_clock
  1857. data = []
  1858. cb_ok = None
  1859. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1860. window_manager.new(None,name,wcb=c)
  1861. if libwin.split_window_show(pos_list,_filter=name):
  1862. window_manager.top(name)
  1863. # =======================================================================
  1864. name="FX"
  1865. args = {"title":name,"master":0,"width":415,"height":297+30,"left":L1+10+W1,"top":TOP+302,"resize":1}
  1866. geo = libwin.split_window_position(pos_list,name)
  1867. if geo:
  1868. args.update(geo)
  1869. cls = draw_fx #(master,w.tk)
  1870. data = []
  1871. cb_ok = None
  1872. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1873. window_manager.new(None,name,wcb=c)
  1874. if libwin.split_window_show(pos_list,_filter=name):
  1875. window_manager.top(name)
  1876. # =======================================================================
  1877. name="PATCH"
  1878. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP,"foot":1,"head":1}
  1879. geo = libwin.split_window_position(pos_list,name)
  1880. if geo:
  1881. args.update(geo)
  1882. cls = GUI_PATCH
  1883. data = FIXTURES
  1884. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1885. window_manager.new(None,name,wcb=c) #,obj)
  1886. if libwin.split_window_show(pos_list,_filter=name):
  1887. window_manager.top(name)
  1888. # =======================================================================
  1889. name="COLORPICKER"
  1890. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  1891. geo = libwin.split_window_position(pos_list,name)
  1892. if geo:
  1893. args.update(geo)
  1894. cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
  1895. data = [FIXTURES,master]
  1896. cb_ok = None #FIXTURES
  1897. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1898. window_manager.new(None,name,wcb=c)
  1899. if libwin.split_window_show(pos_list,_filter=name):
  1900. window_manager.top(name)
  1901. # =======================================================================
  1902. name="TABLE"
  1903. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  1904. geo = libwin.split_window_position(pos_list,name)
  1905. if geo:
  1906. args.update(geo)
  1907. #cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
  1908. cls = TableFrame #(root=w.tk)#,left=80,top=620)
  1909. data = [FIXTURES,master]
  1910. cb_ok = None #FIXTURES
  1911. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1912. window_manager.new(None,name,wcb=c)
  1913. if libwin.split_window_show(pos_list,_filter=name):
  1914. window_manager.top(name)
  1915. def wm_mainloop():
  1916. try:
  1917. window_manager.mainloop()
  1918. finally:
  1919. print()
  1920. print()
  1921. cmd="xset -display :0.0 r rate 240 20"
  1922. os.system(cmd)
  1923. cprint(" - EXIT -",color="red")
  1924. BASE_PATH = "/opt/LibreLight/Xdesk/"
  1925. movewin.process_kill(BASE_PATH+"tksdl/")
  1926. master.exit()
  1927. sys.exit()
  1928. wm_mainloop() #window_manager.mainloop()
  1929. # thread.start_new_thread(wm_mainloop,()) # break TKINTER !!!
  1930. while 1:
  1931. print("loop..")
  1932. time.sleep(1)