_LibreLightDesk.py 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514
  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(6)
  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. x=self.mc.get(ip)
  394. #print(ip,len(x))
  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_to_usb():
  622. cprint("*** "*20,color="yellow")
  623. cprint("+++ "*20,color="yellow")
  624. cprint("*** "*20,color="yellow")
  625. CMD = "df | grep /media/$USER"
  626. CMD = "ls /media/$USER/"
  627. r = os.popen(CMD)
  628. usbs = r.readlines()
  629. print("USB's:",usbs)
  630. for usb in usbs:
  631. usb = usb.strip()
  632. print(usb)
  633. _usbstick_path = "/media/user/"+str(usb)+"/LibreLight/show/"
  634. SHOW_DIR = libwin.showlib.SHOW_DIR
  635. try:
  636. cwd = os.getcwd()
  637. print("cwd:",cwd)
  638. cd = "/".join(_usbstick_path.split("/")[:4])
  639. os.chdir(cd)
  640. mkdir = "/".join(_usbstick_path.split("/")[4:])
  641. libwin.showlib.SHOW_DIR = _usbstick_path
  642. movewin.showlib.SHOW_DIR = _usbstick_path
  643. _show_name = showlib.current_show_name()
  644. _usbstick_path_name = _usbstick_path + str(_show_name)
  645. mkdir += str(_show_name)
  646. CMD="mkdir -p '{}'".format(mkdir)
  647. print("CMD:",cd,";",CMD)
  648. os.system(CMD)
  649. EXEC.base.show_path = _usbstick_path_name
  650. FIXTURES.base.show_path = _usbstick_path_name
  651. movewin.SHOW_PATH = _usbstick_path_name
  652. a=EXEC.backup_exec()
  653. b=FIXTURES.backup_patch()
  654. c=libwin.save_window_position()
  655. d=movewin.store_all_sdl()
  656. except FileNotFoundError as e:
  657. cprint("EXC",e,color="red")
  658. finally:
  659. # reset
  660. os.chdir(cwd)
  661. EXEC.base.show_path = SHOW_DIR
  662. FIXTURES.base.show_path = SHOW_DIR
  663. libwin.showlib.SHOW_DIR = SHOW_DIR
  664. movewin.SHOW_PATH = showlib.current_show_path()
  665. cprint("*** "*20,color="yellow")
  666. print(cwd,os.getcwd())
  667. cprint("--- "*20,color="yellow")
  668. cprint("--- "*20,color="yellow")
  669. cprint("--- "*20,color="yellow")
  670. def save_show(fpath=None,new=0):
  671. if 1:
  672. save_show_to_usb()
  673. if fpath:
  674. a=EXEC.backup_exec(save_as=fpath,new=new)
  675. b=FIXTURES.backup_patch(save_as=fpath,new=new)
  676. c=libwin.save_window_position(save_as=fpath)
  677. d=movewin.store_all_sdl()
  678. else:
  679. print()
  680. print()
  681. cprint("SAVE SHOW ..",color="yellow")
  682. a=EXEC.backup_exec()
  683. b=FIXTURES.backup_patch()
  684. c=libwin.save_window_position()
  685. d=movewin.store_all_sdl()
  686. if a and b and d: # and c
  687. cprint("SAVE SHOW OK",[fpath,new],[a,b,c,d],color="green")
  688. print()
  689. print()
  690. print()
  691. return 1
  692. cprint("SAVE SHOW FAIL",[fpath,new],[a,b,c,d],color="red")
  693. print()
  694. print()
  695. print()
  696. def save_show_as(fname,new=0):
  697. print()
  698. print()
  699. fpath = showlib.generate_show_path(fname)
  700. info = "SAVE SHOW AS"
  701. if new:
  702. info = "SAVE (NEW) SHOW AS"
  703. cprint(info,fpath,fname,color="green")
  704. if showlib.create_new_show_path(fpath):
  705. return save_show(fpath,new)
  706. import lib.showlib as showlib
  707. class cb():
  708. def __init__(self,win):
  709. self.win = win
  710. def _callback(self,event):
  711. clobj=event.widget
  712. ## undermouse=find_withtag(master.CURRENT)
  713. undermouse=self.win.find_closest(self.win.CURRENT)
  714. cprint( repr(undermouse))
  715. def callback(self,event):
  716. cprint(__file__,self,"callback",event)
  717. cnv = self.win
  718. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  719. tags = cnv.gettags(item)
  720. #cnv.itemconfigure(self.tag, text=tags[0])
  721. cprint(tags,item)
  722. color = cnv.itemcget(item, "fill")
  723. cnv.itemconfig("all", width=1)#filla="green")
  724. cnv.itemconfig(item, width=3)#filla="green")
  725. cprint(color)
  726. cprint( hex_to_rgb(color[1:]))
  727. import copy
  728. def get_exec_btn_cfg(nr):
  729. k = nr
  730. if 1:
  731. _bg = "grey"
  732. _ba = "grey"
  733. _fg = "lightgrey"
  734. _text = "N/V"
  735. txt = "None/nNone"
  736. txt1 = "None/nNone"
  737. if nr >= 0:
  738. if nr != k:
  739. return #continue
  740. label = ""
  741. if k in EXEC.label_exec:
  742. label = EXEC.label_exec[k]
  743. ifval = 0
  744. fx_only = 0
  745. fx_color = 0
  746. if k in EXEC.val_exec and len(EXEC.val_exec[k]) :
  747. sdata = EXEC.val_exec[k]
  748. have_fx = 0
  749. have_val = 0
  750. fix_count = 0
  751. BTN="go"
  752. if "CFG" in sdata:#["BUTTON"] = "GO"
  753. if "BUTTON" in sdata["CFG"]:
  754. BTN = sdata["CFG"]["BUTTON"]
  755. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  756. _text = txt
  757. if len(sdata) > 1:
  758. ifval = 1
  759. val_color = 0
  760. for fix in sdata:
  761. if fix == "CFG":
  762. continue
  763. fix_count += 1
  764. for attr in sdata[fix]:
  765. if attr.startswith("_"):
  766. continue
  767. if "FX2" in sdata[fix][attr]:
  768. if sdata[fix][attr]["FX2"]:
  769. fx_color = 1
  770. have_fx += 1
  771. if "FX" in sdata[fix][attr]:
  772. if sdata[fix][attr]["FX"]:
  773. fx_color = 1
  774. have_fx += 1
  775. if "VALUE" in sdata[fix][attr]:
  776. if sdata[fix][attr]["VALUE"] is not None:
  777. val_color = 1
  778. have_val += 1
  779. #if val_color:
  780. # have_val += 1
  781. #if fx_color:
  782. # have_fx += 1
  783. if val_color:
  784. _bg = "gold"
  785. _ba = "#ffaa55"
  786. if fx_color:
  787. _fg = "blue"
  788. else:
  789. if fx_color:
  790. fx_only = 1
  791. else:
  792. _bg = "grey"
  793. _ba = "#aaa"
  794. sdata["CFG"]["HAVE-FX"] = have_fx
  795. sdata["CFG"]["HAVE-VAL"] = have_val
  796. sdata["CFG"]["FIX-COUNT"] = fix_count
  797. if "\n" in txt:
  798. txt1 = txt.split("\n")[0]
  799. _fg = "black"
  800. if ifval:
  801. if fx_only:
  802. _bg = "cyan"
  803. _ba = "#55d4ff"
  804. if "SEL" in txt1:
  805. _bg = "#77f"
  806. else:
  807. _bg = "grey"
  808. _fg = "darkgrey"
  809. if "SEL" in txt1:
  810. _fg = "blue"
  811. elif "ON" in txt1:
  812. _fg = "#040"
  813. elif "GO" in txt1:
  814. _fg = "#555"
  815. if "FL" in txt1:
  816. _fg = "#00e"
  817. out = {} # default
  818. out["fx"] = ""
  819. out["bg"] = "lightgrey"
  820. out["ba"] = "grey"
  821. out["fg"] = "grey"
  822. out["text"] = "?"
  823. out["fx"] = fx_color
  824. out["bg"] = _bg
  825. out["ba"] = _ba
  826. out["fg"] = _fg
  827. out["text"] = _text
  828. return out
  829. class Elem_Container():
  830. def __init__(self):
  831. self.commands = []
  832. self.val = {}
  833. self.elem = {}
  834. import lib.execlib as execlib
  835. class MASTER():
  836. def __init__(self):
  837. self.base = showlib.Base ()
  838. self.load()
  839. self._XX = 0
  840. self.all_attr =["DIM","PAN","TILT"]
  841. self.elem_attr = {}
  842. self.setup_elem = {} # Elem_Container()
  843. self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI","PRO\nMODE"]
  844. self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","PRO\nMODE"]
  845. self.fx_main = Elem_Container()
  846. self.fx_main.commands =["REC-FX","FX OFF","\n"]
  847. self.fx_moves = Elem_Container()
  848. self.fx_moves.commands =[
  849. "FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  850. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  851. ]
  852. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  853. self.fx = Elem_Container()
  854. self.fx.commands =[
  855. "FX:DIM"," ", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  856. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","2D-X:\n-","2D:MODE"
  857. ]
  858. self.fx_generic = Elem_Container()
  859. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","FX:STATIC"]
  860. self.fx_color = Elem_Container()
  861. self.fx_color.commands =["FX:RED","FX-C:A","FX-C:B"]
  862. self.commands = Elem_Container()
  863. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  864. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  865. ,"BLIND","CLEAR","REC","EDIT","COPY",".","\n"
  866. ]
  867. for i in range(8*8*8):
  868. if i not in EXEC.val_exec:
  869. name = "Preset:"+str(i+1)+":\nXYZ"
  870. #self.exec[i] = [i]
  871. EXEC.val_exec[i] = OrderedDict() # FIX
  872. EXEC.val_exec[i]["CFG"] = OrderedDict() # CONFIG
  873. EXEC.label_exec[i] = "-"
  874. modes.set_cb(self.xcb)
  875. def jclient_send(self,data):
  876. # namespace wraper
  877. if not modes.val("BLIND"):
  878. jclient_send(data)
  879. def button_refresh(self,name,color,color2=None,text="",fg=None):
  880. #cprint("button_refresh",name,color)
  881. if color2 is None:
  882. color2 = color
  883. if text:
  884. text = "\n"+str(text)
  885. elem=None
  886. for elem in [self.commands.elem,self.fx.elem,self.fx_main.elem,self.fx_moves.elem]:
  887. try:
  888. if name in elem:
  889. #print(" in xx.elem OK ",[name,color,name,text,color2])
  890. if name in ["BLIND","CLEAR"] and color == "lightgrey":
  891. color = "grey"
  892. color2 = "grey"
  893. elem[name]["bg"] = color
  894. elem[name]["text"] = name+ text
  895. elem[name].config(activebackground=color2)
  896. if fg:
  897. elem[name]["fg"] = fg
  898. except Exception as e:
  899. cprint(" master.button_refresh",self,e)
  900. cprint(" ",elem)
  901. def dialog_cfg_return(self,nr):
  902. # buffer nr
  903. def _cb(data):
  904. cfg = EXEC._btn_cfg(nr)
  905. button = EXEC.btn_cfg(nr)
  906. label = EXEC.label(nr)
  907. if not data:
  908. cprint("err443",self,"_cb",data)
  909. return None
  910. cprint("btn_cfg._cb()",data)
  911. if data:
  912. if "Button" in data and type(data["Button"]) is str:
  913. txt = data["Button"]
  914. EXEC.btn_cfg(nr,txt)
  915. if "Label" in data and type(data["Label"]) is str:
  916. txt = data["Label"]
  917. EXEC.label(nr,txt)
  918. if "Delay" in data and type(data["Delay"]) is str:
  919. txt = data["Delay"]
  920. try:
  921. txt = float(txt)
  922. if "DELAY" in cfg:
  923. cfg["DELAY"] = round(txt,2)
  924. except e as Exception:
  925. print("DELAY Exception",e)
  926. if "in-Fade" in data and type(data["in-Fade"]) is str:
  927. txt = data["in-Fade"]
  928. try:
  929. txt = float(txt)
  930. if "FADE" in cfg:
  931. cfg["FADE"] = round(txt,2)
  932. except e as Exception:
  933. print("in-Fade Exception",e)
  934. if "out-Fade" in data and type(data["out-Fade"]) is str:
  935. txt = data["out-Fade"]
  936. try:
  937. txt = float(txt)
  938. cfg["OUT-FADE"] = round(txt,2)
  939. except e as Exception:
  940. print("out-Fade Exception",e)
  941. modes.val("CFG-BTN",0)
  942. master._refresh_exec(nr=nr)
  943. return _cb
  944. def btn_cfg(self,nr,testing=0):
  945. cfg = EXEC._btn_cfg(nr)
  946. button = EXEC.btn_cfg(nr)
  947. label = EXEC.label(nr)
  948. dialog._cb = self.dialog_cfg_return(nr) # return cb()
  949. if 1: # testing:
  950. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  951. else:
  952. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  953. def label(self,nr):
  954. txt = EXEC.label(nr)
  955. def _cb(data):
  956. if not data:
  957. cprint("err443",self,"_cb",data)
  958. return None
  959. txt = data["Value"]
  960. cprint("label._cb()",nr,txt)
  961. if txt:
  962. EXEC.label(nr,txt)
  963. modes.val("LABEL", 0)
  964. master._refresh_exec(nr=nr)
  965. dialog._cb= _cb #_x(nr)
  966. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  967. def button_clear(self):
  968. modes.clear()
  969. txt=""
  970. for m in modes.modes:
  971. if not modes.modes[m]:
  972. self.button_refresh(m,color="lightgrey",text=txt)
  973. def xcb(self,mode,value=None):
  974. cprint(" Master.xcb mode:",str(mode).rjust(10," "),value,color="yellow",end="")
  975. if value:
  976. cprint("===== ON ======",color="green")
  977. txt = ""
  978. if mode == "REC-FX":
  979. modes.modes["REC"] = 1 # HACK !
  980. self.button_refresh("REC",color="red",text=txt)#,fg="blue")
  981. self.button_refresh(mode,color="red",text=txt)#,fg="blue")
  982. if value == 2:
  983. if mode in ["MOVE","COPY"]:
  984. txt="to"
  985. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  986. else:
  987. if mode in ["MOVE","COPY"]:
  988. txt="from"
  989. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  990. else:
  991. cprint("===== OFF ======",color="red")
  992. if mode == "REC":
  993. modes.val("REC-FX",0)
  994. if mode == "REC-FX":
  995. modes.modes["REC"] = 0 # HACK !
  996. self.button_refresh("REC",color="lightgrey")#,fg="black")
  997. self.button_refresh(mode,color="lightgrey")#,fg="black")
  998. #modes.info()
  999. def load(self,fname=""):
  1000. pass
  1001. def exit(self):
  1002. cprint("__del__",self)
  1003. def refresh_exec(self):
  1004. refresher_exec.reset() # = tkrefresh.Refresher()
  1005. def _refresh_exec(self,nr=-1):
  1006. s = time.time()
  1007. cprint("EXEC.refresh_exec()")
  1008. refresher_exec.reset() # = tkrefresh.Refresher()
  1009. self._XX +=1
  1010. self._nr_ok = 0
  1011. ERR=""
  1012. for nr in EXEC.val_exec:
  1013. cfg = get_exec_btn_cfg(nr)
  1014. time.sleep(0.01)
  1015. def refresh_fix(self):
  1016. refresher_fix.reset() # = tkrefresh.Refresher()
  1017. def _refresh_fix(self):
  1018. cprint("_refresh_fix")
  1019. s=time.time(); _XXX=0
  1020. menu_buff = {"DIM":0,"DIM-SUB":0,"FIX":0,"FIX-SUB":0}
  1021. elem_buffer = []
  1022. for fix in FIXTURES.fixtures:
  1023. sdata = FIXTURES.fixtures[fix]
  1024. elem_attr_fix = None
  1025. if fix in self.elem_attr:
  1026. elem_attr_fix = self.elem_attr[fix]
  1027. if "DIM" in sdata["ATTRIBUT"] and "_ACTIVE" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 2:
  1028. KEY = "DIM-SUB"
  1029. else:
  1030. KEY = "FIX-SUB"
  1031. FIX = 0
  1032. DIM = 0
  1033. for attr in sdata["ATTRIBUT"]:
  1034. _buff = {}
  1035. row = sdata["ATTRIBUT"][attr]
  1036. if attr.endswith("-FINE"):
  1037. continue
  1038. b_attr = attr
  1039. if b_attr == "_ACTIVE":
  1040. b_attr = "S"
  1041. elem = None
  1042. if elem_attr_fix:
  1043. if b_attr not in elem_attr_fix:
  1044. continue
  1045. elem = elem_attr_fix[b_attr]
  1046. if not elem:
  1047. continue
  1048. if "elem" not in _buff:
  1049. _buff["elem"] = elem
  1050. if not attr.startswith("_"):
  1051. v2 = row["VALUE"]
  1052. #_text = "{} {}".format(str(attr).rjust(4,"0"),str(v2).rjust(4,"0")) # ~0.2 sec
  1053. _text = "{} {}".format(attr,v2)
  1054. _buff["text"] = _text
  1055. if row["ACTIVE"]:
  1056. _buff["bg"] = "yellow"
  1057. _buff["abg"] = "yellow"
  1058. menu_buff[KEY] += 1
  1059. if b_attr == "S":
  1060. if KEY == "DIM-SUB":
  1061. DIM =1
  1062. else:
  1063. FIX =1
  1064. else:
  1065. _buff["bg"] = "grey"
  1066. _buff["abg"] = "grey"
  1067. if "FX" not in row: # insert FX2 excetption
  1068. row["FX"] = "" #OrderedDict()
  1069. if "FX2" not in row: # insert FX2 excetption
  1070. row["FX2"] = {} #OrderedDict()
  1071. #print("row",fix,row)
  1072. if row["FX"]:
  1073. _buff["fg"] = "blue"
  1074. elif row["FX2"]:
  1075. _buff["fg"] = "red"
  1076. else:
  1077. _buff["fg"] = "black"
  1078. elem_buffer.append(_buff)
  1079. menu_buff["FIX"] += FIX
  1080. menu_buff["DIM"] += DIM
  1081. try:
  1082. for row in elem_buffer:
  1083. elem = row["elem"]
  1084. if not elem:
  1085. continue
  1086. for e in row:
  1087. if e == "elem":
  1088. continue
  1089. v = row[e]
  1090. if e == "abg":
  1091. elem.config(activebackground=v)
  1092. else:
  1093. elem[e] = v
  1094. w = window_manager.get_win("FIXTURES")
  1095. if w:
  1096. w.update_idle_task()
  1097. except Exception as e:
  1098. cprint("exc434",e,color="red")
  1099. cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
  1100. cprint(gui_menu)
  1101. menu_buff["FIX-SUB"] -= menu_buff["FIX"]
  1102. if menu_buff["FIX-SUB"]:
  1103. gui_menu.config("FIXTURES","bg","yellow")
  1104. gui_menu.config("FIXTURES","activebackground","yellow")
  1105. elif menu_buff["FIX"]:
  1106. gui_menu.config("FIXTURES","bg","orange")
  1107. gui_menu.config("FIXTURES","activebackground","orange")
  1108. else:
  1109. gui_menu.config("FIXTURES","bg","")
  1110. gui_menu.config("FIXTURES","activebackground","")
  1111. gui_menu.update("FIXTURES","{} : {}".format(menu_buff["FIX"],menu_buff["FIX-SUB"]))
  1112. menu_buff["DIM-SUB"] -= menu_buff["DIM"]
  1113. if menu_buff["DIM-SUB"]:
  1114. gui_menu.config("DIMMER","bg","yellow")
  1115. gui_menu.config("DIMMER","activebackground","yellow")
  1116. elif menu_buff["DIM"]:
  1117. gui_menu.config("DIMMER","bg","orange")
  1118. gui_menu.config("DIMMER","activebackground","orange")
  1119. else:
  1120. gui_menu.config("DIMMER","bg","")
  1121. gui_menu.config("DIMMER","activebackground","")
  1122. gui_menu.update("DIMMER","{} : {}".format(menu_buff["DIM"],menu_buff["DIM-SUB"]))
  1123. cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
  1124. def exec_rec(self,nr):
  1125. cprint("Master.exec_rec","-- EXEC RECORD ------------------------------")
  1126. _filter=""
  1127. if modes.val("REC-FX"):
  1128. _filter="ONLY-FX"
  1129. data = fixlib.get_active(FIXTURES.fixtures,_filter=_filter)
  1130. EXEC.rec(nr,data)
  1131. sdata=data
  1132. EXEC.val_exec[nr] = sdata
  1133. modes.val("REC-FX",0)
  1134. modes.val("REC",0)
  1135. cfg = get_exec_btn_cfg(nr)
  1136. #master._refresh_exec()
  1137. return 1
  1138. def exec_edit(self,nr):
  1139. cprint("Master.exec_edit","-- EXEC EDIT ------------------------------")
  1140. fixlib.clear(MAIN.FIXTURES.fixtures)
  1141. self.exec_select(nr)
  1142. event=None
  1143. self.exec_go(nr,xfade=0,event=event,val=255,button="go")
  1144. modes.val("EDIT", 0)
  1145. master.refresh_fix()
  1146. refresher_fix.reset() # = tkrefresh.Refresher()
  1147. def exec_select(self,nr):
  1148. cprint("Master.exec_select","-- EXEC SELECT ------------------------------")
  1149. sdata = EXEC.val_exec[nr]
  1150. cmd = ""
  1151. for fix in sdata:
  1152. if fix == "CFG":
  1153. continue
  1154. for attr in sdata[fix]:
  1155. #v2 = sdata[fix][attr]["VALUE"]
  1156. #v2_fx = sdata[fix][attr]["FX"]
  1157. #print( self.data.elem_attr)
  1158. #if fix in self.elem_attr:
  1159. # if attr in self.elem_attr[fix]:
  1160. # elem = self.elem_attr[fix][attr]
  1161. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  1162. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  1163. #elem["bg"] = "yellow"
  1164. def exec_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  1165. s=time.time()
  1166. t_start = time.time()
  1167. if xfade is None and FADE._is():
  1168. xfade = FADE.val()
  1169. if ptfade is None and FADE_move._is():
  1170. ptfade = FADE_move.val()
  1171. print()
  1172. cprint("Master.exec_go","-- EXEC GO FADE -----",nr,val)
  1173. rdata = EXEC.get_raw_map(nr)
  1174. if not rdata:
  1175. return 0
  1176. cfg = EXEC.get_cfg(nr)
  1177. if not cfg:
  1178. cprint(" NO CFG",cfg,nr)
  1179. return 0
  1180. xFLASH = 0
  1181. value=None
  1182. cprint(" exec_go",nr,cfg)
  1183. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  1184. self.exec_select(nr)
  1185. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  1186. xFLASH = 1
  1187. xfade = 0
  1188. if type(val) is not type(None) and val == 0 :
  1189. value = "off"
  1190. xfade=0
  1191. if "OUT-FADE" in cfg:
  1192. xfade=cfg["OUT-FADE"]
  1193. if event:
  1194. if str(event.type) == "ButtonRelease" or event.type == '5' :
  1195. value = "off"
  1196. xfade=0
  1197. if "OUT-FADE" in cfg:
  1198. xfade=cfg["OUT-FADE"]
  1199. cprint(" exec_go() FLUSH",value,color="red")
  1200. #print(";",rdata)
  1201. print(" cfg:",cfg)
  1202. fcmd = FIXTURES.update_raw(rdata,update=0)
  1203. #print(":",fcmd) # raw dmx
  1204. self._exec_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  1205. elif not val:
  1206. cprint("exec_go() STOP",value,color="red")
  1207. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  1208. fcmd = FIXTURES.update_raw(rdata)
  1209. self._exec_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  1210. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  1211. fcmd = FIXTURES.update_raw(rdata)
  1212. e=time.time()
  1213. #print("_GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
  1214. self._exec_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  1215. e=time.time()
  1216. #print("GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
  1217. return
  1218. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  1219. self.refresh_exec()
  1220. self.refresh_fix()
  1221. cprint("exec_go",time.time()-t_start)
  1222. def _exec_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  1223. if xfade is None and FADE._is():
  1224. xfade = FADE.val()
  1225. if ptfade is None and FADE_move._is():
  1226. ptfade = FADE_move.val()
  1227. cprint("EXEC._exec_go() len=",len(rdata),cfg)
  1228. if xfade is None:
  1229. xfade = cfg["FADE"]
  1230. if ptfade is None:
  1231. ptfade = cfg["FADE"]
  1232. #vcmd = reshape_exec( rdata ,value,[],xfade=xfade,fx=1)
  1233. #cprint(rdata,color="red")
  1234. vcmd = execlib.reshape_exec( rdata ,value,xfade=xfade,ptfade=ptfade)
  1235. cmd = []
  1236. delay=0
  1237. for i,v in enumerate(fcmd):
  1238. #print("go",i,v)
  1239. if xFLASH:
  1240. vcmd[i]["FLASH"] = 1
  1241. DMX = fcmd[i]["DMX"]
  1242. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  1243. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  1244. if value is not None:
  1245. vcmd[i]["VALUE"] = value
  1246. if value == "off":
  1247. if "FX2" in vcmd:
  1248. vcmd[i]["FX2"]["TYPE"] = value
  1249. if "FIX" in fcmd:
  1250. vcmd[i]["FIX"] = fcmd["FIX"]
  1251. if DMX and vcmd[i]:
  1252. vcmd[i]["DMX"] = DMX
  1253. if type(nr) is not type(None):
  1254. vcmd[i]["EXEC"] = str(int(nr)+1)
  1255. cmd.append(vcmd[i])
  1256. if cmd and not modes.val("BLIND"):
  1257. jclient_send(cmd)
  1258. def render(self):
  1259. #Xroot.bind("<Key>",tk_event(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  1260. #self.draw_input()
  1261. pass
  1262. ##draw_sub_dim
  1263. import tkgui.dialog as dialoglib
  1264. dialog = dialoglib.Dialog()
  1265. from tkgui.draw import *
  1266. from tkgui.GUI import *
  1267. class LOAD_SHOW_AND_RESTART():
  1268. def __init__(self,fname=""):
  1269. self.fname=fname
  1270. self.base = showlib.Base()
  1271. def cb(self,event=None,force=0):
  1272. print()
  1273. print()
  1274. print()
  1275. cprint("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname),color="red" )
  1276. if not self.fname and not force:
  1277. return 0
  1278. if self.base.show_name == self.fname and not force:
  1279. cprint("filename is the same",self.fname)
  1280. return 0
  1281. if not force:
  1282. self.base._set(self.fname)
  1283. cprint("LOAD SHOW:",event,self.fname)
  1284. BASE_PATH = "/opt/LibreLight/Xdesk/"
  1285. cmd="_LibreLightDesk.py"
  1286. arg = ""
  1287. print("fork",[BASE_PATH,cmd,arg])
  1288. if "--easy" in sys.argv:
  1289. arg = "--easy"
  1290. movewin.process_kill(BASE_PATH+"tksdl/")
  1291. os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
  1292. sys.exit()
  1293. lf_nr = 0
  1294. from tkinter import PhotoImage
  1295. _shift_key = 0
  1296. class WindowManager():
  1297. def __init__(self):
  1298. self.windows = {}
  1299. self.obj = {}
  1300. self.nr= 0
  1301. self.first=""
  1302. self.window_init_buffer = {}
  1303. def update(self,w,name="",obj=None):
  1304. name = str(name)
  1305. for k in self.windows:
  1306. if k == name:
  1307. self.windows[str(name)] = w
  1308. self.obj[str(name)] = obj
  1309. def new(self,w,name="",obj=None,wcb=None):
  1310. name = str(name)
  1311. if wcb and name:
  1312. self.window_init_buffer[name] = wcb
  1313. if not self.first:
  1314. if name:
  1315. self.first = name
  1316. else:
  1317. self.first = str(self.nr)
  1318. if w:
  1319. w.tk.state(newstate='normal')
  1320. w.tk.attributes('-topmost',True)
  1321. if name:
  1322. self.windows[str(name)] = w
  1323. self.obj[str(name)] = obj
  1324. else:
  1325. self.windows[str(self.nr)] = w
  1326. self.obj[str(self.nr)] = obj
  1327. self.nr+=1
  1328. def mainloop(self):
  1329. self.windows[self.first].mainloop()
  1330. def get_win(self,name):
  1331. #cprint(".get_win(name) =",name)
  1332. name = str(name)
  1333. if name in self.windows:
  1334. out = self.windows[name]
  1335. #cprint(out)
  1336. return out
  1337. def get(self,name):
  1338. return get_win(name)
  1339. def get_obj(self,name):
  1340. name = str(name)
  1341. if name in self.windows:
  1342. out = self.obj[name]
  1343. return out
  1344. def create(self,name):
  1345. #cprint( "create WindowContainer",name)
  1346. if name in self.window_init_buffer:
  1347. c = self.window_init_buffer[name]
  1348. w,obj,cb_ok = c.create()
  1349. window_manager.update(w,name,obj)
  1350. if cb_ok:
  1351. cb_ok()
  1352. resize = 1
  1353. if "resize" in c.args:
  1354. if not c.args["resize"]:
  1355. resize = 0
  1356. #if resize:
  1357. libwin.get_window_position(_filter=name,win=w)
  1358. if name in ["ENCODER"]:
  1359. global _ENCODER_WINDOW
  1360. _ENCODER_WINDOW = w
  1361. if name in ["DIMMER","FIXTURES"]:
  1362. refresher_fix.reset() # = tkrefresh.Refresher()
  1363. def _check_window_is_open(self,name):
  1364. try:
  1365. win = self.windows[name]
  1366. if "tk" not in dir(win):
  1367. return 0
  1368. return win.tk.winfo_exists()
  1369. except Exception as e:
  1370. cprint("_check_window_is_open err",e,color="red")
  1371. def top(self,name):
  1372. name = str(name)
  1373. if name not in self.windows:
  1374. cprint(name," not in self.windows",self.windows.keys())
  1375. return
  1376. if not self._check_window_is_open(name):
  1377. cprint(" ",name," window is closed ! ")
  1378. self.create(name)
  1379. w = self.windows[name]
  1380. if not str(type(w)).startswith("<class 'function'>"):
  1381. w.tk.attributes('-topmost',True)
  1382. w.tk.attributes('-topmost',False)
  1383. w.tk.update_idletasks()
  1384. else:
  1385. print(" 2.2-",w)
  1386. w()
  1387. class Console():
  1388. def __init__(self):
  1389. pass
  1390. def flash_off(self,fix):
  1391. pass
  1392. def fx_off(self,fix):
  1393. cprint("Console.fx_off()",fix)
  1394. if not fix or fix == "all":
  1395. j = []
  1396. if 0:
  1397. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  1398. j.append(jdata)
  1399. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  1400. j.append(jdata)
  1401. else:
  1402. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  1403. j.append(jdata)
  1404. if not modes.val("BLIND"):
  1405. jclient_send(j)
  1406. return 0
  1407. window_manager = WindowManager()
  1408. CONSOLE = Console()
  1409. EXEC = execlib.EXEC()
  1410. def refresh_exec_mc():
  1411. time.sleep(10)
  1412. while 1:
  1413. try:
  1414. pass#
  1415. execlib.exec_set_mc(EXEC.label_exec,EXEC.val_exec)
  1416. except Exception as e:
  1417. print("refresh_exec_mc ERR",e)
  1418. time.sleep(5) # extra time
  1419. time.sleep(3) # refresh time
  1420. thread.start_new_thread(refresh_exec_mc,())
  1421. FIXTURES = fixlib.Fixtures()
  1422. FIXTURES.gui = GUIHandler()
  1423. def LOAD_SHOW():
  1424. EXEC.load_exec()
  1425. FIXTURES.load_patch()
  1426. LOAD_SHOW()
  1427. master = MASTER()
  1428. print("main",__name__)
  1429. import lib.tkrefresh as tkrefresh
  1430. refresher_fix = tkrefresh.Refresher()
  1431. refresher_fix.time_delta = 0.50
  1432. refresher_fix.name = "fix"
  1433. refresher_fix.reset()
  1434. refresher_fix.cb = master._refresh_fix
  1435. refresher_exec = tkrefresh.Refresher()
  1436. refresher_exec.time_delta = 10 #0
  1437. refresher_exec.name = "exec"
  1438. refresher_exec.reset()
  1439. refresher_exec.cb = master._refresh_exec
  1440. refresher_exec = tkrefresh.Refresher()
  1441. refresher_exec.time_delta = 10 #0
  1442. refresher_exec.name = "exec-fader"
  1443. refresher_exec.reset()
  1444. refresher_exec.cb = refresh_exec_fader_cfg
  1445. def loops(**args):
  1446. time.sleep(5) # wait until draw all window's
  1447. cprint("-> run loops")
  1448. thread.start_new_thread(refresher_fix.loop,())
  1449. thread.start_new_thread(refresher_exec.loop,())
  1450. thread.start_new_thread(loops,())
  1451. class window_create_sdl_buffer():
  1452. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  1453. self.args = args.copy()
  1454. self.cls = cls
  1455. self.cb_ok = cb_ok
  1456. self.data = data
  1457. self.scroll = scroll
  1458. self.gui = gui
  1459. def create(self,hidde=0):
  1460. cprint()
  1461. return [self.cls,self.cls,None] #w,obj,cb_ok
  1462. def open_sdl_window():
  1463. cprint("open_sdl_window ... delay 1sec",color="yellow")
  1464. time.sleep(1)
  1465. if "--easy" not in sys.argv:
  1466. movewin.startup_all_sdl()
  1467. thread.start_new_thread(open_sdl_window,())
  1468. mc_fix = MC_FIX()
  1469. def mc_fix_loop():
  1470. global master
  1471. time.sleep(5)
  1472. c=0
  1473. while 1:
  1474. try:
  1475. if c >= 1:
  1476. #master._refresh_exec()
  1477. c=0
  1478. for nr in EXEC.val_exec:
  1479. cfg = get_exec_btn_cfg(nr)
  1480. except Exception as e:
  1481. print("MC_FIX EXCEPTION",e)
  1482. #raise e
  1483. c+=1
  1484. try:
  1485. data = FIXTURES.fixtures
  1486. mc_fix.set(index="fix",data=data)
  1487. except Exception as e:
  1488. print("MC_FIX EXCEPTION",e)
  1489. time.sleep(1/10)
  1490. thread.start_new_thread(mc_fix_loop,())
  1491. if __run_main:
  1492. cprint("main")
  1493. TOP = libtk._POS_TOP + 15
  1494. L0 = libtk._POS_LEFT
  1495. L1 = libtk._POS_LEFT + 95
  1496. L2 = libtk._POS_LEFT + 920
  1497. W1 = 810
  1498. H1 = 550
  1499. HTB = 23 # hight of the titlebar from window manager
  1500. pos_list = libwin.read_window_position()
  1501. #geo = libwin.split_window_position(pos_list,name)
  1502. #args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  1503. #geo = libwin.split_window_position(pos_list,name)
  1504. #if geo:
  1505. # args.update(geo)
  1506. data = []
  1507. #data.append({"text":"COMMAND"})
  1508. #data.append({"text":"CONFIG"})
  1509. data.append({"text":"PATCH"})
  1510. data.append({"text":"DIMMER"})
  1511. data.append({"text":"FIXTURES"})
  1512. data.append({"text":"FIX-LIST"})
  1513. #data.append({"text":"EXEC-BTN","name":"EXEC-BTN"})
  1514. data.append({"text":"EXEC-BTN","name":"EXEC-BTN"})
  1515. data.append({"text":"EXEC-WING"})
  1516. data.append({"text":"---"})
  1517. data.append({"text":"SETUP"})
  1518. data.append({"text":"COMMAND"})
  1519. data.append({"text":"LIVE"})
  1520. data.append({"text":"FX"})
  1521. data.append({"text":"ENCODER"})
  1522. data.append({"text":"COLORPICKER","name":"COLOR"})
  1523. data.append({"text":"---"})
  1524. data.append({"text":"FIXTURE-EDITOR","name":"FIX-EDIT"})
  1525. data.append({"text":"CONFIG"})
  1526. data.append({"text":"SDL-MIDI"})
  1527. data.append({"text":"CLOCK"})
  1528. data.append({"text":"RAY-DMX"})
  1529. data.append({"text":"SDL-DMX"})
  1530. data.append({"text":"SDL-VPU"})
  1531. data.append({"text":"SDL-OSZI"})
  1532. data.append({"text":"Nodescanner","name":"NodeScan"})
  1533. data.append({"text":"---"})
  1534. data.append({"text":"---"})
  1535. data.append({"text":"- DEMO -"})
  1536. data.append({"text":"---"})
  1537. data.append({"text":"XWING"})
  1538. #data.append({"text":"TK-EXEC"})
  1539. #data.append({"text":"EXEC-BTN","name":"EXEC-BTN"})
  1540. data.append({"text":"SDL-STAGE"})
  1541. data.append({"text":"SDL-Shader"})
  1542. data.append({"text":"TABLE"})
  1543. #data.append({"text":"MASTER-WING"})
  1544. name="MAIN"
  1545. args = {"title":"MAIN","master":1,"width":80,"height":H1,"left":L0,"top":TOP,"resize":1}
  1546. geo = libwin.split_window_position(pos_list,name)
  1547. if geo:
  1548. args.update(geo)
  1549. cls = GUI_menu
  1550. cb_ok = None
  1551. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1552. window_manager.new(None,name,wcb=c)
  1553. window_manager.top(name)
  1554. gui_menu_gui = window_manager.get_win(name)
  1555. gui_menu = window_manager.get_obj(name)
  1556. master._refresh_fix()
  1557. # =======================================================================
  1558. if 0:
  1559. name="EXEC-BTN"
  1560. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1561. geo = libwin.split_window_position(pos_list,name)
  1562. if geo:
  1563. args.update(geo)
  1564. data = EXEC
  1565. cls = draw_exec #GUI_ExecWingLayout
  1566. cb_ok = None #set_exec_fader_all
  1567. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1568. window_manager.new(None,name,wcb=c)
  1569. if libwin.split_window_show(pos_list,_filter=name):
  1570. window_manager.top(name)
  1571. #print(dir(cls))
  1572. #print(cls)
  1573. #sys.exit()
  1574. # =======================================================================
  1575. name="SDL-MIDI"
  1576. def sdl_config():
  1577. cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/midi.py &"
  1578. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/midi.py " #&"
  1579. print(cmd)
  1580. #os.popen(cmd)
  1581. def xyz123(cmd):
  1582. os.system(cmd)
  1583. thread.start_new_thread(xyz123,(cmd,))
  1584. return [None,None,None]
  1585. #class window_create_sdl_buffer():
  1586. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1587. geo = libwin.split_window_position(pos_list,name)
  1588. if geo:
  1589. args.update(geo)
  1590. data = []
  1591. cls = sdl_config #: None #GUI_CONF
  1592. cb_ok = None
  1593. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1594. window_manager.new(None,name,wcb=c)
  1595. if libwin.split_window_show(pos_list,_filter=name):
  1596. window_manager.top(name)
  1597. # =======================================================================
  1598. name="SDL-VPU"
  1599. def sdl_config():
  1600. cmd="python3 /opt/LibreLight/Xdesk/vpu/watchdog_vpu.py -single"
  1601. print(cmd)
  1602. def xyz123(cmd):
  1603. os.system(cmd)
  1604. thread.start_new_thread(xyz123,(cmd,))
  1605. return [None,None,None]
  1606. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1607. geo = libwin.split_window_position(pos_list,name)
  1608. if geo:
  1609. args.update(geo)
  1610. data = []
  1611. cls = sdl_config #: None #GUI_CONF
  1612. cb_ok = None
  1613. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1614. window_manager.new(None,name,wcb=c)
  1615. if libwin.split_window_show(pos_list,_filter=name):
  1616. window_manager.top(name)
  1617. # =======================================================================
  1618. name="SDL-OSZI"
  1619. def sdl_config():
  1620. cmd="python3 /opt/LibreLight/ASP/monitor/oszi_grid.py"
  1621. print(cmd)
  1622. def xyz123(cmd):
  1623. os.system(cmd)
  1624. thread.start_new_thread(xyz123,(cmd,))
  1625. return [None,None,None]
  1626. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1627. geo = libwin.split_window_position(pos_list,name)
  1628. if geo:
  1629. args.update(geo)
  1630. data = []
  1631. cls = sdl_config #: None #GUI_CONF
  1632. cb_ok = None
  1633. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1634. window_manager.new(None,name,wcb=c)
  1635. if libwin.split_window_show(pos_list,_filter=name):
  1636. window_manager.top(name)
  1637. # =======================================================================
  1638. name="SDL-DMX"
  1639. def sdl_config():
  1640. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/dmx.py " #&"
  1641. print(cmd)
  1642. def xyz123(cmd):
  1643. os.system(cmd)
  1644. thread.start_new_thread(xyz123,(cmd,))
  1645. return [None,None,None]
  1646. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1647. geo = libwin.split_window_position(pos_list,name)
  1648. if geo:
  1649. args.update(geo)
  1650. data = []
  1651. cls = sdl_config #: None #GUI_CONF
  1652. cb_ok = None
  1653. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1654. window_manager.new(None,name,wcb=c)
  1655. if libwin.split_window_show(pos_list,_filter=name):
  1656. window_manager.top(name)
  1657. # =======================================================================
  1658. name="RAY-DMX"
  1659. def sdl_config():
  1660. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tkray/dmx.py " #&"
  1661. print(cmd)
  1662. def xyz123(cmd):
  1663. os.system(cmd)
  1664. thread.start_new_thread(xyz123,(cmd,))
  1665. return [None,None,None]
  1666. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1667. geo = libwin.split_window_position(pos_list,name)
  1668. if geo:
  1669. args.update(geo)
  1670. data = []
  1671. cls = sdl_config #: None #GUI_CONF
  1672. cb_ok = None
  1673. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1674. window_manager.new(None,name,wcb=c)
  1675. if libwin.split_window_show(pos_list,_filter=name):
  1676. window_manager.top(name)
  1677. # =======================================================================
  1678. name="EXEC-BTN" #"TK-EXEC"
  1679. def sdl_config():
  1680. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tkgui/EXEC-BTN.py " #&"
  1681. print(cmd)
  1682. def xyz123(cmd):
  1683. os.system(cmd)
  1684. thread.start_new_thread(xyz123,(cmd,))
  1685. return [None,None,None]
  1686. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1687. geo = libwin.split_window_position(pos_list,name)
  1688. if geo:
  1689. args.update(geo)
  1690. data = []
  1691. cls = sdl_config #: None #GUI_CONF
  1692. cb_ok = None
  1693. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1694. window_manager.new(None,name,wcb=c)
  1695. if libwin.split_window_show(pos_list,_filter=name):
  1696. window_manager.top(name)
  1697. # =======================================================================
  1698. # =======================================================================
  1699. name="Nodescanner" #"TK-EXEC"
  1700. def sdl_config():
  1701. cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tool/TK-Nodescanner.py" #&"
  1702. print(cmd)
  1703. def xyz123(cmd):
  1704. os.system(cmd)
  1705. thread.start_new_thread(xyz123,(cmd,))
  1706. return [None,None,None]
  1707. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1708. geo = libwin.split_window_position(pos_list,name)
  1709. if geo:
  1710. args.update(geo)
  1711. data = []
  1712. cls = sdl_config #: None #GUI_CONF
  1713. cb_ok = None
  1714. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1715. window_manager.new(None,name,wcb=c)
  1716. if libwin.split_window_show(pos_list,_filter=name):
  1717. window_manager.top(name)
  1718. # =======================================================================
  1719. # =======================================================================
  1720. name="XWING" #"TK-EXEC"
  1721. def sdl_config():
  1722. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tkgui/EXEC-XWING.py " #&"
  1723. print(cmd)
  1724. def xyz123(cmd):
  1725. os.system(cmd)
  1726. thread.start_new_thread(xyz123,(cmd,))
  1727. return [None,None,None]
  1728. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1729. geo = libwin.split_window_position(pos_list,name)
  1730. if geo:
  1731. args.update(geo)
  1732. data = []
  1733. cls = sdl_config #: None #GUI_CONF
  1734. cb_ok = None
  1735. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1736. window_manager.new(None,name,wcb=c)
  1737. if libwin.split_window_show(pos_list,_filter=name):
  1738. window_manager.top(name)
  1739. # =======================================================================
  1740. name="SDL-STAGE"
  1741. def sdl_config():
  1742. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk//3d/stage_3d.py " #&"
  1743. print(cmd)
  1744. def xyz123(cmd):
  1745. os.system(cmd)
  1746. thread.start_new_thread(xyz123,(cmd,))
  1747. return [None,None,None]
  1748. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1749. geo = libwin.split_window_position(pos_list,name)
  1750. if geo:
  1751. args.update(geo)
  1752. data = []
  1753. cls = sdl_config #: None #GUI_CONF
  1754. cb_ok = None
  1755. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1756. window_manager.new(None,name,wcb=c)
  1757. if libwin.split_window_show(pos_list,_filter=name):
  1758. window_manager.top(name)
  1759. # =======================================================================
  1760. name="SDL-Shader"
  1761. def sdl_config():
  1762. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk//3d/demo_shaders.py " #&"
  1763. print(cmd)
  1764. #os.popen(cmd)
  1765. def xyz123(cmd):
  1766. os.system(cmd)
  1767. thread.start_new_thread(xyz123,(cmd,))
  1768. return [None,None,None]
  1769. #class window_create_sdl_buffer():
  1770. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1771. geo = libwin.split_window_position(pos_list,name)
  1772. if geo:
  1773. args.update(geo)
  1774. data = []
  1775. cls = sdl_config #: None #GUI_CONF
  1776. cb_ok = None
  1777. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1778. window_manager.new(None,name,wcb=c)
  1779. if libwin.split_window_show(pos_list,_filter=name):
  1780. window_manager.top(name)
  1781. # =======================================================================
  1782. name="FIX-LIST"
  1783. def sdl_config():
  1784. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/fix.py " #&"
  1785. print(cmd)
  1786. #os.popen(cmd)
  1787. def xyz123(cmd):
  1788. os.system(cmd)
  1789. thread.start_new_thread(xyz123,(cmd,))
  1790. return [None,None,None]
  1791. #class window_create_sdl_buffer():
  1792. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1793. geo = libwin.split_window_position(pos_list,name)
  1794. if geo:
  1795. args.update(geo)
  1796. data = []
  1797. cls = sdl_config #: None #GUI_CONF
  1798. cb_ok = None
  1799. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1800. window_manager.new(None,name,wcb=c)
  1801. if libwin.split_window_show(pos_list,_filter=name):
  1802. window_manager.top(name)
  1803. # =======================================================================
  1804. name="CONFIG"
  1805. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1806. geo = libwin.split_window_position(pos_list,name)
  1807. if geo:
  1808. args.update(geo)
  1809. data = []
  1810. cls = GUI_CONF
  1811. cb_ok = None
  1812. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1813. window_manager.new(None,name,wcb=c)
  1814. if libwin.split_window_show(pos_list,_filter=name):
  1815. window_manager.top(name)
  1816. # =======================================================================
  1817. name="DIMMER"
  1818. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1819. geo = libwin.split_window_position(pos_list,name)
  1820. if geo:
  1821. args.update(geo)
  1822. cls = GUI_DIM
  1823. data = FIXTURES
  1824. ok_cb=None
  1825. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1826. window_manager.new(None,name,wcb=c)
  1827. if libwin.split_window_show(pos_list,_filter=name):
  1828. window_manager.top(name)
  1829. # =======================================================================
  1830. name="FIXTURES"
  1831. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1832. geo = libwin.split_window_position(pos_list,name)
  1833. if geo:
  1834. args.update(geo)
  1835. cls = GUI_FIX
  1836. ok_cb=None
  1837. data = FIXTURES
  1838. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1839. window_manager.new(None,name,wcb=c)
  1840. if libwin.split_window_show(pos_list,_filter=name):
  1841. window_manager.top(name)
  1842. # =======================================================================
  1843. name="FIXTURE-EDITOR"
  1844. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  1845. geo = libwin.split_window_position(pos_list,name)
  1846. if geo:
  1847. args.update(geo)
  1848. data=[]
  1849. for i in range(12*6):
  1850. data.append({"text"+str(i):"test"})
  1851. import tkgui.fix as guifix
  1852. cls = guifix.GUI_FixtureEditor
  1853. cb_ok = None
  1854. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1855. window_manager.new(None,name,wcb=c)
  1856. # =======================================================================
  1857. name="MASTER-WING"
  1858. args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220,"resize":0}
  1859. geo = libwin.split_window_position(pos_list,name)
  1860. if geo:
  1861. args.update(geo)
  1862. data=[]
  1863. for i in range(2):
  1864. data.append({"MASTER"+str(i):"MASTER"})
  1865. cls = GUI_MasterWingLayout #(w1,data)
  1866. cb_ok = None
  1867. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1868. window_manager.new(None,name,wcb=c)
  1869. if libwin.split_window_show(pos_list,_filter=name):
  1870. window_manager.top(name)
  1871. # =======================================================================
  1872. name="EXEC-WING"
  1873. args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
  1874. geo = libwin.split_window_position(pos_list,name)
  1875. if geo:
  1876. args.update(geo)
  1877. data=[]
  1878. for i in range(10*3):
  1879. data.append({"EXEC"+str(i):"EXEC"})
  1880. cls = GUI_ExecWingLayout
  1881. cb_ok = set_exec_fader_all
  1882. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1883. window_manager.new(None,name,wcb=c)
  1884. if libwin.split_window_show(pos_list,_filter=name):
  1885. window_manager.top(name)
  1886. # =======================================================================
  1887. name="ENCODER"
  1888. args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
  1889. geo = libwin.split_window_position(pos_list,name)
  1890. if geo:
  1891. args.update(geo)
  1892. cls = draw_enc #(master,w.tk)#Xroot)
  1893. cb_ok = None
  1894. data = FIXTURES #master
  1895. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1896. window_manager.new(None,name,wcb=c)
  1897. if libwin.split_window_show(pos_list,_filter=name):
  1898. window_manager.top(name)
  1899. # =======================================================================
  1900. name = "SETUP"
  1901. args = {"title":name +" SHOW:"+master.base.show_name,
  1902. "master":0,"width":445,"height":42,"left":L1+10+W1,"top":TOP,"resize":10}
  1903. args["title"] = "SETUP SHOW:"+master.base.show_name
  1904. geo = libwin.split_window_position(pos_list,name)
  1905. try:
  1906. geo["width"] = args["width"]
  1907. geo["height"] = args["height"]
  1908. except:pass
  1909. if geo:
  1910. args.update(geo)
  1911. cls = draw_setup #(master,w.tk)
  1912. data = []
  1913. cb_ok = None
  1914. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1915. window_manager.new(None,name,wcb=c)
  1916. if libwin.split_window_show(pos_list,_filter=name):
  1917. window_manager.top(name)
  1918. # =======================================================================
  1919. name = "COMMAND"
  1920. args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":10}
  1921. geo = libwin.split_window_position(pos_list,name)
  1922. if geo:
  1923. args.update(geo)
  1924. cls = draw_command #(master,w.tk)
  1925. data = []
  1926. cb_ok = None
  1927. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1928. window_manager.new(None,name,wcb=c)
  1929. if libwin.split_window_show(pos_list,_filter=name):
  1930. window_manager.top(name)
  1931. # =======================================================================
  1932. name = "LIVE"
  1933. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":10}
  1934. geo = libwin.split_window_position(pos_list,name)
  1935. if geo:
  1936. args.update(geo)
  1937. cls = draw_live #(master,w.tk)
  1938. data = []
  1939. cb_ok = None
  1940. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1941. window_manager.new(None,name,wcb=c)
  1942. if libwin.split_window_show(pos_list,_filter=name):
  1943. window_manager.top(name)
  1944. # =======================================================================
  1945. name = "CLOCK"
  1946. args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
  1947. geo = libwin.split_window_position(pos_list,name)
  1948. if geo:
  1949. args.update(geo)
  1950. cclock = X_CLOCK()
  1951. cls = cclock.draw_clock
  1952. data = []
  1953. cb_ok = None
  1954. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1955. window_manager.new(None,name,wcb=c)
  1956. if libwin.split_window_show(pos_list,_filter=name):
  1957. window_manager.top(name)
  1958. # =======================================================================
  1959. name="FX"
  1960. args = {"title":name,"master":0,"width":415,"height":297+30,"left":L1+10+W1,"top":TOP+302,"resize":1}
  1961. geo = libwin.split_window_position(pos_list,name)
  1962. if geo:
  1963. args.update(geo)
  1964. cls = draw_fx #(master,w.tk)
  1965. data = []
  1966. cb_ok = None
  1967. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1968. window_manager.new(None,name,wcb=c)
  1969. if libwin.split_window_show(pos_list,_filter=name):
  1970. window_manager.top(name)
  1971. # =======================================================================
  1972. name="PATCH"
  1973. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP,"foot":1,"head":1}
  1974. geo = libwin.split_window_position(pos_list,name)
  1975. if geo:
  1976. args.update(geo)
  1977. cls = GUI_PATCH
  1978. data = FIXTURES
  1979. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  1980. window_manager.new(None,name,wcb=c) #,obj)
  1981. if libwin.split_window_show(pos_list,_filter=name):
  1982. window_manager.top(name)
  1983. # =======================================================================
  1984. name="COLORPICKER"
  1985. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  1986. geo = libwin.split_window_position(pos_list,name)
  1987. if geo:
  1988. args.update(geo)
  1989. cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
  1990. data = [FIXTURES,master]
  1991. cb_ok = None #FIXTURES
  1992. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  1993. window_manager.new(None,name,wcb=c)
  1994. if libwin.split_window_show(pos_list,_filter=name):
  1995. window_manager.top(name)
  1996. # =======================================================================
  1997. name="TABLE"
  1998. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  1999. geo = libwin.split_window_position(pos_list,name)
  2000. if geo:
  2001. args.update(geo)
  2002. #cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
  2003. cls = TableFrame #(root=w.tk)#,left=80,top=620)
  2004. data = [FIXTURES,master]
  2005. cb_ok = None #FIXTURES
  2006. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2007. window_manager.new(None,name,wcb=c)
  2008. if libwin.split_window_show(pos_list,_filter=name):
  2009. window_manager.top(name)
  2010. def wm_mainloop():
  2011. try:
  2012. window_manager.mainloop()
  2013. finally:
  2014. print()
  2015. print()
  2016. cmd="xset -display :0.0 r rate 240 20"
  2017. os.system(cmd)
  2018. cprint(" - EXIT -",color="red")
  2019. BASE_PATH = "/opt/LibreLight/Xdesk/"
  2020. movewin.process_kill(BASE_PATH+"tksdl/")
  2021. master.exit()
  2022. sys.exit()
  2023. wm_mainloop() #window_manager.mainloop()
  2024. # thread.start_new_thread(wm_mainloop,()) # break TKINTER !!!
  2025. while 1:
  2026. print("loop..")
  2027. time.sleep(1)