_LibreLightDesk.py 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635
  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. IS_GUI = 0
  18. if __name__ == "__main__":
  19. IS_GUI = 1
  20. import tool.movewin as movewin
  21. import lib.fixlib as fixlib
  22. import lib.libwin as libwin
  23. rnd_id = str(random.randint(100,900))
  24. rnd_id += " beta"
  25. rnd_id2 = ""
  26. rnd_id3 = ""
  27. _ENCODER_WINDOW = None
  28. import tool.git as git
  29. rnd_id += git.get_all()
  30. try:
  31. xtitle = __file__
  32. except:
  33. xtitle = "__file__"
  34. if "/" in xtitle:
  35. xtitle = xtitle.split("/")[-1]
  36. sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title
  37. HOME = os.getenv('HOME')
  38. space_font = None
  39. if IS_GUI:
  40. import tkinter
  41. import tkinter as tk
  42. from tkinter import font
  43. import tkinter.simpledialog
  44. from idlelib.tooltip import Hovertip
  45. INIT_OK = 0
  46. _global_short_key = 1
  47. path = "/home/user/LibreLight/"
  48. #os.chdir(path)
  49. f = open(path+"init.txt","r")
  50. lines=f.readlines()
  51. f.close()
  52. out = []
  53. for line in lines:
  54. if line != "EASY\n":
  55. out.append(line)
  56. f = open(path+"init.txt","w")
  57. f.writelines(out)
  58. f.close()
  59. if "--easy" in sys.argv:
  60. f = open(path+"init.txt","a")
  61. f.write("EASY\n")
  62. f.close()
  63. if not os.path.isdir(path+"show/EASY"):
  64. cmd = "cp -vrf '/opt/LibreLight/Xdesk/home/LibreLight/show/EASY' '{}/show/EASY' ".format(path)
  65. print(cmd)
  66. #input()
  67. os.system(cmd)
  68. # check if EASY show exist !
  69. from lib.cprint import *
  70. cprint("________________________________")
  71. import lib.zchat as chat
  72. import lib.motion as motion
  73. from collections import OrderedDict
  74. _FIX_FADE_ATTR = ["PAN","TILT","DIM","RED","GREEN","BLUE","WHITE","CYAN","YELLOW","MAGENTA","FOCUS","ZOOM","FROST"]
  75. _POS_LEFT = 0
  76. _POS_TOP = 15
  77. _config = []
  78. try:
  79. h = os.environ["HOME"]
  80. lines = [{}]
  81. try:
  82. f = open(h +"/LibreLight/config.json")
  83. lines = f.readlines()
  84. except FileNotFoundError as e: #Exception as e:
  85. f = open(h +"/LibreLight/config.json","w")
  86. f.write('{"POS_TOP":0}\n{"POS_LEFT":0}')
  87. f.close()
  88. cprint("Exception:",e)
  89. cprint("config read")
  90. for line in lines:
  91. line=line.strip()
  92. print(" config:",line)
  93. row = json.loads(line)
  94. _config.append(row)
  95. except Exception as e:
  96. cprint("Exception:",e)
  97. try:
  98. for row in _config:
  99. #print(" config:",row)
  100. if "POS_LEFT" in row:
  101. _POS_LEFT = int(row["POS_LEFT"])
  102. if "POS_TOP" in row:
  103. _POS_TOP = int(row["POS_TOP"])
  104. except Exception as e:
  105. cprint("Exception:",e)
  106. CUES = OrderedDict()
  107. groups = OrderedDict()
  108. class Modes():
  109. def __init__(self):
  110. self.modes = {}
  111. self.__cfg = {}
  112. self.__cb = None
  113. def val(self,mode,value=None): #like jquery
  114. if value is not None:
  115. return self.set(mode,value)
  116. elif mode in self.modes:
  117. return self.modes[mode]
  118. def get(self,mode,value=None):
  119. return self.val(mode,value)
  120. def __check(self,mode):
  121. if mode not in self.modes:
  122. self.modes[mode] = 0
  123. self.__cfg[mode] = 0
  124. def cfg(self,mode,data={}):
  125. self.__check(mode)
  126. if type(data) is dict:
  127. for k in data:
  128. v = data[k]
  129. if v not in self.__cfg:
  130. self.__cfg[k] = v
  131. return 1
  132. elif type(data) is str:
  133. if data in self.__cfg:
  134. return self.__cfg[data]
  135. def set(self,mode,value):
  136. protected = ["BLIND","CLEAR","REC-FX"]
  137. self.__check(mode)
  138. if mode == "CLEAR":
  139. return 1
  140. elif mode == "ESC":
  141. for m in self.modes:
  142. cprint("ESC",m)
  143. if m == "COPY":
  144. PRESETS.clear_copy()
  145. if m == "MOVE":
  146. PRESETS.clear_move()
  147. if m != "BLIND":
  148. self.modes[m] = 0
  149. self.callback(m)
  150. return 1
  151. if value:
  152. for m in self.modes:
  153. if m not in protected and mode not in protected and m != mode:
  154. #cprint("-#-# clear mode",mode,m,value,color="red")
  155. if self.modes[m]:
  156. self.modes[m]= 0
  157. self.callback(m)
  158. if self.modes[mode] and value == 1:
  159. if modes == "MOVE":
  160. PRESETS.clear_move()
  161. if modes == "COPY":
  162. PRESETS.clear_copy()
  163. self.modes[mode] = 0 # value
  164. else:
  165. self.modes[mode] = value #1 #value
  166. else:
  167. self.modes[mode] = 0 #value
  168. if modes == "COPY":
  169. PRESETS.clear_copy()
  170. if modes == "MOVE":
  171. PRESETS.clear_move()
  172. self.callback(mode)
  173. return value
  174. def set_cb(self,cb):
  175. if cb:
  176. self.__cb = cb
  177. def callback(self,mode):
  178. if self.__cb is not None and mode in self.modes:
  179. value = self.modes[mode]
  180. self.__cb(mode=mode,value=value)
  181. modes = Modes()
  182. #modes.val("BLIND", 0)
  183. #modes.modes["BLIND"] = 0
  184. modes.modes["ESC"] = 0
  185. modes.modes["REC"] = 0
  186. modes.modes["EDIT"] = 0
  187. modes.modes["MOVE"] = 0
  188. modes.modes["FLASH"] = 0
  189. modes.modes["GO"] = 0
  190. modes.modes["DEL"] = 0
  191. modes.modes["REC-FX"] = 0
  192. modes.modes["SELECT"] = 0
  193. modes.modes["CFG-BTN"] = 0
  194. modes.modes["LABEL"] = 0
  195. def xcb(mode,value=None):
  196. cprint("xcb","MODE CALLBACK",mode,value)
  197. if mode == "REC-FX":
  198. cprint("xcb",modes.val("REC-FX"))
  199. #modes.set_cb(xcb)
  200. POS = ["PAN","TILT","MOTION"]
  201. COLOR = ["RED","GREEN","BLUE","COLOR"]
  202. BEAM = ["GOBO","G-ROT","PRISMA","P-ROT","FOCUS","SPEED"]
  203. INT = ["DIM","SHUTTER","STROBE","FUNC"]
  204. #client = chat.tcp_sender(port=50001)
  205. def set_exec_fader_cfg(nr,val,label="",color=""):
  206. exec_wing = window_manager.get_obj(name="EXEC-WING")
  207. if not exec_wing:
  208. return
  209. try:
  210. if len(exec_wing.fader_elem) > nr:
  211. exec_wing.fader_elem[nr].attr["text"] = label
  212. cfg = get_exec_btn_cfg(nr+80)
  213. if cfg:
  214. exec_wing.fader_elem[nr].attr["bg"] = cfg["bg"]
  215. exec_wing.fader_elem[nr].attr["fg"] = cfg["fg"]
  216. exec_wing.fader_elem[nr].attr["fx"] = cfg["fx"]
  217. except Exception as e:
  218. cprint("- exception:",e)
  219. print(nr,val,label)
  220. def set_exec_fader(nr,val,label="",color="",info="info",change=0):
  221. exec_wing = window_manager.get_obj(name="EXEC-WING")
  222. if not exec_wing:
  223. return
  224. try:
  225. exec_wing.set_fader(nr,val,color=color,info=info,change=change)
  226. except Exception as e:
  227. pass
  228. cprint("- exception:",e)
  229. print(nr,val,label)
  230. raise e
  231. def set_exec_fader_all():
  232. print()
  233. cprint( "set_exec_fader_all()",color="green")
  234. for nr in range(10):
  235. _label = PRESETS.label_presets[nr+80] # = label
  236. print(" _label",_label)
  237. set_exec_fader(nr,0,label=_label)
  238. set_exec_fader_cfg(nr,0,label=_label)
  239. def refresh_exec_fader_cfg():
  240. cprint( "set_exec_fader_all()",color="green")
  241. for nr in range(10):
  242. _label = PRESETS.label_presets[nr+80] # = label
  243. #print("_label",_label)
  244. set_exec_fader_cfg(nr,0,label=_label)
  245. # remote input - start (memcached)
  246. def JCB(x,sock=None):
  247. for i in x:
  248. jv = x[i]
  249. try:
  250. jv = json.loads(jv)
  251. jv = jv[0]
  252. #print(jv)
  253. v = jv["iVAL"]
  254. #exec_wing.set_fader(0,v)
  255. set_exec_fader(0,v)
  256. set_exec_fader(1,200-v)
  257. set_exec_fader(2,int(v/2+10))
  258. except Exception as e:
  259. cprint("exception",e)
  260. print(sys.exc_info()[2])
  261. #print("remote in:",round(time.time(),0),"x",i,v)
  262. if __name__ == "__main__":
  263. r1_server = chat.Server(port=30002)
  264. def server1_loop():
  265. while 1:
  266. r1_server.poll(cb=JCB)
  267. time.sleep(1/90)
  268. thread.start_new_thread(server1_loop,()) # SERVER
  269. # remote input - end
  270. #chat.dbg=1
  271. class DEVENT():
  272. def __init__(self):
  273. #if "keysym" in dir(event):
  274. #if "Escape" ==
  275. #event.keysym:
  276. #event.num == 1:
  277. self.keysym = ""
  278. self.num = 1
  279. self.type = ""
  280. import lib.jsbc as JSBC
  281. if __name__ == "__main__":
  282. # external GUI
  283. r_server = chat.Server(port=30003,cb=JSBC.JSCB)
  284. def server_loop():
  285. while 1:
  286. r_server.poll(cb=JSBC.JSCB)
  287. #time.sleep(1/90)
  288. thread.start_new_thread(server_loop,()) # SERVER
  289. # read memcachd
  290. memcache = None
  291. try:
  292. import memcache
  293. except Exception as e:
  294. cprint("Exception IMPORT ERROR",e)
  295. class MC_FIX():
  296. def __init__(self,server="127.0.0.1",port=11211):
  297. cprint("MC.init() ----------" ,server,port,color="red")
  298. try:
  299. #self.mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  300. self.mc = memcache.Client(['{}:{}'.format(server,port)], debug=0)
  301. #self.init()
  302. except Exception as e:
  303. cprint("-- Exception",e)
  304. def set(self,index="fix",data=[]):
  305. #time.sleep(5)
  306. if 1: #while 1:
  307. #print("MC.send",index) #,data)
  308. index = self.mc.get("index")
  309. #if index:
  310. # for i in index:
  311. # print(" key",i)
  312. self.mc.set("fix", data)
  313. #examles
  314. #self.mc.set("some_key", "Some value")
  315. #self.value = mc.get("some_key")
  316. #self.mc.set("another_key", 3)
  317. #self.mc.delete("another_key")
  318. class MC():
  319. def __init__(self,server="127.0.0.1",port=11211):
  320. cprint("MC.init() ----------" ,server,port,color="red")
  321. try:
  322. #self.mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  323. self.mc = memcache.Client(['{}:{}'.format(server,port)], debug=0)
  324. #self.init()
  325. except Exception as e:
  326. cprint("-- Exception",e)
  327. # def init(self):
  328. data = {}
  329. start = time.time()
  330. delta = start
  331. index = self.mc.get("index")
  332. if index:
  333. for i in index:
  334. print(" key",i)
  335. self.last_fader_val = [-1]*512
  336. self.fader_map = []
  337. for i in range(30+1):
  338. self.fader_map.append({"UNIV":0,"DMX":0})
  339. try:
  340. fname = HOME + "/LibreLight/fader.json"
  341. f = open(fname)
  342. lines = f.readlines()
  343. cprint("FADER MAP",fname)
  344. for i,line in enumerate(lines):
  345. jdata = json.loads(line)
  346. print(" fader_map ->>",i,jdata)
  347. self.fader_map[i] = jdata
  348. except Exception as e:
  349. cprint("-- Except Fader_map",e)
  350. #exit()
  351. def ok(self):
  352. if self.mc:
  353. return 1
  354. return 0
  355. def test(self):
  356. if not self.ok():
  357. return
  358. self.mc.set("some_key", "Some value")
  359. self.value = mc.get("some_key")
  360. self.mc.set("another_key", 3)
  361. self.mc.delete("another_key")
  362. def loop(self):
  363. thread.start_new_thread(self._loop,())
  364. if not self.ok():
  365. return
  366. def _loop(self):
  367. cprint("++++++++++ start.memcachd read loop",self )
  368. while 1:
  369. send = 0
  370. #print("+")
  371. try:
  372. ip="10.10.10.13:0"
  373. #ip="ltp-out:0"
  374. #print(ip)
  375. x=self.mc.get(ip)
  376. if x:
  377. #print(ip,x)
  378. #val = x[501-1]
  379. #val = x[141-1]
  380. for i, line in enumerate(self.fader_map):
  381. try:
  382. #print(i,line)
  383. dmx = int(line["DMX"])
  384. if dmx > 0:
  385. val = x[dmx-1]
  386. #print("mc val",val)
  387. #print("dmx_in change:",[i,val])
  388. change = 0
  389. if i < len(self.last_fader_val):
  390. if self.last_fader_val[i] != val:
  391. self.last_fader_val[i] = val
  392. print("dmx_in change:",[i,val])
  393. change = 1
  394. set_exec_fader(nr=i,val=val,color="#aaa",info="dmx_in",change=change)
  395. except Exception as e:
  396. cprint("MC exc:",e,color="red")
  397. traceback.print_exc()
  398. pass
  399. time.sleep(1/10)
  400. except Exception as e:
  401. cprint("exc", e)
  402. time.sleep(1)
  403. _mc=MC()
  404. _mc.loop()
  405. console = chat.Client() #port=50001)
  406. def jclient_send(data):
  407. t_start = time.time()
  408. jtxt = data
  409. jdatas = []
  410. for jdata in data:
  411. if "CMD" in jdata:
  412. try:
  413. jdatas.append(jdata)
  414. except Exception as e:
  415. cprint("jclient_send, Exception DMX ",color="red")
  416. cprint("",jdata,color="red")
  417. cprint("-----",color="red")
  418. elif "DMX" in jdata:
  419. try:
  420. jdata["DMX"] = int(jdata["DMX"])
  421. dmx = jdata["DMX"]
  422. if "ATTR" not in jdata:
  423. # for fx off
  424. jdatas.append(jdata)
  425. else:
  426. fix = "00000"
  427. attr = "00000"
  428. if "FIX" in jdata:
  429. fix = jdata["FIX"]
  430. if "ATTR" in jdata:
  431. attr = jdata["ATTR"]
  432. dmx_fine = FIXTURES.get_dmx(fix,attr+"-FINE")
  433. if jdata["DMX"] != dmx_fine and dmx > 0 and dmx_fine > 0:
  434. jdata["DMX-FINE"] = dmx_fine
  435. if "DMX-FINE" in jdata:
  436. if jdata["DMX-FINE"] <= 0:
  437. del jdata["DMX-FINE"]
  438. if jdata["ATTR"].startswith("_"):
  439. pass # ignore attr._ACTIVE
  440. else:#
  441. jdata["time"] = t_start
  442. jdatas.append(jdata)
  443. #cprint("-- ",jdata,color="red")
  444. except Exception as e:
  445. cprint("jclient_send, Exception DMX ",color="red")
  446. cprint("",jdata,color="red")
  447. cprint(e,color="red")
  448. cprint("-----",color="red")
  449. jtxt = jdatas
  450. jtxt = json.dumps(jtxt)
  451. jtxt = jtxt.encode()
  452. console.send( jtxt ) #b"\00 ")
  453. cprint("{:0.04} sec.".format(time.time()-t_start),color="yellow")
  454. cprint("{:0.04} tick".format(time.time()),color="yellow")
  455. def _highlight(fix,_attr="DIM"):
  456. " patch test button "
  457. cprint("highlight",fix,"1")
  458. if fix not in FIXTURES.fixtures:
  459. return None
  460. d = FIXTURES.fixtures[fix]
  461. #for k,v in d.items():
  462. # cprint("-",k,v)
  463. DMX = d["DMX"] + d["UNIVERS"]*512
  464. if "ATTRIBUT" in d:
  465. ATTR= d["ATTRIBUT"]
  466. data = {"VALUE":200,"DMX":1}
  467. attr = ""
  468. if _attr in ATTR:
  469. attr = _attr
  470. else:
  471. return #stop
  472. cprint(attr,ATTR[attr])
  473. old_val = ATTR[attr]["VALUE"]
  474. data["DMX"] = DMX + ATTR[attr]["NR"]-1
  475. cprint(attr,ATTR[attr])
  476. cprint(data)
  477. for i in range(3):
  478. cprint("highlight",fix,"0")
  479. data["VALUE"] = 100
  480. jclient_send([data])
  481. time.sleep(0.1)
  482. cprint("highlight",fix,"1")
  483. data["VALUE"] = 234
  484. jclient_send([data])
  485. time.sleep(0.3)
  486. cprint("highlight",fix,"0")
  487. data["VALUE"] = old_val
  488. jclient_send([data])
  489. def highlight2(fix,attr="DIM"):
  490. def x():
  491. highlight(fix,attr=attr)
  492. return x
  493. def highlight(fix):
  494. cprint("highlight",fix)
  495. thread.start_new_thread(_highlight,(fix,"DIM"))
  496. thread.start_new_thread(_highlight,(fix,"RED"))
  497. thread.start_new_thread(_highlight,(fix,"GREEN"))
  498. thread.start_new_thread(_highlight,(fix,"BLUE"))
  499. class ValueBuffer():
  500. def __init__(self,_min=0,_max=255):
  501. self._value = 2
  502. self._on = 1
  503. self._min=_min
  504. self._max=_max
  505. def check(self):
  506. if self._value < self._min:
  507. self._value = self._min
  508. elif self._value > self._max:
  509. self._value = self._max
  510. def inc(self,value=None):
  511. if value is not None:
  512. if type(value) is float:
  513. self._value += round(value,4)
  514. else:
  515. self._value += value
  516. self.check()
  517. return self._value
  518. def val(self,value=None):
  519. if value is not None:
  520. if type(value) is float:
  521. self._value = round(value,4)
  522. else:
  523. self._value = value
  524. self.check()
  525. return self._value
  526. def on(self):
  527. self._on = 1
  528. def off(self):
  529. self._on = 0
  530. def _is(self):
  531. if self._on:
  532. return 1
  533. return 0
  534. FADE = ValueBuffer() #2 #0.1 #1.13
  535. FADE.val(2.0)
  536. FADE_move = ValueBuffer() #2 #0.1 #1.13
  537. FADE_move.val(4.0)
  538. DELAY = ValueBuffer() #2 #0.1 #1.13
  539. DELAY.off()
  540. DELAY.val(0.2)
  541. fx_prm_main = {}
  542. 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}
  543. fx_color = {"A":"red","B":"blue"}
  544. 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}
  545. fx_x_modes = ["spiral","left","right","up","down","left_right","up_down"]
  546. fx_modes = ["RED","GREEN","BLUE","MAG","YELLOW","CYAN"]
  547. fx_mo = ["fade","on","rnd","ramp","ramp2","cosinus","sinus","static"]
  548. class FX_handler():
  549. def __init__():
  550. pass
  551. class dummy_event():
  552. def __init__(self):
  553. self.num =0
  554. self.type = 4 #press 5 release
  555. self.set_value=-1
  556. from lib import matrix
  557. import lib.fxlib as fxlib
  558. def process_matrix(xfixtures):
  559. fx_x = fx_prm["2D-X"]
  560. fx_mod = fx_x_modes[fx_prm["2D:MODE"]]
  561. r = _process_matrix(xfixtures,fx_x,fx_mod)
  562. return r
  563. def _process_matrix(xfixtures,fx_x,fx_mod):
  564. fix_count = len(xfixtures)
  565. cprint("----",fx_x,fx_mod)
  566. if fx_x > 1 and fix_count > fx_x:
  567. try:
  568. w=fx_x
  569. h=int(fix_count/fx_x)
  570. if fx_mod == "spiral":
  571. _map = matrix.spiral(w,h)
  572. elif fx_mod == "up_down":
  573. _map = matrix.up_down(w,h)
  574. elif fx_mod == "left_right":
  575. _map = matrix.left_right(w,h)
  576. elif fx_mod == "left":
  577. _map = matrix.left(w,h)
  578. elif fx_mod == "right":
  579. _map = matrix.right(w,h)
  580. elif fx_mod == "up":
  581. _map = matrix.up(w,h)
  582. elif fx_mod == "down":
  583. _map = matrix.down(w,h)
  584. else:
  585. return xfixtures # do nothing
  586. matrix.mprint(xfixtures,w,h)
  587. out = ["0"]*(w*h)
  588. for i,f in enumerate(xfixtures):
  589. if i < w*h:
  590. j = int(_map[i])
  591. cprint(["i:",i,"f:",f,"j:",j])
  592. out[j] = f
  593. matrix.mprint(out,w,h)
  594. xfixtures = out
  595. except Exception as e:
  596. cprint("matrix exception",e)
  597. return xfixtures
  598. class Xevent_fx():
  599. """ global input event Handeler for short cut's ... etc
  600. """
  601. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  602. self.fix = fix
  603. self.data = data
  604. self.attr = attr
  605. self.elem = elem
  606. self.mode = mode
  607. def fx(self,event):
  608. cprint("Xevent.fx",self.attr,self.fix,event)
  609. fx2 = {}
  610. if self.attr == "FX:RED":
  611. if event.num == 4:
  612. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  613. txt = "FX:RED"
  614. fx_prm["MODE"] += 1
  615. if fx_prm["MODE"] >= len(fx_modes):
  616. fx_prm["MODE"]=0
  617. txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
  618. master.fx_color.elem["FX:RED"]["text"] = txt
  619. elif event.num == 5:
  620. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  621. txt = "FX:RED"
  622. fx_prm["MODE"] -= 1
  623. if fx_prm["MODE"] < 0:
  624. fx_prm["MODE"]= len(fx_modes)-1
  625. txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
  626. master.fx_color.elem["FX:RED"]["text"] = txt
  627. if self.attr.startswith("2D"):
  628. if event.num == 4:
  629. cprint("2D-X: CHANGE",fx_prm,color="red")
  630. txt = "2D-X:"
  631. fx_prm["2D:MODE"] += 1
  632. if fx_prm["2D:MODE"] >= len(fx_x_modes):
  633. fx_prm["2D:MODE"]=0
  634. txt = "2D:MODE\n"+fx_x_modes[fx_prm["2D:MODE"]]
  635. master.fx.elem["2D:MODE"]["text"] = txt
  636. elif event.num == 5:
  637. cprint("2D-X: CHANGE",fx_prm,color="red")
  638. txt = "2D-X:"
  639. fx_prm["2D:MODE"] -= 1
  640. if fx_prm["2D:MODE"] < 0:
  641. fx_prm["2D:MODE"]= len(fx_x_modes)-1
  642. txt = "2D:MODE\n"+fx_x_modes[fx_prm["2D:MODE"]]
  643. master.fx.elem["2D:MODE"]["text"] = txt
  644. elif event.num == 1:
  645. xfixtures = []
  646. fix_active =FIXTURES.get_active()
  647. for fix in fix_active:
  648. if fix == "CFG":
  649. continue
  650. xfixtures.append(fix)
  651. if not xfixtures:
  652. cprint("470 fx() ... init no fixture selected",color="red")
  653. return 0
  654. xfixtures = process_matrix(xfixtures)
  655. wing_buffer = fxlib.process_wings(xfixtures,fx_prm)
  656. fxlib.process_effect(wing_buffer,fx_prm,fx_prm_move,modes,jclient_send,master,FIXTURES,fx_name=self.attr)
  657. def command(self,event,mode=""):
  658. cprint("fx_command",self.mode)
  659. if self.mode == "FX":
  660. prm = fx_prm
  661. ct = self.data.fx
  662. if self.mode == "FX-MOVE":
  663. prm = fx_prm_move
  664. ct = self.data.fx_moves
  665. if 1:
  666. if self.attr.startswith("SIZE:"):#SIN":
  667. #global fx_prm
  668. k = "SIZE"
  669. if event.num == 1:
  670. _stats = [0,30,100,255]
  671. if prm[k] in _stats:
  672. idx = _stats.index(prm[k])+1
  673. if idx > len(_stats)-1: #rotate
  674. idx = 0
  675. prm[k] = _stats[idx]
  676. else:
  677. prm[k] = _stats[1]
  678. elif event.num == 3:
  679. prm[k] =100
  680. elif event.num == 4:
  681. if prm[k] <= 0:
  682. prm[k] = 1
  683. prm[k] +=5
  684. elif event.num == 5:
  685. prm[k] -=5
  686. #prm[k] =int(prm[k])
  687. if prm[k] > 4000:
  688. prm[k] = 4000
  689. if prm[k] < 0:
  690. prm[k] =0
  691. if prm[k] == 6: #bug
  692. prm[k] =5
  693. ct.elem[self.attr]["text"] = "SIZE:\n{:0.0f}".format(prm[k])
  694. cprint(prm)
  695. elif self.attr.startswith("SPEED:"):#SIN":
  696. #global prm
  697. k = "SPEED"
  698. if event.num == 1:
  699. _stats = [0,5,25,30,100,255]
  700. if prm[k] in _stats:
  701. idx = _stats.index(prm[k])+1
  702. if idx > len(_stats)-1: #rotate
  703. idx = 0
  704. prm[k] = _stats[idx]
  705. else:
  706. prm[k] = 0
  707. elif event.num == 3:
  708. prm[k] = 10
  709. elif event.num == 4:
  710. if prm[k] <= 0:
  711. prm[k] = 0.06
  712. elif prm[k] < 5:
  713. prm[k] *=1.2
  714. else:
  715. prm[k] +=5 #1.1
  716. elif event.num == 5:
  717. if prm[k] <= 5:
  718. prm[k] *=0.8
  719. else:
  720. prm[k] -= 5 #1.1
  721. #prm[k] =int(prm[k])
  722. if prm[k] > 4000:
  723. prm[k] = 4000
  724. if prm[k] < 0.05:
  725. prm[k] =0
  726. if prm[k] > 5 and prm[k] < 10: #bug
  727. prm[k] =5
  728. if prm[k] < 0:
  729. ct.elem[self.attr]["text"] = "SPEED:\noff".format(prm[k])
  730. else:
  731. ct.elem[self.attr]["text"] = "SPEED:\n{:0.02f}".format(prm[k])
  732. cprint(prm)
  733. elif self.attr.startswith("START:"):#SIN":
  734. #global prm
  735. k = "START"
  736. if event.num == 1:
  737. pass
  738. elif event.num == 2:
  739. pass
  740. elif event.num == 4:
  741. if prm[k] <= 0:
  742. prm[k] = 1
  743. prm[k] += 5 #1.1
  744. elif event.num == 5:
  745. prm[k] -= 5 #1.1
  746. #prm[k] =int(prm[k])
  747. if prm[k] > 4000:
  748. prm[k] = 4000
  749. if prm[k] < 5:
  750. prm[k] =0
  751. if prm[k] == 6: #bug
  752. prm[k] =5
  753. ct.elem[self.attr]["text"] = "START:\n{:0.0f}".format(prm[k])
  754. cprint(prm)
  755. elif self.attr.startswith("WIDTH:"):#SIN":
  756. #global prm
  757. k = "WIDTH"
  758. if event.num == 1:
  759. _stats = [0,25,50,75,10]
  760. if prm[k] in _stats:
  761. idx = _stats.index(prm[k])+1
  762. if idx > len(_stats)-1: #rotate
  763. idx = 0
  764. prm[k] = _stats[idx]
  765. else:
  766. prm[k] = 25
  767. elif event.num == 2:
  768. prm[k] = 50
  769. elif event.num == 3:
  770. prm[k] = 100
  771. elif event.num == 4:
  772. if prm[k] <= 0:
  773. prm[k] = 1
  774. elif prm[k] == 50:
  775. prm[k] = 100
  776. elif prm[k] == 5:
  777. prm[k] = 25
  778. elif prm[k] == 25:
  779. prm[k] = 50
  780. else:
  781. prm[k] += 5 #*=1.1
  782. elif event.num == 5:
  783. if prm[k] == 10:
  784. prm[k] = 5
  785. elif prm[k] == 25:
  786. prm[k] = 10
  787. elif prm[k] == 50:
  788. prm[k] = 25
  789. elif prm[k] == 100:
  790. prm[k] = 50
  791. #else:
  792. # prm[k] -=5 #/=1.1
  793. #prm[k] =int(prm[k])
  794. if prm[k] < 0:
  795. prm[k] = 0
  796. if prm[k] > 100:
  797. prm[k] = 100
  798. if prm[k] == 6: #bug
  799. prm[k] =5
  800. if prm[k] > 25 and prm[k] < 50: #bug
  801. prm[k] =50
  802. if prm[k] > 50 and prm[k] < 75: #bug
  803. prm[k] =75
  804. if prm[k] > 75 and prm[k] < 100: #bug
  805. prm[k] =100
  806. ct.elem[self.attr]["text"] = "WIDTH:\n{:0.0f}".format(prm[k])
  807. cprint(prm)
  808. elif self.attr.startswith("DIR:"):#SIN":
  809. #global prm
  810. k = "DIR"
  811. if event.num == 1:
  812. prm[k] = 1
  813. elif event.num == 3:
  814. prm[k] = -1
  815. elif event.num == 4:
  816. prm[k] = 1
  817. elif event.num == 5:
  818. prm[k] =-1
  819. txt = prm[k]
  820. ct.elem[self.attr]["text"] = "DIR:\n{}".format(prm[k])
  821. cprint(prm)
  822. elif self.attr.startswith("SHUFFLE:"):#SIN":
  823. #global prm
  824. k = "SHUFFLE"
  825. if event.num == 1:
  826. prm[k] = 0
  827. elif event.num == 3:
  828. prm[k] = 1
  829. elif event.num == 4:
  830. prm[k] = 1
  831. elif event.num == 5:
  832. prm[k] =0
  833. if prm[k] == 6: #bug ?
  834. prm[k] =5
  835. ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
  836. cprint(prm)
  837. elif self.attr.startswith("INVERT:"):#SIN":
  838. #global prm
  839. k = "INVERT"
  840. if event.num == 1:
  841. prm[k] = 0
  842. elif event.num == 3:
  843. prm[k] = 1
  844. elif event.num == 4:
  845. prm[k] = 1
  846. elif event.num == 5:
  847. prm[k] =0
  848. if prm[k] == 6: #bug ?
  849. prm[k] =5
  850. ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
  851. cprint(prm)
  852. elif self.attr.startswith("2D-X:"):#SIN":
  853. #global prm
  854. k = "2D-X"
  855. if event.num == 1:
  856. prm[k] = 1
  857. elif event.num == 3:
  858. prm[k] = 2
  859. elif event.num == 4:
  860. prm[k] += 1
  861. elif event.num == 5:
  862. prm[k] -=1
  863. if prm[k] > 100:
  864. prm[k] = 100
  865. if prm[k] < 1:
  866. prm[k] =1
  867. txt = prm[k]
  868. ct.elem[self.attr]["text"] = "2D-X:\n{}".format(prm[k])
  869. cprint(prm)
  870. elif self.attr.startswith("WING:"):#SIN":
  871. #global prm
  872. k = "WING"
  873. if event.num == 1:
  874. prm[k] = 1
  875. elif event.num == 3:
  876. prm[k] = 2
  877. elif event.num == 4:
  878. prm[k] += 1
  879. elif event.num == 5:
  880. prm[k] -=1
  881. if prm[k] > 100:
  882. prm[k] = 100
  883. if prm[k] < 1:
  884. prm[k] =1
  885. txt = prm[k]
  886. ct.elem[self.attr]["text"] = "WING:\n{}".format(prm[k])
  887. cprint(prm)
  888. elif self.attr.startswith("OFFSET:"):#SIN":
  889. #global prm
  890. k = "OFFSET"
  891. if event.num == 1:
  892. prm[k] = 50
  893. elif event.num == 2:
  894. prm[k] *= 2
  895. elif event.num == 3:
  896. prm[k] = 100
  897. elif event.num == 4:
  898. if prm[k] <= 0:
  899. prm[k] = 1
  900. prm[k] +=5 #*=1.1
  901. elif event.num == 5:
  902. prm[k] -=5 #/=1.1
  903. #prm[k] =int(prm[k])
  904. #if prm[k] > 512:
  905. # prm[k] = 512
  906. if prm[k] < 5:
  907. prm[k] =0
  908. if prm[k] == 6: #bug
  909. prm[k] =5
  910. ct.elem[self.attr]["text"] = "OFFSET:\n{:0.0f}".format(prm[k])
  911. cprint(prm)
  912. elif self.attr.startswith("BASE:"):
  913. k = "BASE"
  914. if event.num == 1:
  915. prm[k] = "-"
  916. elif event.num == 3:
  917. prm[k] = "0"
  918. elif event.num == 4:
  919. prm[k] = "+"
  920. elif event.num == 5:
  921. prm[k] = "0"
  922. ct.elem[self.attr]["text"] = "BASE:\n{}".format(prm[k])
  923. elif self.attr.startswith("2D:"):#SIN":
  924. self.fx(event)
  925. elif self.attr.startswith("FX:"):#SIN":
  926. self.fx(event)
  927. elif self.attr == "FX OFF":
  928. if event.num == 1:
  929. FIXTURES.fx_off("all")
  930. CONSOLE.fx_off("all")
  931. CONSOLE.flash_off("all")
  932. master._refresh_fix()
  933. return 0
  934. #if event.num == 1:
  935. elif self.attr == "REC-FX":
  936. cprint("ELSE",self.attr)
  937. modes.val(self.attr,1)
  938. return 0
  939. def cb(self,event):
  940. cprint("EVENT_fx cb",self.attr,self.mode,event,color='yellow')
  941. cprint(["type",event.type,"num",event.num])
  942. try:
  943. change = 0
  944. if self.mode.startswith("FX"):
  945. self.command(event)
  946. return 0
  947. except Exception as e:
  948. cprint("== cb EXCEPT",e,color="red")
  949. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  950. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  951. return 1
  952. class BLINKI():
  953. def __init__(self,e):
  954. self.e = e
  955. def blink(self):
  956. e = self.e
  957. e.config(bg='green')
  958. duration = 150
  959. for i in range(8):
  960. d = i * duration
  961. if i % 2 == 0:
  962. e.after(d, lambda: e.config(bg='white')) # after 1000ms
  963. e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
  964. else:
  965. e.after(d, lambda: e.config(bg='orange')) # after 1000ms
  966. e.after(d, lambda: e.config(activebackground='orange')) # after 1000ms
  967. i+=1
  968. duration = 150
  969. e.after(d, lambda: e.config(bg='white')) # after 1000ms
  970. e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
  971. class Xevent():
  972. """ global input event Handeler for short cut's ... etc
  973. """
  974. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  975. self.fix = fix
  976. self.data=data
  977. self.attr = attr
  978. self.elem = elem
  979. self.mode = mode
  980. def _save_show(self):
  981. self.elem["bg"] = "orange"
  982. self.elem["text"] = "SAVING..."
  983. self.elem["bg"] = "red"
  984. self.elem.config(activebackground="orange")
  985. modes.val(self.attr,1)
  986. PRESETS.backup_presets()
  987. FIXTURES.backup_patch()
  988. libwin.save_window_position()
  989. movewin.store_all_sdl()
  990. self.elem["bg"] = "lightgrey"
  991. self.elem.config(activebackground="lightgrey")
  992. b = BLINKI(self.elem)
  993. b.blink()
  994. self.elem["text"] = "SAVE\nSHOW"
  995. def setup(self,event):
  996. cprint("xevent.SETUP",[self.mode,self.attr],color="red")
  997. if self.mode == "SETUP":
  998. if self.attr == "SAVE\nSHOW":
  999. self._save_show()
  1000. elif self.attr == "LOAD\nSHOW":
  1001. name = "LOAD-SHOW"
  1002. base = baselib.Base()
  1003. line1 = "PATH: "+base.show_path1 +base.show_name
  1004. line2 = "DATE: "+ time.strftime("%Y-%m-%d %X", time.localtime(time.time()))
  1005. class cb():
  1006. def __init__(self,name=""):
  1007. self.name=name
  1008. cprint(" LOAD-SHOW.init",name)
  1009. def cb(self,event=None,**args):
  1010. cprint(" LOAD-SHOW.cdb",self.name,event,args)
  1011. if self.name != "<exit>":
  1012. cprint("-----------------------:")
  1013. LOAD_SHOW_AND_RESTART(self.name).cb()
  1014. pw = libtk.PopupList(name,cb=cb)
  1015. print(line1,line2)
  1016. frame = pw.sframe(line1=line1,line2=line2)
  1017. r = frame_of_show_list(frame,cb=cb)
  1018. elif self.attr == "NEW\nSHOW":
  1019. base = baselib.Base()
  1020. #def _cb(fname):
  1021. def _cb(data):
  1022. if not data:
  1023. cprint("err443",self,"_cb",data)
  1024. return None
  1025. fname = data["Value"]
  1026. cprint(self,"save_show._cb()",fname)
  1027. fpath,fname = base.build_path(fname)
  1028. cprint("SAVE NEW SHOW",fpath,fname)
  1029. if base._create_path(fpath):
  1030. a=PRESETS.backup_presets(save_as=fpath,new=1)
  1031. b=FIXTURES.backup_patch(save_as=fpath,new=1)
  1032. #base._set(fname)
  1033. libwin.save_window_position(save_as=fpath)
  1034. LOAD_SHOW_AND_RESTART(fname).cb()
  1035. dialog._cb = _cb
  1036. dialog.askstring("CREATE NEW SHOW","CREATE NEW SHOW:")
  1037. elif self.attr == "SAVE\nSHOW AS":
  1038. base = baselib.Base()
  1039. #def _cb(fname):
  1040. def _cb(data):
  1041. if not data:
  1042. cprint("err443",self,"_cb",data)
  1043. return None
  1044. fname = data["Value"]
  1045. cprint(self,"save_show._cb()",fname)
  1046. fpath,fname = base.build_path(fname)
  1047. cprint("SAVE AS",fpath,fname)
  1048. if base._create_path(fpath):
  1049. a=PRESETS.backup_presets(save_as=fpath)
  1050. b=FIXTURES.backup_patch(save_as=fpath)
  1051. #base._set(fname)
  1052. libwin.save_window_position(save_as=fpath)
  1053. LOAD_SHOW_AND_RESTART(fname).cb()
  1054. dialog._cb = _cb
  1055. dialog.askstring("SAVE SHOW AS","SAVE SHOW AS:")
  1056. elif self.attr == "SAVE &\nRESTART":
  1057. self.elem["bg"] = "orange"
  1058. self.elem["text"] = "SAVING..."
  1059. self.elem["bg"] = "red"
  1060. self.elem.config(activebackground="orange")
  1061. modes.val(self.attr,1)
  1062. PRESETS.backup_presets()
  1063. FIXTURES.backup_patch()
  1064. movewin.store_all_sdl()
  1065. libwin.save_window_position()
  1066. self.elem["text"] = "RESTARTING..."
  1067. self.elem["bg"] = "lightgrey"
  1068. self.elem.config(activebackground="lightgrey")
  1069. LOAD_SHOW_AND_RESTART("").cb(force=1)
  1070. elif self.attr == "DRAW\nGUI":
  1071. old_text = self.elem["text"]
  1072. window_manager.top("PATCH")
  1073. gui_patch.draw(FIXTURES)
  1074. gui_fix.draw(FIXTURES)
  1075. window_manager.top("FIXTURES")
  1076. master._refresh_exec()
  1077. self.elem["text"] = old_text
  1078. elif self.attr == "PRO\nMODE":
  1079. self._save_show()
  1080. import lib.restart as restart
  1081. restart.pro()
  1082. elif self.attr == "EASY\nMODE":
  1083. self._save_show()
  1084. import lib.restart as restart
  1085. restart.easy()
  1086. else:
  1087. if IS_GUI:
  1088. r=tkinter.messagebox.showwarning(message="{}\nnot implemented".format(self.attr.replace("\n"," ")),parent=None)
  1089. return 1
  1090. def live(self,event):
  1091. if self.mode == "LIVE":
  1092. if "FADE" in self.attr or "DELAY" in self.attr:
  1093. if self.attr == "FADE":
  1094. ct = FADE
  1095. if self.attr == "DELAY":
  1096. ct = DELAY
  1097. if "PAN/TILT\nFADE" in self.attr:
  1098. ct = FADE_move
  1099. value = ct.val()
  1100. #print("EVENT CHANGE ",[self.attr])
  1101. cprint("EVENT CHANGE:",self.mode,value,self.attr)
  1102. if value < 0.01:
  1103. ct.val(0.01)
  1104. elif value > 100.0:
  1105. pass #value = 100
  1106. if event.num == 4:
  1107. value *= 1.1
  1108. elif event.num == 5:
  1109. value /= 1.1
  1110. elif event.num == 1:
  1111. if ct._is():
  1112. ct.off()# = 0
  1113. self.data.commands.elem[self.attr]["bg"] = "grey"
  1114. self.elem.config(activebackground="grey")
  1115. else:
  1116. ct.on()# = 1
  1117. self.data.commands.elem[self.attr]["bg"] = "green"
  1118. self.elem.config(activebackground="lightgreen")
  1119. elif event.num == 2:
  1120. if value > 1 and value < 4:
  1121. value = 4
  1122. elif value > 3 and value < 6:
  1123. value = 6
  1124. elif value > 5 and value < 7:
  1125. value = 8
  1126. elif value > 7 and value < 9:
  1127. value = 10
  1128. elif value > 9:
  1129. value = 0.01
  1130. elif value < 1:
  1131. value = 1.1
  1132. value = round(value,3)
  1133. value = ct.val(value)
  1134. if self.attr == "FADE":
  1135. self.data.commands.elem[self.attr]["text"] = "FADE:\n{:0.2f}".format(value)
  1136. if self.attr == "DELAY":
  1137. self.data.commands.elem[self.attr]["text"] = "DELAY:\n{:0.3f}".format(value)
  1138. if "PAN/TILT\nFADE" in self.attr:
  1139. self.data.commands.elem[self.attr]["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
  1140. def command(self,event):
  1141. if self.mode == "COMMAND":
  1142. if self.attr == "CLEAR":
  1143. if event.num == 1:
  1144. ok = FIXTURES.clear()
  1145. if ok:
  1146. master._refresh_fix()
  1147. modes.val(self.attr,0)
  1148. elif self.attr == "SAVE":
  1149. modes.val(self.attr,1)
  1150. PRESETS.backup_presets()
  1151. FIXTURES.backup_patch()
  1152. #time.sleep(1)
  1153. modes.val(self.attr,0)
  1154. elif self.attr == "S-KEY":
  1155. global _global_short_key
  1156. if _global_short_key:
  1157. _global_short_key = 0
  1158. master.commands.elem["S-KEY"]["bg"] = "red"
  1159. master.commands.elem["S-KEY"]["activebackground"] = "red"
  1160. else:
  1161. _global_short_key = 1
  1162. master.commands.elem["S-KEY"]["bg"] = "green"
  1163. master.commands.elem["S-KEY"]["activebackground"] = "green"
  1164. cprint("s-key",_global_short_key)
  1165. else:
  1166. if event.num == 1:
  1167. cprint("ELSE",self.attr)
  1168. modes.val(self.attr,1)
  1169. return 0
  1170. def encoder(self,event):
  1171. global _shift_key
  1172. cprint("Xevent","ENC",self.fix,self.attr,self.mode)
  1173. cprint("SHIFT_KEY",_shift_key,"??????????")
  1174. if self.mode == "ENCODER":
  1175. if self._encoder(event):
  1176. master.refresh_fix() # delayed
  1177. refresher_fix.reset() # = Refresher()
  1178. if self.mode == "ENCODER2":
  1179. if self._encoder(event):
  1180. master.refresh_fix() # delayed
  1181. refresher_fix.reset() # = Refresher()
  1182. if self.mode == "INVERT":
  1183. cprint("INVERT",event)
  1184. if self._encoder(event):
  1185. master.refresh_fix() # delayed
  1186. refresher_fix.reset() # = Refresher()
  1187. def _encoder(self,event):
  1188. global _shift_key
  1189. if 1: #self.mode == "ENCODER" or self.mode == "ENCODER2":
  1190. cprint("-- Xevent","_ENC",self.fix,self.attr,self.mode)
  1191. cprint("-- SHIFT_KEY",_shift_key,"??????????")
  1192. #cprint(self.data)
  1193. val=""
  1194. if event.num == 1:
  1195. val ="click"
  1196. elif event.num == 4:
  1197. val ="++"
  1198. if _shift_key:
  1199. val = "+"
  1200. elif event.num == 5:
  1201. val ="--"
  1202. if _shift_key:
  1203. val = "-"
  1204. #print("SHIFT",val,_shift_key)
  1205. if val:
  1206. FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
  1207. return 1
  1208. def cb(self,event):
  1209. cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
  1210. cprint(["type",event.type,"num",event.num])
  1211. global INIT_OK
  1212. INIT_OK = 1
  1213. try:
  1214. change = 0
  1215. if "keysym" in dir(event):
  1216. if "Escape" == event.keysym:
  1217. ok = FIXTURES.clear()
  1218. master._refresh_fix()
  1219. cprint()
  1220. return 0
  1221. if self.mode == "SETUP":
  1222. self.setup(event)
  1223. elif self.mode == "COMMAND":
  1224. self.command(event)
  1225. elif self.mode == "LIVE":
  1226. self.live(event)
  1227. elif self.mode == "ENCODER":
  1228. self.encoder(event)
  1229. master.refresh_fix()
  1230. elif self.mode == "ENCODER2":
  1231. self.encoder(event)
  1232. elif self.mode == "INVERT":
  1233. self.encoder(event)
  1234. elif self.mode == "FX":
  1235. cprint("Xevent CALLING FX WRONG EVENT OBJECT !!",color="red")
  1236. elif self.mode == "ROOT":
  1237. if event.keysym=="Escape":
  1238. pass
  1239. elif self.mode == "INPUT":
  1240. cprint("INP",self.data.entry.get())
  1241. if event.keycode == 36:
  1242. x=self.data.entry.get()
  1243. #client.send(x)
  1244. elif self.mode == "INPUT2":
  1245. cprint("INP2",self.data.entry2.get())
  1246. if event.keycode == 36:
  1247. x=self.data.entry2.get()
  1248. #client.send(x)
  1249. elif self.mode == "INPUT3":
  1250. cprint("INP3",self.data.entry3.get())
  1251. if event.keycode == 36:
  1252. x=self.data.entry3.get()
  1253. #client.send(x)
  1254. elif self.mode == "PRESET":
  1255. nr = self.attr #int(self.attr.split(":")[1])-1
  1256. if event.num == 3: # right click for testing
  1257. if str(event.type) == '4': #4 ButtonPress
  1258. if modes.val("CFG-BTN"):
  1259. master.btn_cfg(nr,testing=1)
  1260. if event.num == 1:
  1261. if str(event.type) == '4': #4 ButtonPress
  1262. if modes.val("REC"):
  1263. self.data.preset_rec(nr)
  1264. modes.val("REC",0)
  1265. time.sleep(0.05)
  1266. master._refresh_exec(nr=nr)
  1267. elif modes.val("DEL"):
  1268. ok=PRESETS.delete(nr)
  1269. if ok:
  1270. modes.val("DEL",0)
  1271. #master.refresh_exec()
  1272. master._refresh_exec(nr=nr)
  1273. elif modes.val("COPY"):
  1274. ok=PRESETS.copy(nr)
  1275. if ok:
  1276. modes.val("COPY",0)
  1277. master._refresh_exec(nr=nr)
  1278. elif modes.val("MOVE"):
  1279. ok,cnr,bnr=PRESETS.move(nr)
  1280. if ok:
  1281. #modes.val("MOVE",0) # keep MOVE on
  1282. master._refresh_exec(nr=nr)
  1283. master._refresh_exec(nr=bnr)
  1284. elif modes.val("CFG-BTN"):
  1285. master.btn_cfg(nr)
  1286. #master._refresh_exec(nr=nr)
  1287. elif modes.val("LABEL"):#else:
  1288. master.label(nr)
  1289. #master._refresh_exec(nr=nr)
  1290. elif modes.val("EDIT"):
  1291. FIXTURES.clear()
  1292. self.data.preset_select(nr)
  1293. self.data.preset_go(nr,xfade=0,event=event,val=255,button="go")
  1294. modes.val("EDIT", 0)
  1295. master.refresh_fix()
  1296. refresher_fix.reset() # = Refresher()
  1297. elif modes.val("SELECT"):
  1298. self.data.preset_select(nr)
  1299. else:
  1300. self.data.preset_go(nr,event=event,val=255)
  1301. else:
  1302. self.data.preset_go(nr,xfade=0,event=event,val=0)
  1303. cprint(" == "*10)
  1304. master.refresh_fix()
  1305. refresher_fix.reset() # = Refresher()
  1306. if event.num == 3:
  1307. if not modes.val("REC"):
  1308. if str(event.type) == '4': #4 ButtonPress
  1309. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=255)
  1310. else:
  1311. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=0)
  1312. cprint()
  1313. return 0
  1314. elif self.mode == "INPUT":
  1315. cprint()
  1316. return 0
  1317. except Exception as e:
  1318. cprint("== cb EXCEPT",e,color="red")
  1319. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1320. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1321. cprint()
  1322. return 1
  1323. def wheel(event,d=None):
  1324. cprint("wheel",event,d)
  1325. class Element():
  1326. def __init__(self):
  1327. self.__data = {}
  1328. def set(self,key,val):
  1329. self.__data[key] = val
  1330. #import lib.base as _base
  1331. import lib.baselib as baselib
  1332. def hex_to_rgb(hex):
  1333. return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
  1334. class cb():
  1335. def __init__(self,win):
  1336. self.win = win
  1337. def _callback(self,event):
  1338. clobj=event.widget
  1339. ## undermouse=find_withtag(master.CURRENT)
  1340. undermouse=self.win.find_closest(self.win.CURRENT)
  1341. cprint( repr(undermouse))
  1342. def callback(self,event):
  1343. cprint(__file__,self,"callback",event)
  1344. cnv = self.win
  1345. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  1346. tags = cnv.gettags(item)
  1347. #cnv.itemconfigure(self.tag, text=tags[0])
  1348. cprint(tags,item)
  1349. color = cnv.itemcget(item, "fill")
  1350. cnv.itemconfig("all", width=1)#filla="green")
  1351. cnv.itemconfig(item, width=3)#filla="green")
  1352. cprint(color)
  1353. cprint( hex_to_rgb(color[1:]))
  1354. def get_exec_btn_cfg(nr):
  1355. #b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
  1356. #for k in PRESETS.val_presets:
  1357. k = nr
  1358. if 1:
  1359. _bg = "grey"
  1360. _ba = "grey"
  1361. _fg = "lightgrey"
  1362. _text = "N/V"
  1363. if nr >= 0:
  1364. #if self._nr_ok:
  1365. # return #pass#abreak
  1366. if nr != k:
  1367. return #continue
  1368. #else:
  1369. # self._nr_ok = 1
  1370. label = ""
  1371. #if k not in self.elem_presets:
  1372. # cprint("ERROR",k ,"not in elem_presets continue")
  1373. # return #continue
  1374. if k in PRESETS.label_presets:
  1375. label = PRESETS.label_presets[k]
  1376. #print([label])
  1377. #b = self.elem_presets[k]
  1378. ifval = 0
  1379. fx_only = 0
  1380. fx_color = 0
  1381. if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
  1382. sdata = PRESETS.val_presets[k]
  1383. #print("sdata7654",sdata)
  1384. BTN="go"
  1385. if "CFG" in sdata:#["BUTTON"] = "GO"
  1386. if "BUTTON" in sdata["CFG"]:
  1387. BTN = sdata["CFG"]["BUTTON"]
  1388. #txt=str(k+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+label
  1389. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  1390. _text = txt
  1391. #if b.text != txt: # TODO
  1392. # #txt+=str(self._XX)
  1393. # #b.configure(text= txt)
  1394. # _text = txt
  1395. # _bg="yellow"
  1396. # _ba="yellow"
  1397. if len(sdata) > 1:
  1398. ifval = 1
  1399. val_color = 0
  1400. for fix in sdata:
  1401. if fix == "CFG":
  1402. continue
  1403. #print( "$$$$",fix,sdata[fix])
  1404. for attr in sdata[fix]:
  1405. if "FX2" in sdata[fix][attr]:
  1406. if sdata[fix][attr]["FX2"]:
  1407. fx_color = 1
  1408. if "FX" in sdata[fix][attr]:
  1409. if sdata[fix][attr]["FX"]:
  1410. fx_color = 1
  1411. if "VALUE" in sdata[fix][attr]:
  1412. if sdata[fix][attr]["VALUE"] is not None:
  1413. val_color = 1
  1414. #try:b.configure(fg= "black")
  1415. #except:pass
  1416. if val_color:
  1417. _bg = "gold"
  1418. _ba = "#ffaa55"
  1419. if fx_color:
  1420. _fg = "blue"
  1421. else:
  1422. if fx_color:
  1423. fx_only = 1
  1424. else:
  1425. _bg = "grey"
  1426. _ba = "#aaa"
  1427. if "\n" in txt:
  1428. txt1 = txt.split("\n")[0]
  1429. _fg = "black"
  1430. if ifval:
  1431. if fx_only:
  1432. _bg = "cyan"
  1433. _ba = "#55d4ff"
  1434. if "SEL" in txt1:
  1435. #b.configure(bg="#77f")
  1436. _bg = "#77f"
  1437. else:
  1438. _bg = "grey"
  1439. _fg = "darkgrey"
  1440. if "SEL" in txt1:
  1441. _fg = "blue"
  1442. elif "ON" in txt1:
  1443. _fg = "#040"
  1444. elif "GO" in txt1:
  1445. _fg = "#555"
  1446. if "FL" in txt1:
  1447. _fg = "#00e"
  1448. out = {}
  1449. out["fx"] = fx_color
  1450. out["bg"] = _bg
  1451. out["ba"] = _ba
  1452. out["fg"] = _fg
  1453. #if fx_color:
  1454. # out["fg"] = "red"
  1455. out["text"] = _text
  1456. return out
  1457. #b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
  1458. class Elem_Container():
  1459. def __init__(self):
  1460. self.commands = []
  1461. self.val = {}
  1462. self.elem = {}
  1463. import lib.execlib as execlib
  1464. class MASTER():
  1465. def __init__(self):
  1466. #super().__init__()
  1467. self.base = baselib.Base ()
  1468. self.load()
  1469. self._XX = 0
  1470. self.all_attr =["DIM","PAN","TILT"]
  1471. self.elem_attr = {}
  1472. self.setup_elem = {} # Elem_Container()
  1473. self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI","PRO\nMODE"]
  1474. self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","PRO\nMODE"]
  1475. self.fx_main = Elem_Container()
  1476. self.fx_main.commands =["REC-FX","FX OFF","\n"]
  1477. self.fx_moves = Elem_Container()
  1478. self.fx_moves.commands =[
  1479. "FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  1480. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  1481. ]
  1482. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  1483. self.fx = Elem_Container()
  1484. self.fx.commands =[
  1485. "FX:DIM"," ", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  1486. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","2D-X:\n-","2D:MODE"
  1487. ]
  1488. self.fx_generic = Elem_Container()
  1489. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","FX:STATIC"]
  1490. self.fx_color = Elem_Container()
  1491. self.fx_color.commands =["FX:RED","FX-C:A","FX-C:B"]
  1492. self.commands = Elem_Container()
  1493. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  1494. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  1495. ,"BLIND","CLEAR","REC","EDIT","COPY",".","\n"
  1496. ]
  1497. self.elem_presets = {}
  1498. for i in range(8*8*8):
  1499. if i not in PRESETS.val_presets:
  1500. name = "Preset:"+str(i+1)+":\nXYZ"
  1501. #self.presets[i] = [i]
  1502. PRESETS.val_presets[i] = OrderedDict() # FIX
  1503. PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
  1504. PRESETS.label_presets[i] = "-"
  1505. modes.set_cb(self.xcb)
  1506. def jclient_send(self,data):
  1507. # namespace wraper
  1508. if not modes.val("BLIND"):
  1509. jclient_send(data)
  1510. def button_refresh(self,name,color,color2=None,text="",fg=None):
  1511. cprint("button_refresh",name,color)
  1512. #if color == "gold":
  1513. # color2 = "yellow"
  1514. try:
  1515. if color2 is None:
  1516. color2 = color
  1517. if text:
  1518. text = "\n"+str(text)
  1519. if name in self.commands.elem:
  1520. self.commands.elem[name]["bg"] = color
  1521. self.commands.elem[name]["text"] = name+ text
  1522. self.commands.elem[name].config(activebackground=color2)
  1523. if fg:
  1524. self.commands.elem[name]["fg"] = fg
  1525. elif name in self.fx.elem:
  1526. #todo
  1527. self.fx.elem[name]["bg"] = color
  1528. self.fx.elem[name].config(activebackground=color2)
  1529. if fg:
  1530. self.fx.elem[name]["fg"] = fg
  1531. # new version
  1532. for elems in [self.fx_moves]:
  1533. if name in elems.elem:
  1534. elem = elems.elem[name]
  1535. cprint("elem",elem)
  1536. elem.config(bg = color)
  1537. elem.config(text = name+text)
  1538. elem.config(activebackground=color2)
  1539. if fg and "fg" in elem:
  1540. elem["fg"] = fg
  1541. except Exception as e:cprint("exc",self,e)
  1542. def btn_cfg(self,nr,testing=0):
  1543. cfg = PRESETS._btn_cfg(nr)
  1544. button = PRESETS.btn_cfg(nr)
  1545. label = PRESETS.label(nr)
  1546. def _cb(data):
  1547. if not data:
  1548. cprint("err443",self,"_cb",data)
  1549. return None
  1550. cprint(self,"btn_cfg._cb()",data)
  1551. if data:
  1552. if "Button" in data and type(data["Button"]) is str:
  1553. txt = data["Button"]
  1554. PRESETS.btn_cfg(nr,txt)
  1555. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1556. if "Label" in data and type(data["Label"]) is str:
  1557. txt = data["Label"]
  1558. PRESETS.label(nr,txt)
  1559. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1560. if "Delay" in data and type(data["Delay"]) is str:
  1561. txt = data["Delay"]
  1562. try:
  1563. txt = float(txt)
  1564. if "DELAY" in cfg:
  1565. cfg["DELAY"] = round(txt,2)
  1566. except e as Exception:
  1567. print("DELAY Exception",e)
  1568. if "in-Fade" in data and type(data["in-Fade"]) is str:
  1569. txt = data["in-Fade"]
  1570. try:
  1571. txt = float(txt)
  1572. if "FADE" in cfg:
  1573. cfg["FADE"] = round(txt,2)
  1574. except e as Exception:
  1575. print("in-Fade Exception",e)
  1576. if "out-Fade" in data and type(data["out-Fade"]) is str:
  1577. txt = data["out-Fade"]
  1578. try:
  1579. txt = float(txt)
  1580. #if "OUT-FADE" in cfg:
  1581. cfg["OUT-FADE"] = round(txt,2)
  1582. except e as Exception:
  1583. print("out-Fade Exception",e)
  1584. modes.val("CFG-BTN",0)
  1585. master._refresh_exec(nr=nr)
  1586. dialog._cb = _cb
  1587. if 1: # testing:
  1588. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  1589. else:
  1590. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  1591. def label(self,nr):
  1592. txt = PRESETS.label(nr)
  1593. def _cb(data):
  1594. if not data:
  1595. cprint("err443",self,"_cb",data)
  1596. return None
  1597. txt = data["Value"]
  1598. cprint(self,"label._cb()",nr,txt)
  1599. if txt:
  1600. PRESETS.label(nr,txt)
  1601. self.elem_presets[nr].configure(text = PRESETS.get_btn_txt(nr))
  1602. modes.val("LABEL", 0)
  1603. master._refresh_exec(nr=nr)
  1604. dialog._cb= _cb #_x(nr)
  1605. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  1606. def xcb(self,mode,value=None):
  1607. cprint("MODE CALLBACK",mode,value,color="green",end="")
  1608. #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
  1609. if value:
  1610. cprint("===== ON ======",color="red")
  1611. txt = ""
  1612. if mode == "REC-FX":
  1613. modes.val("REC",0)
  1614. modes.val("REC",1)
  1615. if value == 2:
  1616. if mode in ["MOVE","COPY"]:
  1617. txt="to"
  1618. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  1619. else:
  1620. if mode in ["MOVE","COPY"]:
  1621. txt="from"
  1622. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  1623. else:
  1624. cprint("===== OFF ======",color="red")
  1625. if mode == "REC-FX":
  1626. modes.val("REC",0)
  1627. self.button_refresh(mode,color="lightgrey")#,fg="black")
  1628. def load(self,fname=""):
  1629. pass
  1630. def exit(self):
  1631. cprint("__del__",self)
  1632. PRESETS.backup_presets()
  1633. #print("********************************************************")
  1634. FIXTURES.backup_patch()
  1635. #print("*********del",self,"***********************************************")
  1636. def refresh_exec(self):
  1637. refresher_exec.reset() # = Refresher()
  1638. def _refresh_exec(self,nr=-1):
  1639. s = time.time()
  1640. cprint("PRESET.refresh_exec()")
  1641. refresher_exec.reset() # = Refresher()
  1642. self._XX +=1
  1643. self._nr_ok = 0
  1644. for nr in PRESETS.val_presets:
  1645. cfg = get_exec_btn_cfg(nr)
  1646. if not cfg:
  1647. out = {}
  1648. out["bg"] = "lightgrey"
  1649. out["ba"] = "grey"
  1650. out["fg"] = "grey"
  1651. out["text"] = "?"
  1652. cfg = out
  1653. b = self.elem_presets[nr]
  1654. b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"],fx=cfg["fx"])
  1655. time.sleep(0.01)
  1656. def refresh_fix(self):
  1657. refresher_fix.reset() # = Refresher()
  1658. def _refresh_fix(self):
  1659. cprint(self,"_refresh_fix")
  1660. s=time.time(); _XXX=0
  1661. menu_buff = {"DIM":0,"DIM-SUB":0,"FIX":0,"FIX-SUB":0}
  1662. elem_buffer = []
  1663. for fix in FIXTURES.fixtures:
  1664. sdata = FIXTURES.fixtures[fix]
  1665. elem_attr_fix = None
  1666. if fix in self.elem_attr:
  1667. elem_attr_fix = self.elem_attr[fix]
  1668. if "DIM" in sdata["ATTRIBUT"] and "_ACTIVE" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 2:
  1669. KEY = "DIM-SUB"
  1670. else:
  1671. KEY = "FIX-SUB"
  1672. FIX = 0
  1673. DIM = 0
  1674. for attr in sdata["ATTRIBUT"]:
  1675. _buff = {}
  1676. row = sdata["ATTRIBUT"][attr]
  1677. if attr.endswith("-FINE"):
  1678. continue
  1679. b_attr = attr
  1680. if b_attr == "_ACTIVE":
  1681. b_attr = "S"
  1682. elem = None
  1683. if elem_attr_fix:
  1684. if b_attr not in elem_attr_fix:
  1685. continue
  1686. elem = elem_attr_fix[b_attr]
  1687. if not elem:
  1688. continue
  1689. if "elem" not in _buff:
  1690. _buff["elem"] = elem
  1691. if not attr.startswith("_"):
  1692. v2 = row["VALUE"]
  1693. #_text = "{} {}".format(str(attr).rjust(4,"0"),str(v2).rjust(4,"0")) # ~0.2 sec
  1694. _text = "{} {}".format(attr,v2)
  1695. _buff["text"] = _text
  1696. if row["ACTIVE"]:
  1697. _buff["bg"] = "yellow"
  1698. _buff["abg"] = "yellow"
  1699. menu_buff[KEY] += 1
  1700. if b_attr == "S":
  1701. if KEY == "DIM-SUB":
  1702. DIM =1
  1703. else:
  1704. FIX =1
  1705. else:
  1706. _buff["bg"] = "grey"
  1707. _buff["abg"] = "grey"
  1708. if "FX" not in row: # insert FX2 excetption
  1709. row["FX"] = "" #OrderedDict()
  1710. if "FX2" not in row: # insert FX2 excetption
  1711. row["FX2"] = {} #OrderedDict()
  1712. #print("row",fix,row)
  1713. if row["FX"]:
  1714. _buff["fg"] = "blue"
  1715. elif row["FX2"]:
  1716. _buff["fg"] = "red"
  1717. else:
  1718. _buff["fg"] = "black"
  1719. elem_buffer.append(_buff)
  1720. menu_buff["FIX"] += FIX
  1721. menu_buff["DIM"] += DIM
  1722. cprint(" =+= "*10,"refresh_fix")
  1723. try:
  1724. for row in elem_buffer:
  1725. elem = row["elem"]
  1726. if not elem:
  1727. continue
  1728. #print("<elem>",elem)
  1729. for e in row:
  1730. if e == "elem":
  1731. continue
  1732. v = row[e]
  1733. #print("confg:",["key:",e,"val:",v])
  1734. if e == "abg":
  1735. elem.config(activebackground=v)
  1736. else:
  1737. elem[e] = v
  1738. w = window_manager.get_win("FIXTURES")
  1739. #print(dir(w))
  1740. w.update_idle_task()
  1741. #tkinter.Tk.update_idletasks(w)
  1742. except Exception as e:
  1743. cprint("exc434",e)
  1744. cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
  1745. cprint(gui_menu)
  1746. menu_buff["FIX-SUB"] -= menu_buff["FIX"]
  1747. if menu_buff["FIX-SUB"]:
  1748. gui_menu.config("FIXTURES","bg","yellow")
  1749. gui_menu.config("FIXTURES","activebackground","yellow")
  1750. elif menu_buff["FIX"]:
  1751. gui_menu.config("FIXTURES","bg","orange")
  1752. gui_menu.config("FIXTURES","activebackground","orange")
  1753. else:
  1754. gui_menu.config("FIXTURES","bg","")
  1755. gui_menu.config("FIXTURES","activebackground","")
  1756. gui_menu.update("FIXTURES","{} : {}".format(menu_buff["FIX"],menu_buff["FIX-SUB"]))
  1757. menu_buff["DIM-SUB"] -= menu_buff["DIM"]
  1758. if menu_buff["DIM-SUB"]:
  1759. gui_menu.config("DIMMER","bg","yellow")
  1760. gui_menu.config("DIMMER","activebackground","yellow")
  1761. elif menu_buff["DIM"]:
  1762. gui_menu.config("DIMMER","bg","orange")
  1763. gui_menu.config("DIMMER","activebackground","orange")
  1764. else:
  1765. gui_menu.config("DIMMER","bg","")
  1766. gui_menu.config("DIMMER","activebackground","")
  1767. gui_menu.update("DIMMER","{} : {}".format(menu_buff["DIM"],menu_buff["DIM-SUB"]))
  1768. cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
  1769. def preset_rec(self,nr):
  1770. cprint("------- STORE PRESET")
  1771. data = FIXTURES.get_active()
  1772. if modes.val("REC-FX"):
  1773. PRESETS.rec(nr,data,"REC-FX")
  1774. modes.val("REC-FX",0)
  1775. else:
  1776. PRESETS.rec(nr,data)
  1777. sdata=data
  1778. PRESETS.val_presets[nr] = sdata
  1779. master._refresh_exec()
  1780. return 1
  1781. def preset_select(self,nr):
  1782. cprint("SELECT PRESET")
  1783. sdata = PRESETS.val_presets[nr]
  1784. cmd = ""
  1785. for fix in sdata:
  1786. if fix == "CFG":
  1787. continue
  1788. for attr in sdata[fix]:
  1789. #v2 = sdata[fix][attr]["VALUE"]
  1790. #v2_fx = sdata[fix][attr]["FX"]
  1791. #print( self.data.elem_attr)
  1792. #if fix in self.elem_attr:
  1793. # if attr in self.elem_attr[fix]:
  1794. # elem = self.elem_attr[fix][attr]
  1795. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  1796. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  1797. #elem["bg"] = "yellow"
  1798. def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  1799. s=time.time()
  1800. t_start = time.time()
  1801. if xfade is None and FADE._is():
  1802. xfade = FADE.val()
  1803. if ptfade is None and FADE_move._is():
  1804. ptfade = FADE_move.val()
  1805. cprint("GO PRESET FADE",nr,val)
  1806. rdata = PRESETS.get_raw_map(nr)
  1807. if not rdata:
  1808. return 0
  1809. cprint("???????")
  1810. cfg = PRESETS.get_cfg(nr)
  1811. cprint("''''''''")
  1812. #virtcmd = FIXTURES.get_virtual(rdata)
  1813. if not cfg:
  1814. cprint("NO CFG",cfg,nr)
  1815. return 0
  1816. xFLASH = 0
  1817. value=None
  1818. cprint("preset_go",nr,cfg)
  1819. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  1820. self.preset_select(nr)
  1821. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  1822. xFLASH = 1
  1823. xfade = 0
  1824. if type(val) is not type(None) and val == 0 :
  1825. value = "off"
  1826. xfade=0
  1827. if "OUT-FADE" in cfg:
  1828. xfade=cfg["OUT-FADE"]
  1829. if event:
  1830. if str(event.type) == "ButtonRelease" or event.type == '5' :
  1831. value = "off"
  1832. xfade=0
  1833. if "OUT-FADE" in cfg:
  1834. xfade=cfg["OUT-FADE"]
  1835. cprint("preset_go() FLUSH",value,color="red")
  1836. #print(";",rdata)
  1837. print(";",cfg)
  1838. fcmd = FIXTURES.update_raw(rdata,update=0)
  1839. #print(":",fcmd) # raw dmx
  1840. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  1841. elif not val:
  1842. cprint("preset_go() STOP",value,color="red")
  1843. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  1844. fcmd = FIXTURES.update_raw(rdata)
  1845. self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  1846. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  1847. fcmd = FIXTURES.update_raw(rdata)
  1848. e=time.time()
  1849. print("_GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
  1850. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  1851. e=time.time()
  1852. print("GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
  1853. return
  1854. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  1855. self.refresh_exec()
  1856. self.refresh_fix()
  1857. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  1858. #print(len(self.elem_presets) )
  1859. if len(self.elem_presets) > nr: # RED BUTTON IF PRESSED
  1860. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  1861. if val:# or value:
  1862. #self.elem_presets[nr].config(borderwidth=1)
  1863. self.elem_presets[nr].config(bg="red")
  1864. else:
  1865. self._refresh_exec()
  1866. cprint("preset_go",time.time()-t_start)
  1867. def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  1868. if xfade is None and FADE._is():
  1869. xfade = FADE.val()
  1870. if ptfade is None and FADE_move._is():
  1871. ptfade = FADE_move.val()
  1872. cprint("PRESETS._preset_go() len=",len(rdata),cfg)
  1873. if xfade is None:
  1874. xfade = cfg["FADE"]
  1875. if ptfade is None:
  1876. ptfade = cfg["FADE"]
  1877. #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
  1878. #cprint(rdata,color="red")
  1879. vcmd = execlib.reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
  1880. cmd = []
  1881. delay=0
  1882. for i,v in enumerate(fcmd):
  1883. #print("go",i,v)
  1884. if xFLASH:
  1885. vcmd[i]["FLASH"] = 1
  1886. DMX = fcmd[i]["DMX"]
  1887. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  1888. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  1889. if value is not None:
  1890. vcmd[i]["VALUE"] = value
  1891. if value == "off":
  1892. if "FX2" in vcmd:
  1893. vcmd[i]["FX2"]["TYPE"] = value
  1894. if "FIX" in fcmd:
  1895. vcmd[i]["FIX"] = fcmd["FIX"]
  1896. if DMX and vcmd[i]:
  1897. vcmd[i]["DMX"] = DMX
  1898. if type(nr) is not type(None):
  1899. vcmd[i]["EXEC"] = str(int(nr)+1)
  1900. cmd.append(vcmd[i])
  1901. if cmd and not modes.val("BLIND"):
  1902. jclient_send(cmd)
  1903. def render(self):
  1904. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  1905. #self.draw_input()
  1906. pass
  1907. ##draw_sub_dim
  1908. import tkgui.dialog as dialoglib
  1909. dialog = dialoglib.Dialog()
  1910. from tkgui.draw import *
  1911. from tkgui.GUI import *
  1912. class LOAD_SHOW_AND_RESTART():
  1913. def __init__(self,fname=""):
  1914. self.fname=fname
  1915. self.base = baselib.Base()
  1916. def cb(self,event=None,force=0):
  1917. cprint("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
  1918. if not self.fname and not force:
  1919. return 0
  1920. if self.base.show_name == self.fname and not force:
  1921. cprint("filename is the same",self.fname)
  1922. return 0
  1923. if not force:
  1924. self.base._set(self.fname)
  1925. cprint("LOAD SHOW:",event,self.fname)
  1926. BASE_PATH = "/opt/LibreLight/Xdesk/"
  1927. cmd="_LibreLightDesk.py"
  1928. arg = ""
  1929. print("fork",[BASE_PATH,cmd,arg])
  1930. if "--easy" in sys.argv:
  1931. arg = "--easy"
  1932. movewin.process_kill(BASE_PATH+"tksdl/")
  1933. os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
  1934. sys.exit()
  1935. class BaseCallback():
  1936. def __init__(self,cb=None,args={}):
  1937. self._cb=cb
  1938. self.args = args
  1939. def cb(self,**args):
  1940. print("BaseCallback.cb()")
  1941. print(" ",self.args)
  1942. print(" ",self._cb)
  1943. if self._cb:
  1944. if self.args:
  1945. self._cb(args=self.args)
  1946. else:
  1947. self._cb()
  1948. def frame_of_show_list(frame,cb=None):
  1949. c=0
  1950. r=0
  1951. base = baselib.Base()
  1952. for i in ["name","stamp"]: #,"create"]:
  1953. b = tk.Label(frame,bg="grey",text=i)
  1954. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1955. c+=1
  1956. r+=1
  1957. blist = base._list()
  1958. for i in range(10):
  1959. blist.append(["",""])
  1960. if cb is None:
  1961. cb = DummyCallback #("load_show_list.cb")
  1962. for i in blist:
  1963. #print(i)
  1964. c=0
  1965. for j in i:
  1966. bg="lightgrey"
  1967. dbg="lightgrey"
  1968. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  1969. dbg = "lightgreen"
  1970. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  1971. dbg = "green"
  1972. if c > 0:
  1973. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  1974. b.config(activebackground=dbg)
  1975. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1976. else:
  1977. if base.show_name == i[0]:
  1978. bg="green"
  1979. _cb = cb(j)
  1980. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  1981. if base.show_name == i[0]:
  1982. b.config(activebackground=bg)
  1983. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1984. c+=1
  1985. r+=1
  1986. def PRESET_CFG_CHECKER(sdata):
  1987. "repair CFG "
  1988. ok = 0
  1989. if "CFG" not in sdata:
  1990. sdata["CFG"] = OrderedDict()
  1991. ok += 1
  1992. if "FADE" not in sdata["CFG"]:
  1993. sdata["CFG"]["FADE"] = 4
  1994. ok += 1
  1995. if "DELAY" not in sdata["CFG"]:
  1996. sdata["CFG"]["DELAY"] = 0
  1997. ok += 1
  1998. if "BUTTON" not in sdata["CFG"]:
  1999. sdata["CFG"]["BUTTON"] = "GO"
  2000. ok += 1
  2001. if "HTP-MASTER" not in sdata["CFG"]:
  2002. sdata["CFG"]["HTP-MASTER"] = 100 #%
  2003. ok += 1
  2004. if "SIZE-MASTER" not in sdata["CFG"]:
  2005. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  2006. ok += 1
  2007. if "SPEED-MASTER" not in sdata["CFG"]:
  2008. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  2009. ok += 1
  2010. if "OFFSET-MASTER" not in sdata["CFG"]:
  2011. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  2012. ok += 1
  2013. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  2014. #except:pass
  2015. return ok
  2016. class Presets():
  2017. def __init__(self):
  2018. #super().__init__()
  2019. self.base = baselib.Base()
  2020. #self.load()
  2021. self._last_copy = None
  2022. self._last_move = None
  2023. self.fx_buffer = {}
  2024. def load_presets(self):
  2025. #self._load()
  2026. filename="presets"
  2027. #self.base._init()
  2028. d,l = self.base._load(filename)
  2029. for i in d:
  2030. sdata = d[i]
  2031. ok = PRESET_CFG_CHECKER(sdata)
  2032. self.val_presets = d
  2033. self.label_presets = l
  2034. def check_cfg(self,nr=None):
  2035. cprint("PRESETS.check_cfg()",nr)#,color="red")
  2036. ok = 0
  2037. if nr is not None:
  2038. if nr in self.val_presets:
  2039. sdata = self.val_presets[nr]
  2040. ok += self._check_cfg(sdata)
  2041. else:
  2042. cprint("nr not in data ",nr,color="red")
  2043. else:
  2044. for nr in self.val_presets:
  2045. sdata = self.val_presets[nr]
  2046. ok += self._check_cfg(sdata)
  2047. return ok
  2048. def _check_cfg(self,sdata):
  2049. cprint("PRESETS._check_cfg()")#,color="red")
  2050. ok = PRESET_CFG_CHECKER(sdata)
  2051. if ok:
  2052. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  2053. return ok
  2054. def backup_presets(self,save_as="",new=0):
  2055. filename = "presets"
  2056. data = self.val_presets
  2057. labels = self.label_presets
  2058. if new:
  2059. #a = []
  2060. #for i in range(512):
  2061. # e = PRESET_CFG_CHECKER({})
  2062. # e["NAME"] = str(i)
  2063. # a.append(e)
  2064. #data = a
  2065. data = []#*512
  2066. labls = [""]*512
  2067. #self.base._init()
  2068. self.base._backup(filename,data,labels,save_as)
  2069. def get_cfg(self,nr):
  2070. cprint("PRESETS.get_cfg()",nr)
  2071. self.check_cfg(nr)
  2072. if nr not in self.val_presets:
  2073. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  2074. return {}
  2075. if "CFG" in self.val_presets[nr]:
  2076. return self.val_presets[nr]["CFG"]
  2077. def clean(self,nr):
  2078. if nr not in self.val_presets:
  2079. self.val_presets[nr] = OrderedDict()
  2080. #self.val_presets[nr]["VALUE"] = 0
  2081. #self.val_presets[nr]["FX"] = ""
  2082. sdata = self.val_presets[nr]
  2083. for fix in sdata:
  2084. #print("exec.clear()",nr,fix,sdata[fix])
  2085. for attr in sdata[fix]:
  2086. row = sdata[fix][attr]
  2087. if fix == "CFG":
  2088. continue
  2089. if "VALUE" not in row:
  2090. row["VALUE"] = None
  2091. if "FX" not in row:
  2092. row["FX"] = ""
  2093. if "FX2" not in row:
  2094. row["FX2"] = OrderedDict()
  2095. elif row["FX2"]:
  2096. for k in ["SIZE","SPEED","START","OFFSET"]:
  2097. row["FX2"][k] = int( row["FX2"][k] )
  2098. row["FX"] = ""
  2099. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  2100. #"off:0:0:0:16909:-:"
  2101. x = row["FX"].split(":")
  2102. cprint("-fx",x,len(x))
  2103. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  2104. if len(x) >= 6:
  2105. row["FX2"]["TYPE"] = x[0]
  2106. row["FX2"]["SIZE"] = int(x[1])
  2107. row["FX2"]["SPEED"] = int(x[2])
  2108. row["FX2"]["START"] = int(x[3])
  2109. row["FX2"]["OFFSET"] = int(x[4])
  2110. row["FX2"]["BASE"] = x[5]
  2111. row["FXOLD"] = row["FX"]
  2112. row["FX"] = ""
  2113. #cprint("exec.clear()",nr,fix,row)
  2114. def get_raw_map(self,nr):
  2115. self.clean(nr)
  2116. cprint("get_raw_map",nr)
  2117. sdata = self.val_presets[nr]
  2118. cmd = ""
  2119. out = []
  2120. dmx=-1
  2121. for fix in sdata:
  2122. if fix == "CFG":
  2123. #print("CFG",nr,sdata[fix])
  2124. continue
  2125. for attr in sdata[fix]:
  2126. x = {}
  2127. #print("RAW",attr)
  2128. x["FIX"] = fix
  2129. x["ATTR"] = attr
  2130. x["VALUE"] = sdata[fix][attr]["VALUE"]
  2131. x["FX"] = sdata[fix][attr]["FX"]
  2132. x["FX2"] = sdata[fix][attr]["FX2"]
  2133. #x["DMX"] = sdata[fix][attr]["NR"]
  2134. out.append(x)
  2135. return out
  2136. def get_btn_txt(self,nr):
  2137. sdata=self.val_presets[nr]
  2138. BTN="go"
  2139. if "CFG" in sdata:
  2140. if "BUTTON" in sdata["CFG"]:
  2141. BTN = sdata["CFG"]["BUTTON"]
  2142. _label = self.label_presets[nr] # = label
  2143. #txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  2144. #txt=str(nr+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+_label
  2145. txt="{} {} {}\n{}".format(nr+1,BTN,len(sdata)-1,_label)
  2146. cprint("get_btn_txt",nr,[txt])
  2147. return txt
  2148. def _btn_cfg(self,nr,txt=None):
  2149. if nr not in self.val_presets:
  2150. return ""
  2151. if "CFG" not in self.val_presets[nr]:
  2152. self.val_presets[nr]["CFG"] = OrderedDict()
  2153. return self.val_presets[nr]["CFG"]
  2154. def btn_cfg(self,nr,txt=None):
  2155. if nr not in self.val_presets:
  2156. return ""
  2157. if "CFG" not in self.val_presets[nr]:
  2158. self.val_presets[nr]["CFG"] = OrderedDict()
  2159. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  2160. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  2161. if type(txt) is str:
  2162. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  2163. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  2164. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  2165. master._refresh_exec(nr=nr)
  2166. cprint("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  2167. return self.val_presets[nr]["CFG"]["BUTTON"]
  2168. def label(self,nr,txt=None):
  2169. if nr not in self.label_presets:
  2170. return ""
  2171. if type(txt) is str:
  2172. self.label_presets[nr] = txt
  2173. cprint("set label",nr,[txt])
  2174. cprint("??? ?? set label",nr,[txt])
  2175. return self.label_presets[nr]
  2176. def clear_move(self):
  2177. cprint("PRESETS.clear_move()",end=" ")
  2178. self.clear_copy()
  2179. def clear_copy(self):
  2180. cprint("PRESETS.clear_copy()",end=" ")
  2181. if self._last_copy is not None:
  2182. cprint("=OK=",color="red")
  2183. self._last_copy = None
  2184. else:
  2185. cprint("=NONE=",color="green")
  2186. def copy(self,nr,overwrite=1):
  2187. cprint("PRESETS._copy",nr,"last",self._last_copy)
  2188. if nr >= 0:
  2189. if self._last_copy is not None:
  2190. if modes.val("COPY"):
  2191. modes.val("COPY",3)
  2192. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  2193. return ok #ok
  2194. else:
  2195. if modes.val("COPY"):
  2196. modes.val("COPY",2)
  2197. self._last_copy = nr
  2198. cprint("PRESETS.copy START ",color="red")
  2199. return 0
  2200. return 1 # on error reset move
  2201. def _copy(self,nr_from,nr_to,overwrite=1):
  2202. cprint("PRESETS._copy",nr_from,"to",nr_to)
  2203. self.check_cfg(nr_from)
  2204. if type(self._last_copy) is None:
  2205. cprint("PRESETS._copy last nr is None",color="red")
  2206. return 0
  2207. cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
  2208. if nr_from in self.val_presets and nr_to in self.val_presets:
  2209. fdata = self.val_presets[nr_from]
  2210. tdata = self.val_presets[nr_to]
  2211. #cprint(fdata)
  2212. flabel = self.label_presets[nr_from]
  2213. tlabel = self.label_presets[nr_to]
  2214. self.val_presets[nr_to] = copy.deepcopy(fdata)
  2215. self.label_presets[nr_to] = flabel
  2216. if not overwrite: #default
  2217. cprint("overwrite",overwrite)
  2218. self.val_presets[nr_from] = copy.deepcopy(tdata)
  2219. self.label_presets[nr_from] = tlabel
  2220. #self.label_presets[nr_from] = "MOVE"
  2221. self.clear_copy()
  2222. cprint("PRESETS.copy OK",color="green")
  2223. return 1
  2224. def move(self,nr):
  2225. cprint("PRESETS.move",self._last_copy,"to",nr)
  2226. if nr >= 0:
  2227. last = self._last_copy
  2228. if modes.val("MOVE"):
  2229. modes.val("MOVE",2)
  2230. ok= self.copy(nr,overwrite=0)
  2231. if ok and last >= 0:
  2232. if modes.val("MOVE"):
  2233. modes.val("MOVE",3)
  2234. cprint("PRESETS.move OK",color="red")
  2235. #self.delete(last)
  2236. return ok,nr,last #ok
  2237. return 0,nr,last # on error reset move
  2238. def delete(self,nr):
  2239. cprint("PRESETS.delete",nr)
  2240. ok=0
  2241. if nr in self.val_presets:
  2242. self.val_presets[nr] = OrderedDict()
  2243. self.label_presets[nr] = "-"
  2244. ok = 1
  2245. self.check_cfg(nr)
  2246. return ok
  2247. def rec(self,nr,data,arg=""):
  2248. cprint("rec",self,"rec()",len(data),arg)
  2249. self.check_cfg(nr)
  2250. self._check_cfg(data) #by ref
  2251. odata=self.val_presets[nr]
  2252. #print("odata",odata)
  2253. if "CFG" in odata:
  2254. if "BUTTON" in odata["CFG"]:
  2255. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  2256. self.val_presets[nr] = data
  2257. return 1
  2258. class FixtureEditor():
  2259. def __init__(self,dmx=1):
  2260. pass
  2261. self.elem=[]
  2262. self.dmx=dmx
  2263. cprint("init FixtureEditor",dmx)
  2264. def event(self,a1="",a2=""):
  2265. cprint([self.dmx,a1,a2])
  2266. j=[]
  2267. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
  2268. j.append(jdata)
  2269. jclient_send(j)
  2270. class MasterWingX():
  2271. def __init__(self,dmx=1):
  2272. pass
  2273. self.elem=[]
  2274. self.dmx=dmx
  2275. cprint("init MasterWing",dmx)
  2276. def event(self,a1="",a2=""):
  2277. cprint([self.dmx,a1,a2])
  2278. jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
  2279. j=[]
  2280. j.append(jdata)
  2281. jclient_send(j)
  2282. class BufferVar():
  2283. def __init__(self,elem):
  2284. self.elem = elem
  2285. def change_dmx(self,event=""):
  2286. nr=1
  2287. txt=""
  2288. def cb(data):
  2289. txt = data["Value"]
  2290. dialog._cb = _cb
  2291. dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
  2292. cprint("change_dmx",[event,self])
  2293. lf_nr = 0
  2294. from tkinter import PhotoImage
  2295. _shift_key = 0
  2296. class WindowManager():
  2297. def __init__(self):
  2298. self.windows = {}
  2299. self.obj = {}
  2300. self.nr= 0
  2301. self.first=""
  2302. self.window_init_buffer = {}
  2303. def update(self,w,name="",obj=None):
  2304. name = str(name)
  2305. for k in self.windows:
  2306. if k == name:
  2307. self.windows[str(name)] = w
  2308. self.obj[str(name)] = obj
  2309. def new(self,w,name="",obj=None,wcb=None):
  2310. name = str(name)
  2311. if wcb and name:
  2312. self.window_init_buffer[name] = wcb
  2313. if not self.first:
  2314. if name:
  2315. self.first = name
  2316. else:
  2317. self.first = str(self.nr)
  2318. if w:
  2319. w.tk.state(newstate='normal')
  2320. w.tk.attributes('-topmost',True)
  2321. if name:
  2322. self.windows[str(name)] = w
  2323. self.obj[str(name)] = obj
  2324. else:
  2325. self.windows[str(self.nr)] = w
  2326. self.obj[str(self.nr)] = obj
  2327. self.nr+=1
  2328. def mainloop(self):
  2329. self.windows[self.first].mainloop()
  2330. def get_win(self,name):
  2331. cprint(self,".get_win(name) =",name)
  2332. name = str(name)
  2333. if name in self.windows:
  2334. out = self.windows[name]
  2335. cprint(out)
  2336. return out
  2337. def get(self,name):
  2338. return get_win(name)
  2339. def get_obj(self,name):
  2340. name = str(name)
  2341. if name in self.windows:
  2342. out = self.obj[name]
  2343. return out
  2344. def create(self,name):
  2345. cprint( "create Window",name)
  2346. if name in self.window_init_buffer:
  2347. c = self.window_init_buffer[name]
  2348. print(c)
  2349. print(dir(c))
  2350. w,obj,cb_ok = c.create()
  2351. window_manager.update(w,name,obj)
  2352. if cb_ok:
  2353. cb_ok()
  2354. resize = 1
  2355. if "resize" in c.args:
  2356. if not c.args["resize"]:
  2357. resize = 0
  2358. #if resize:
  2359. libwin.get_window_position(_filter=name,win=w)
  2360. if name in ["ENCODER"]:
  2361. global _ENCODER_WINDOW
  2362. _ENCODER_WINDOW = w
  2363. if name in ["DIMMER","FIXTURES"]:
  2364. refresher_fix.reset() # = Refresher()
  2365. def _check(self,name):
  2366. try:
  2367. self.windows[name].tk.state(newstate='normal')
  2368. return 1
  2369. except Exception as e:
  2370. cprint("exception",e,color="red")
  2371. cprint("info",name,self.windows[name],color="red")
  2372. def top(self,name):
  2373. name = str(name)
  2374. if name not in self.windows:
  2375. cprint(name,"not in self.windows",self.windows.keys())
  2376. return
  2377. if not self._check(name):
  2378. self.create(name)
  2379. w = self.windows[name]
  2380. #def get_lineno():
  2381. print(" 2.1- ln",movewin.get_lineno(),w,str(type(w)))
  2382. #if type(w) is type(window_create_buffer):
  2383. if not str(type(w)).startswith("<class 'function'>"):
  2384. w.tk.attributes('-topmost',True)
  2385. w.tk.attributes('-topmost',False)
  2386. w.tk.update_idletasks()
  2387. else:
  2388. print(" 2.2-",w)
  2389. w()
  2390. class Console():
  2391. def __init__(self):
  2392. pass
  2393. def flash_off(self,fix):
  2394. pass#client.send("df0:alloff:::,")
  2395. def fx_off(self,fix):
  2396. cprint("Console.fx_off()",fix)
  2397. if not fix or fix == "all":
  2398. #client.send("fx0:alloff:,fxf:alloff:,")
  2399. #client.send("df0:alloff:::,")
  2400. j = []
  2401. if 0:
  2402. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  2403. j.append(jdata)
  2404. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  2405. j.append(jdata)
  2406. else:
  2407. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  2408. j.append(jdata)
  2409. if not modes.val("BLIND"):
  2410. jclient_send(j)
  2411. return 0
  2412. def test_1():
  2413. #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
  2414. pass
  2415. window_manager = WindowManager()
  2416. CONSOLE = Console()
  2417. PRESETS = Presets()
  2418. FIXTURES = fixlib.Fixtures()
  2419. FIXTURES.gui = GUIHandler()
  2420. def LOAD_SHOW():
  2421. PRESETS.load_presets()
  2422. FIXTURES.load_patch()
  2423. #master._refresh_fix()
  2424. #master._refresh_exec()
  2425. LOAD_SHOW()
  2426. master = MASTER()
  2427. class Refresher():
  2428. def __init__(self):
  2429. self.time = time.time()
  2430. self.time_max = time.time()
  2431. self.time_delta = 15
  2432. self.update = 1
  2433. self.name = "name" # exec
  2434. self.cb = None #self.dummy_cb
  2435. def dummy_cb(self):
  2436. cprint(self,"dummy_cd()",time.time()-self.time)
  2437. def reset(self):
  2438. self.time = time.time()
  2439. self.update = 1
  2440. def refresh(self):
  2441. if self.update:
  2442. if self.time+self.time_delta < time.time():
  2443. self._refresh()
  2444. else:
  2445. self.time = time.time()
  2446. def _refresh(self):
  2447. cprint("_refresh()",self.name,self)
  2448. if not INIT_OK:
  2449. return
  2450. self.time_max = time.time()
  2451. self.time = time.time()
  2452. self.update = 0
  2453. try:
  2454. if self.cb:
  2455. self.cb()
  2456. else:
  2457. self.dummy_cb()
  2458. except Exception as e:
  2459. cprint("_refresh except:",e,"cb:",self.cb)
  2460. traceback.print_exc()
  2461. cprint()
  2462. cprint("t=",self.time_max- time.time())
  2463. def loop(self,args={}):
  2464. while 1:
  2465. try:
  2466. if INIT_OK:
  2467. self.refresh()
  2468. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  2469. except Exception as e:
  2470. cprint("loop exc",e)
  2471. traceback.print_exc()
  2472. cprint("== cb EXCEPT",e,color="red")
  2473. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  2474. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  2475. time.sleep(0.2)
  2476. print("main",__name__)
  2477. __run_main = 0
  2478. if __name__ == "__main__":
  2479. __run_main = 1
  2480. else:
  2481. import __main__
  2482. if "unittest" not in dir(__main__):
  2483. __run_main = 1
  2484. refresher_fix = Refresher()
  2485. refresher_fix.time_delta = 0.50
  2486. refresher_fix.name = "fix"
  2487. refresher_fix.reset()
  2488. refresher_fix.cb = master._refresh_fix
  2489. refresher_exec = Refresher()
  2490. refresher_exec.time_delta = 10 #0
  2491. refresher_exec.name = "exec"
  2492. refresher_exec.reset()
  2493. refresher_exec.cb = master._refresh_exec
  2494. refresher_exec = Refresher()
  2495. refresher_exec.time_delta = 10 #0
  2496. refresher_exec.name = "exec-fader"
  2497. refresher_exec.reset()
  2498. refresher_exec.cb = refresh_exec_fader_cfg
  2499. def loops(**args):
  2500. time.sleep(5) # wait until draw all window's
  2501. cprint("-> run loops")
  2502. thread.start_new_thread(refresher_fix.loop,())
  2503. thread.start_new_thread(refresher_exec.loop,())
  2504. class window_create_sdl_buffer():
  2505. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  2506. self.args = args.copy()
  2507. self.cls = cls
  2508. self.cb_ok = cb_ok
  2509. self.data = data
  2510. self.scroll = scroll
  2511. self.gui = gui
  2512. def create(self,hidde=0):
  2513. cprint()
  2514. return [self.cls,self.cls,None] #w,obj,cb_ok
  2515. class window_create_buffer():
  2516. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  2517. self.args = args.copy()
  2518. self.cls = cls
  2519. self.cb_ok = cb_ok
  2520. self.data = data
  2521. self.scroll = scroll
  2522. self.gui = gui
  2523. def create(self,hidde=0):
  2524. cprint()
  2525. cprint()
  2526. cprint("window_create_buffer.create()",id(self),self.args["title"],color="green")
  2527. obj = None
  2528. w = libtk.Window(self.args)
  2529. out = []
  2530. f = None
  2531. h = None
  2532. if self.scroll:
  2533. head = None
  2534. foot = None
  2535. if "head" in self.args:
  2536. head = self.args["head"]
  2537. if "foot" in self.args:
  2538. foot = self.args["foot"]
  2539. w1 = ScrollFrame(w.tk,width=self.args["width"],height=self.args["height"],foot=foot,head=head)
  2540. if type(w1) is list:
  2541. try:
  2542. h = w1[0]
  2543. f = w1[2]
  2544. except:pass
  2545. w1 = w1[1]
  2546. else:
  2547. w1 = tk.Frame(w.tk,width=self.args["width"],height=self.args["height"])
  2548. w1.pack()
  2549. try:
  2550. obj=self.cls(self.gui,w1,self.data,foot=f,head=h)
  2551. except:
  2552. obj=self.cls(self.gui,w1,self.data)
  2553. return w,obj,self.cb_ok
  2554. def open_sdl_window():
  2555. cprint("open_sdl_window ... delay 1sec",color="yellow")
  2556. time.sleep(1)
  2557. movewin.startup_all_sdl()
  2558. if __run_main:
  2559. cprint("main")
  2560. #thread.start_new_thread(refresher_fix.loop,())
  2561. #thread.start_new_thread(refresher_exec.loop,())
  2562. TOP = _POS_TOP + 15
  2563. L0 = _POS_LEFT
  2564. L1 = _POS_LEFT + 95
  2565. L2 = _POS_LEFT + 920
  2566. W1 = 810
  2567. H1 = 550
  2568. HTB = 23 # hight of the titlebar from window manager
  2569. pos_list = libwin.read_window_position()
  2570. data = []
  2571. #data.append({"text":"COMMAND"})
  2572. #data.append({"text":"CONFIG"})
  2573. data.append({"text":"PATCH"})
  2574. data.append({"text":"DIMMER"})
  2575. data.append({"text":"FIXTURES"})
  2576. data.append({"text":"FIX-LIST"})
  2577. data.append({"text":"EXEC","name":"EXEC-BTN"})
  2578. data.append({"text":"EXEC-WING"})
  2579. data.append({"text":"---"})
  2580. data.append({"text":"SETUP"})
  2581. data.append({"text":"COMMAND"})
  2582. data.append({"text":"LIVE"})
  2583. data.append({"text":"FX"})
  2584. data.append({"text":"ENCODER"})
  2585. data.append({"text":"COLORPICKER","name":"COLOR"})
  2586. data.append({"text":"---"})
  2587. data.append({"text":"FIXTURE-EDITOR","name":"FIX-EDIT"})
  2588. data.append({"text":"CONFIG"})
  2589. data.append({"text":"SDL-MIDI"})
  2590. data.append({"text":"CLOCK"})
  2591. data.append({"text":"RAY-DMX"})
  2592. data.append({"text":"SDL-DMX"})
  2593. data.append({"text":"SDL-VPU"})
  2594. data.append({"text":"SDL-OSZI"})
  2595. data.append({"text":"---"})
  2596. data.append({"text":"---"})
  2597. data.append({"text":"- DEMO -"})
  2598. data.append({"text":"---"})
  2599. data.append({"text":"SDL-STAGE"})
  2600. data.append({"text":"SDL-Shader"})
  2601. #data.append({"text":"MASTER-WING"})
  2602. name="MAIN"
  2603. args = {"title":"MAIN","master":1,"width":80,"height":H1,"left":L0,"top":TOP,"resize":1}
  2604. geo = libwin.split_window_position(pos_list,name)
  2605. if geo:
  2606. args.update(geo)
  2607. cls = GUI_menu
  2608. cb_ok = None
  2609. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2610. window_manager.new(None,name,wcb=c)
  2611. window_manager.top(name)
  2612. gui_menu_gui = window_manager.get_win(name)
  2613. gui_menu = window_manager.get_obj(name)
  2614. master._refresh_fix()
  2615. # =======================================================================
  2616. name="EXEC"
  2617. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2618. geo = libwin.split_window_position(pos_list,name)
  2619. if geo:
  2620. args.update(geo)
  2621. data = PRESETS
  2622. cls = draw_exec #GUI_ExecWingLayout
  2623. cb_ok = None #set_exec_fader_all
  2624. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2625. window_manager.new(None,name,wcb=c)
  2626. if libwin.split_window_show(pos_list,_filter=name):
  2627. window_manager.top(name)
  2628. #print(dir(cls))
  2629. #print(cls)
  2630. #sys.exit()
  2631. # =======================================================================
  2632. name="SDL-MIDI"
  2633. def sdl_config():
  2634. cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/midi.py &"
  2635. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/midi.py " #&"
  2636. print(cmd)
  2637. #os.popen(cmd)
  2638. def xyz123(cmd):
  2639. os.system(cmd)
  2640. thread.start_new_thread(xyz123,(cmd,))
  2641. return [None,None,None]
  2642. #class window_create_sdl_buffer():
  2643. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2644. geo = libwin.split_window_position(pos_list,name)
  2645. if geo:
  2646. args.update(geo)
  2647. data = []
  2648. cls = sdl_config #: None #GUI_CONF
  2649. cb_ok = None
  2650. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2651. window_manager.new(None,name,wcb=c)
  2652. if libwin.split_window_show(pos_list,_filter=name):
  2653. window_manager.top(name)
  2654. # =======================================================================
  2655. name="SDL-VPU"
  2656. def sdl_config():
  2657. cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/config.py &"
  2658. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/dmx.py " #&"
  2659. cmd="python3 /opt/LibreLight/Xdesk/vpu/watchdog_vpu.py -single"
  2660. print(cmd)
  2661. #os.popen(cmd)
  2662. def xyz123(cmd):
  2663. os.system(cmd)
  2664. thread.start_new_thread(xyz123,(cmd,))
  2665. return [None,None,None]
  2666. #class window_create_sdl_buffer():
  2667. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2668. geo = libwin.split_window_position(pos_list,name)
  2669. if geo:
  2670. args.update(geo)
  2671. data = []
  2672. cls = sdl_config #: None #GUI_CONF
  2673. cb_ok = None
  2674. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2675. window_manager.new(None,name,wcb=c)
  2676. if libwin.split_window_show(pos_list,_filter=name):
  2677. window_manager.top(name)
  2678. # =======================================================================
  2679. #python3 /opt/LibreLight/Xdesk/vpu/watchdog_vpu.py -single
  2680. name="SDL-OSZI"
  2681. def sdl_config():
  2682. cmd="python3 /opt/LibreLight/ASP/monitor/oszi_grid.py"
  2683. print(cmd)
  2684. def xyz123(cmd):
  2685. os.system(cmd)
  2686. thread.start_new_thread(xyz123,(cmd,))
  2687. return [None,None,None]
  2688. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2689. geo = libwin.split_window_position(pos_list,name)
  2690. if geo:
  2691. args.update(geo)
  2692. data = []
  2693. cls = sdl_config #: None #GUI_CONF
  2694. cb_ok = None
  2695. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2696. window_manager.new(None,name,wcb=c)
  2697. if libwin.split_window_show(pos_list,_filter=name):
  2698. window_manager.top(name)
  2699. # =======================================================================
  2700. #python3 /opt/LibreLight/Xdesk/vpu/watchdog_vpu.py -single
  2701. name="SDL-DMX"
  2702. def sdl_config():
  2703. cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/config.py &"
  2704. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/dmx.py " #&"
  2705. print(cmd)
  2706. #os.popen(cmd)
  2707. def xyz123(cmd):
  2708. os.system(cmd)
  2709. thread.start_new_thread(xyz123,(cmd,))
  2710. return [None,None,None]
  2711. #class window_create_sdl_buffer():
  2712. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2713. geo = libwin.split_window_position(pos_list,name)
  2714. if geo:
  2715. args.update(geo)
  2716. data = []
  2717. cls = sdl_config #: None #GUI_CONF
  2718. cb_ok = None
  2719. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2720. window_manager.new(None,name,wcb=c)
  2721. if libwin.split_window_show(pos_list,_filter=name):
  2722. window_manager.top(name)
  2723. # =======================================================================
  2724. #python3 /opt/LibreLight/Xdesk/vpu/watchdog_vpu.py -single
  2725. name="RAY-DMX"
  2726. def sdl_config():
  2727. cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/config.py &"
  2728. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tkray/dmx.py " #&"
  2729. print(cmd)
  2730. #os.popen(cmd)
  2731. def xyz123(cmd):
  2732. os.system(cmd)
  2733. thread.start_new_thread(xyz123,(cmd,))
  2734. return [None,None,None]
  2735. #class window_create_sdl_buffer():
  2736. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2737. geo = libwin.split_window_position(pos_list,name)
  2738. if geo:
  2739. args.update(geo)
  2740. data = []
  2741. cls = sdl_config #: None #GUI_CONF
  2742. cb_ok = None
  2743. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2744. window_manager.new(None,name,wcb=c)
  2745. if libwin.split_window_show(pos_list,_filter=name):
  2746. window_manager.top(name)
  2747. # =======================================================================
  2748. name="SDL-STAGE"
  2749. def sdl_config():
  2750. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk//3d/stage_3d.py " #&"
  2751. print(cmd)
  2752. #os.popen(cmd)
  2753. def xyz123(cmd):
  2754. os.system(cmd)
  2755. thread.start_new_thread(xyz123,(cmd,))
  2756. return [None,None,None]
  2757. #class window_create_sdl_buffer():
  2758. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2759. geo = libwin.split_window_position(pos_list,name)
  2760. if geo:
  2761. args.update(geo)
  2762. data = []
  2763. cls = sdl_config #: None #GUI_CONF
  2764. cb_ok = None
  2765. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2766. window_manager.new(None,name,wcb=c)
  2767. if libwin.split_window_show(pos_list,_filter=name):
  2768. window_manager.top(name)
  2769. # =======================================================================
  2770. name="SDL-Shader"
  2771. def sdl_config():
  2772. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk//3d/demo_shaders.py " #&"
  2773. print(cmd)
  2774. #os.popen(cmd)
  2775. def xyz123(cmd):
  2776. os.system(cmd)
  2777. thread.start_new_thread(xyz123,(cmd,))
  2778. return [None,None,None]
  2779. #class window_create_sdl_buffer():
  2780. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2781. geo = libwin.split_window_position(pos_list,name)
  2782. if geo:
  2783. args.update(geo)
  2784. data = []
  2785. cls = sdl_config #: None #GUI_CONF
  2786. cb_ok = None
  2787. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2788. window_manager.new(None,name,wcb=c)
  2789. if libwin.split_window_show(pos_list,_filter=name):
  2790. window_manager.top(name)
  2791. # =======================================================================
  2792. name="FIX-LIST"
  2793. def sdl_config():
  2794. cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/fix.py " #&"
  2795. print(cmd)
  2796. #os.popen(cmd)
  2797. def xyz123(cmd):
  2798. os.system(cmd)
  2799. thread.start_new_thread(xyz123,(cmd,))
  2800. return [None,None,None]
  2801. #class window_create_sdl_buffer():
  2802. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2803. geo = libwin.split_window_position(pos_list,name)
  2804. if geo:
  2805. args.update(geo)
  2806. data = []
  2807. cls = sdl_config #: None #GUI_CONF
  2808. cb_ok = None
  2809. c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2810. window_manager.new(None,name,wcb=c)
  2811. if libwin.split_window_show(pos_list,_filter=name):
  2812. window_manager.top(name)
  2813. # =======================================================================
  2814. name="CONFIG"
  2815. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2816. geo = libwin.split_window_position(pos_list,name)
  2817. if geo:
  2818. args.update(geo)
  2819. data = []
  2820. cls = GUI_CONF
  2821. cb_ok = None
  2822. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2823. window_manager.new(None,name,wcb=c)
  2824. if libwin.split_window_show(pos_list,_filter=name):
  2825. window_manager.top(name)
  2826. # =======================================================================
  2827. name="DIMMER"
  2828. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2829. geo = libwin.split_window_position(pos_list,name)
  2830. if geo:
  2831. args.update(geo)
  2832. cls = GUI_DIM
  2833. data = FIXTURES
  2834. ok_cb=None
  2835. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2836. window_manager.new(None,name,wcb=c)
  2837. if libwin.split_window_show(pos_list,_filter=name):
  2838. window_manager.top(name)
  2839. # =======================================================================
  2840. name="FIXTURES"
  2841. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2842. geo = libwin.split_window_position(pos_list,name)
  2843. if geo:
  2844. args.update(geo)
  2845. cls = GUI_FIX
  2846. ok_cb=None
  2847. data = FIXTURES
  2848. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2849. window_manager.new(None,name,wcb=c)
  2850. if libwin.split_window_show(pos_list,_filter=name):
  2851. window_manager.top(name)
  2852. # =======================================================================
  2853. name="FIXTURE-EDITOR"
  2854. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  2855. geo = libwin.split_window_position(pos_list,name)
  2856. if geo:
  2857. args.update(geo)
  2858. data=[]
  2859. for i in range(12*6):
  2860. data.append({"text"+str(i):"test"})
  2861. cls = GUI_FixtureEditor
  2862. #cls = GUI_FaderLayout
  2863. cb_ok = None
  2864. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2865. window_manager.new(None,name,wcb=c)
  2866. #window_manager.top(name)
  2867. # =======================================================================
  2868. name="MASTER-WING"
  2869. args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220,"resize":0}
  2870. geo = libwin.split_window_position(pos_list,name)
  2871. if geo:
  2872. args.update(geo)
  2873. data=[]
  2874. for i in range(2):
  2875. data.append({"MASTER"+str(i):"MASTER"})
  2876. cls = GUI_MasterWingLayout #(w1,data)
  2877. cb_ok = None
  2878. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2879. window_manager.new(None,name,wcb=c)
  2880. if libwin.split_window_show(pos_list,_filter=name):
  2881. window_manager.top(name)
  2882. # =======================================================================
  2883. name="EXEC-WING"
  2884. args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
  2885. geo = libwin.split_window_position(pos_list,name)
  2886. if geo:
  2887. args.update(geo)
  2888. data=[]
  2889. for i in range(10*3):
  2890. data.append({"EXEC"+str(i):"EXEC"})
  2891. cls = GUI_ExecWingLayout
  2892. cb_ok = set_exec_fader_all
  2893. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2894. window_manager.new(None,name,wcb=c)
  2895. if libwin.split_window_show(pos_list,_filter=name):
  2896. window_manager.top(name)
  2897. # =======================================================================
  2898. name="ENCODER"
  2899. args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
  2900. geo = libwin.split_window_position(pos_list,name)
  2901. if geo:
  2902. args.update(geo)
  2903. cls = draw_enc #(master,w.tk)#Xroot)
  2904. cb_ok = None
  2905. data = FIXTURES #master
  2906. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2907. window_manager.new(None,name,wcb=c)
  2908. if libwin.split_window_show(pos_list,_filter=name):
  2909. window_manager.top(name)
  2910. # =======================================================================
  2911. name = "SETUP"
  2912. args = {"title":name +" SHOW:"+master.base.show_name,
  2913. "master":0,"width":445,"height":42,"left":L1+10+W1,"top":TOP,"resize":10}
  2914. args["title"] = "SETUP SHOW:"+master.base.show_name
  2915. geo = libwin.split_window_position(pos_list,name)
  2916. try:
  2917. geo["width"] = args["width"]
  2918. geo["height"] = args["height"]
  2919. except:pass
  2920. if geo:
  2921. args.update(geo)
  2922. cls = draw_setup #(master,w.tk)
  2923. data = []
  2924. cb_ok = None
  2925. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2926. window_manager.new(None,name,wcb=c)
  2927. if libwin.split_window_show(pos_list,_filter=name):
  2928. window_manager.top(name)
  2929. # =======================================================================
  2930. name = "COMMAND"
  2931. args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":10}
  2932. geo = libwin.split_window_position(pos_list,name)
  2933. if geo:
  2934. args.update(geo)
  2935. cls = draw_command #(master,w.tk)
  2936. data = []
  2937. cb_ok = None
  2938. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2939. window_manager.new(None,name,wcb=c)
  2940. if libwin.split_window_show(pos_list,_filter=name):
  2941. window_manager.top(name)
  2942. # =======================================================================
  2943. name = "LIVE"
  2944. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":10}
  2945. geo = libwin.split_window_position(pos_list,name)
  2946. if geo:
  2947. args.update(geo)
  2948. cls = draw_live #(master,w.tk)
  2949. data = []
  2950. cb_ok = None
  2951. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2952. window_manager.new(None,name,wcb=c)
  2953. if libwin.split_window_show(pos_list,_filter=name):
  2954. window_manager.top(name)
  2955. # =======================================================================
  2956. name = "CLOCK"
  2957. args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
  2958. geo = libwin.split_window_position(pos_list,name)
  2959. if geo:
  2960. args.update(geo)
  2961. cclock = X_CLOCK()
  2962. cls = cclock.draw_clock
  2963. data = []
  2964. cb_ok = None
  2965. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2966. window_manager.new(None,name,wcb=c)
  2967. if libwin.split_window_show(pos_list,_filter=name):
  2968. window_manager.top(name)
  2969. # =======================================================================
  2970. name="FX"
  2971. args = {"title":name,"master":0,"width":415,"height":297+30,"left":L1+10+W1,"top":TOP+302,"resize":1}
  2972. geo = libwin.split_window_position(pos_list,name)
  2973. if geo:
  2974. args.update(geo)
  2975. cls = draw_fx #(master,w.tk)
  2976. data = []
  2977. cb_ok = None
  2978. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  2979. window_manager.new(None,name,wcb=c)
  2980. if libwin.split_window_show(pos_list,_filter=name):
  2981. window_manager.top(name)
  2982. # =======================================================================
  2983. name="PATCH"
  2984. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP,"foot":1,"head":1}
  2985. geo = libwin.split_window_position(pos_list,name)
  2986. if geo:
  2987. args.update(geo)
  2988. cls = GUI_PATCH
  2989. data = FIXTURES
  2990. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  2991. window_manager.new(None,name,wcb=c) #,obj)
  2992. if libwin.split_window_show(pos_list,_filter=name):
  2993. window_manager.top(name)
  2994. # =======================================================================
  2995. name="COLORPICKER"
  2996. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  2997. geo = libwin.split_window_position(pos_list,name)
  2998. if geo:
  2999. args.update(geo)
  3000. #w = libtk.Window(args)
  3001. #draw_colorpicker(master,w.tk,FIXTURES,master)
  3002. cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
  3003. data = [FIXTURES,master]
  3004. cb_ok = None #FIXTURES
  3005. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3006. window_manager.new(None,name,wcb=c)
  3007. if libwin.split_window_show(pos_list,_filter=name):
  3008. window_manager.top(name)
  3009. # =======================================================================
  3010. name="TableA"
  3011. #w = libtk.Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3012. #space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
  3013. #x=TableFrame(root=w.tk)#,left=80,top=620)
  3014. #w.show()
  3015. #data =[]
  3016. #for a in range(40):
  3017. # data.append(["E","E{}".format(a+1)])
  3018. #x.draw(data=data,head=["E","C"],config=[12,5,5])
  3019. #w=x.bframe
  3020. #window_manager.new(w,name)
  3021. master.render()
  3022. window_manager.top("Table")
  3023. #w = frame_fix #Window("OLD",master=0,width=W1,height=500,left=130,top=TOP)
  3024. #window_manager.new(w,name)
  3025. #if "--easy" in sys.argv:
  3026. #load_window_position()
  3027. thread.start_new_thread(loops,())
  3028. mc_fix = MC_FIX()
  3029. def mc_fix_loop():
  3030. time.sleep(5)
  3031. while 1:
  3032. try:
  3033. #print(1)
  3034. data = FIXTURES.fixtures
  3035. mc_fix.set(index="fix",data=data)
  3036. except Exception as e:
  3037. print("MC_FIX EXCEPTION",e)
  3038. time.sleep(1/10)
  3039. thread.start_new_thread(mc_fix_loop,())
  3040. thread.start_new_thread(open_sdl_window,())
  3041. try:
  3042. window_manager.mainloop()
  3043. finally:
  3044. BASE_PATH = "/opt/LibreLight/Xdesk/"
  3045. movewin.process_kill(BASE_PATH+"tksdl/")
  3046. master.exit()