_LibreLightDesk.py 116 KB

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