_LibreLightDesk.py 157 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. This file is part of LibreLight.
  5. LibreLight is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, version 2 of the License.
  8. LibreLight is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with LibreLight. If not, see <http://www.gnu.org/licenses/>.
  14. (c) 2012 micha@librelight.de
  15. """
  16. import random
  17. import subprocess
  18. import string
  19. import copy
  20. import traceback
  21. rnd_id = str(random.randint(100,900))
  22. rnd_id += " beta"
  23. rnd_id2 = ""
  24. rnd_id3 = ""
  25. _ENCODER_WINDOW = None
  26. try:
  27. _gcmd=['git','log','-1', '--format=%ci']
  28. r = subprocess.check_output(_gcmd)
  29. rnd_id3 += " " + r.decode('ascii').strip().split()[0]
  30. except:pass
  31. rnd_id += rnd_id3
  32. _gcmd=['git', 'rev-parse', '--short', 'HEAD']
  33. try:
  34. r = subprocess.check_output(_gcmd)
  35. rnd_id2 += " "+r.decode('ascii').strip()
  36. except Exception as e:
  37. rnd_id2 += " no git"
  38. #rnd_id += " ".join(_gcmd) +str(e)
  39. rnd_id += rnd_id2
  40. try:
  41. xtitle = __file__
  42. except:
  43. xtitle = "__file__"
  44. if "/" in xtitle:
  45. xtitle = xtitle.split("/")[-1]
  46. import sys
  47. sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title
  48. import json
  49. import time
  50. import sys
  51. import os
  52. HOME = os.getenv('HOME')
  53. import _thread as thread
  54. import traceback
  55. import tkinter
  56. import tkinter as tk
  57. from tkinter import font
  58. space_font = None
  59. import tkinter.simpledialog
  60. from idlelib.tooltip import Hovertip
  61. INIT_OK = 0
  62. _global_short_key = 1
  63. icolor = 1
  64. def cprint(*text,color="blue",space=" ",end="\n"):
  65. #return 0 #disable print dbg
  66. if not color:
  67. print(text)
  68. return 0
  69. if color == "green":
  70. txt = '\033[92m'
  71. elif color == "red":
  72. txt = '\033[0;31m\033[1m'
  73. elif color == "yellow":
  74. txt = '\033[93m\033[1m'
  75. elif color == "cyan":
  76. txt = '\033[96m'
  77. else:
  78. txt = '\033[94m'
  79. for t in text:
  80. txt += str(t ) +" "
  81. #HEADER = '\033[95m'
  82. #OKBLUE = '\033[94m'
  83. #OKCYAN = '\033[96m'
  84. #OKGREEN = '\033[92m'
  85. #WARNING = '\033[93m'
  86. #FAIL = '\033[91m'
  87. #ENDC = '\033[0m'
  88. #BOLD = '\033[1m'
  89. #UNDERLINE = '\033[4m'
  90. txt += '\033[0m'
  91. print(txt,end=end)
  92. #return txt
  93. sys.stdout.flush() # to grep output
  94. cprint("________________________________")
  95. import lib.zchat as chat
  96. import lib.motion as motion
  97. from collections import OrderedDict
  98. _POS_LEFT = 0
  99. _POS_TOP = 15
  100. _config = []
  101. try:
  102. h = os.environ["HOME"]
  103. lines = [{}]
  104. try:
  105. f = open(h +"/LibreLight/config.json")
  106. lines = f.readlines()
  107. except FileNotFoundError as e: #Exception as e:
  108. f = open(h +"/LibreLight/config.json","w")
  109. f.write('{"POS_TOP":0}\n{"POS_LEFT":0}')
  110. f.close()
  111. cprint("Exception:",e)
  112. cprint("config read")
  113. for line in lines:
  114. line=line.strip()
  115. cprint("- config:",line)
  116. row = json.loads(line)
  117. _config.append(row)
  118. except Exception as e:
  119. cprint("Exception:",e)
  120. try:
  121. for row in _config:
  122. cprint("config:",row)
  123. if "POS_LEFT" in row:
  124. _POS_LEFT = int(row["POS_LEFT"])
  125. if "POS_TOP" in row:
  126. _POS_TOP = int(row["POS_TOP"])
  127. except Exception as e:
  128. cprint("Exception:",e)
  129. def showwarning(msg="<ERROR>",title="<TITLE>"):
  130. _main = tkinter.Tk()
  131. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  132. cprint("showwarning",defaultFont)
  133. defaultFont.configure(family="FreeSans",
  134. size=10,
  135. weight="normal")
  136. geo ="{}x{}".format(20,20)
  137. _main.geometry(geo)
  138. def _quit():
  139. time.sleep(.02)
  140. _main.quit()
  141. thread.start_new_thread(_main.mainloop,())
  142. #_main.quit()
  143. #msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  144. #msg += "please check\n"
  145. #msg += "-{}init.txt\n".format(self.show_path0)
  146. #msg += "-{}".format(self.show_path1)
  147. r=tkinter.messagebox.showwarning(message=msg,title=title,parent=None)
  148. CUES = OrderedDict()
  149. groups = OrderedDict()
  150. class Modes():
  151. def __init__(self):
  152. self.modes = {}
  153. self.__cfg = {}
  154. self.__cb = None
  155. def val(self,mode,value=None): #like jquery
  156. if value is not None:
  157. return self.set(mode,value)
  158. elif mode in self.modes:
  159. return self.modes[mode]
  160. def get(self,mode,value=None):
  161. return self.val(mode,value)
  162. def __check(self,mode):
  163. if mode not in self.modes:
  164. self.modes[mode] = 0
  165. self.__cfg[mode] = 0
  166. def cfg(self,mode,data={}):
  167. self.__check(mode)
  168. if type(data) is dict:
  169. for k in data:
  170. v = data[k]
  171. if v not in self.__cfg:
  172. self.__cfg[k] = v
  173. return 1
  174. elif type(data) is str:
  175. if data in self.__cfg:
  176. return self.__cfg[data]
  177. def set(self,mode,value):
  178. protected = ["BLIND","CLEAR","REC-FX"]
  179. self.__check(mode)
  180. if mode == "CLEAR":
  181. return 1
  182. elif mode == "ESC":
  183. for m in self.modes:
  184. cprint("ESC",m)
  185. if m == "COPY":
  186. PRESETS.clear_copy()
  187. if m == "MOVE":
  188. PRESETS.clear_move()
  189. if m != "BLIND":
  190. self.modes[m] = 0
  191. self.callback(m)
  192. return 1
  193. if value:
  194. for m in self.modes:
  195. if m not in protected and mode not in protected and m != mode:
  196. #cprint("-#-# clear mode",mode,m,value,color="red")
  197. if self.modes[m]:
  198. self.modes[m]= 0
  199. self.callback(m)
  200. if self.modes[mode] and value == 1:
  201. if modes == "MOVE":
  202. PRESETS.clear_move()
  203. if modes == "COPY":
  204. PRESETS.clear_copy()
  205. self.modes[mode] = 0 # value
  206. else:
  207. self.modes[mode] = value #1 #value
  208. else:
  209. self.modes[mode] = 0 #value
  210. if modes == "COPY":
  211. PRESETS.clear_copy()
  212. if modes == "MOVE":
  213. PRESETS.clear_move()
  214. self.callback(mode)
  215. return value
  216. def set_cb(self,cb):
  217. if cb:
  218. self.__cb = cb
  219. def callback(self,mode):
  220. if self.__cb is not None and mode in self.modes:
  221. value = self.modes[mode]
  222. self.__cb(mode=mode,value=value)
  223. modes = Modes()
  224. #modes.val("BLIND", 0)
  225. #modes.modes["BLIND"] = 0
  226. modes.modes["ESC"] = 0
  227. modes.modes["REC"] = 0
  228. modes.modes["EDIT"] = 0
  229. modes.modes["MOVE"] = 0
  230. modes.modes["FLASH"] = 0
  231. modes.modes["GO"] = 0
  232. modes.modes["DEL"] = 0
  233. modes.modes["REC-FX"] = 0
  234. modes.modes["SELECT"] = 0
  235. modes.modes["CFG-BTN"] = 0
  236. modes.modes["LABEL"] = 0
  237. def xcb(mode,value=None):
  238. cprint("xcb","MODE CALLBACK",mode,value)
  239. if mode == "REC-FX":
  240. cprint("xcb",modes.val("REC-FX"))
  241. #modes.set_cb(xcb)
  242. POS = ["PAN","TILT","MOTION"]
  243. COLOR = ["RED","GREEN","BLUE","COLOR"]
  244. BEAM = ["GOBO","G-ROT","PRISMA","P-ROT","FOCUS","SPEED"]
  245. INT = ["DIM","SHUTTER","STROBE","FUNC"]
  246. #client = chat.tcp_sender(port=50001)
  247. def set_exec_fader(nr,val,color=""):
  248. exec_wing = window_manager.get_obj(name="EXEC-WING")
  249. if not exec_wing:
  250. return
  251. #print(exec_wing)
  252. try:
  253. exec_wing.set_fader(nr,val,color=color)
  254. except Exception as e:
  255. cprint("- exception:",e)
  256. #print("remote in:",round(time.time(),0),"x",i,v)
  257. def set_exec_fader_all():
  258. cprint( "set_exec_fader_all()",color="green")
  259. for nr in range(10):
  260. set_exec_fader(nr,0) #,color="#fff")
  261. # remote input - start (memcached)
  262. def JCB(x,sock=None):
  263. for i in x:
  264. jv = x[i]
  265. try:
  266. jv = json.loads(jv)
  267. jv = jv[0]
  268. #print(jv)
  269. v = jv["iVAL"]
  270. #exec_wing.set_fader(0,v)
  271. set_exec_fader(0,v)
  272. set_exec_fader(1,200-v)
  273. set_exec_fader(2,int(v/2+10))
  274. except Exception as e:
  275. cprint("exception",e)
  276. print(sys.exc_info()[2])
  277. #print("remote in:",round(time.time(),0),"x",i,v)
  278. r1_server = chat.Server(port=30002)
  279. def server1_loop():
  280. while 1:
  281. r1_server.poll(cb=JCB)
  282. time.sleep(0.01)
  283. thread.start_new_thread(server1_loop,()) # SERVER
  284. # remote input - end
  285. def JSCB(x,sock=None):
  286. i = ""
  287. msg = ""
  288. try:
  289. for i in x:
  290. #print("i",[i])
  291. msg = json.loads(i)
  292. print("JSCB",i,msg,sock)
  293. if sock:
  294. msg = json.dumps(msg)
  295. msg = bytes(msg,"utf8")
  296. chat._send(sock,msg)
  297. except Exception as e:
  298. cprint("exception JSCB:",e)
  299. cprint("- i:",i)
  300. cprint("- msg:",msg)
  301. cprint(traceback.format_exc(),color="red")
  302. if sock:
  303. msg = ["Notice: Exception on JSCB-SERVER: ",str(e)]
  304. msg = json.dumps(msg)
  305. msg = bytes(msg,"utf8")
  306. chat._send(sock,msg)
  307. # external GUI
  308. r_server = chat.Server(port=30003,cb=JSCB)
  309. def server_loop():
  310. while 1:
  311. r_server.poll(cb=JSCB)
  312. time.sleep(0.001)
  313. thread.start_new_thread(server_loop,()) # SERVER
  314. # read memcachd
  315. memcache = None
  316. try:
  317. import memcache
  318. except Exception as e:
  319. cprint("Exception IMPORT ERROR",e)
  320. class MC():
  321. def __init__(self,server="127.0.0.1",port=11211):
  322. cprint("MC.init() ----------" ,server,port,color="red")
  323. try:
  324. #self.mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  325. self.mc = memcache.Client(['{}:{}'.format(server,port)], debug=0)
  326. #self.init()
  327. except Exception as e:
  328. cprint("-- Exception",e)
  329. # def init(self):
  330. data = {}
  331. start = time.time()
  332. delta = start
  333. index = self.mc.get("index")
  334. if index:
  335. for i in index:
  336. cprint("-- key",i)
  337. self.fader_map = []
  338. for i in range(30+1):
  339. self.fader_map.append({"UNIV":0,"DMX":0})
  340. try:
  341. fname = HOME + "/LibreLight/fader.json"
  342. f = open(fname)
  343. lines = f.readlines()
  344. cprint("FADER MAP",fname)
  345. for i,line in enumerate(lines):
  346. jdata = json.loads(line)
  347. cprint("-- fader_map ->>",i,jdata)
  348. self.fader_map[i] = jdata
  349. except Exception as e:
  350. cprint("-- Except Fader_map",e)
  351. #exit()
  352. def ok(self):
  353. if self.mc:
  354. return 1
  355. return 0
  356. def test(self):
  357. if not self.ok():
  358. return
  359. self.mc.set("some_key", "Some value")
  360. self.value = mc.get("some_key")
  361. self.mc.set("another_key", 3)
  362. self.mc.delete("another_key")
  363. def loop(self):
  364. thread.start_new_thread(self._loop,())
  365. if not self.ok():
  366. return
  367. def _loop(self):
  368. cprint("++++++++++ start.memcachd read loop",self )
  369. while 1:
  370. send = 0
  371. #print("+")
  372. try:
  373. ip="10.10.10.13:0"
  374. #ip="ltp-out:0"
  375. #print(ip)
  376. x=self.mc.get(ip)
  377. if x:
  378. #print(ip,x)
  379. #val = x[501-1]
  380. #val = x[141-1]
  381. for i, line in enumerate(self.fader_map):
  382. try:
  383. #print(i,line)
  384. dmx = int(line["DMX"])
  385. if dmx > 0:
  386. val = x[dmx-1]
  387. #print("mc val",val)
  388. set_exec_fader(i,val,color="#aaa")
  389. except:pass
  390. time.sleep(0.01)
  391. except Exception as e:
  392. cprint("exc", e)
  393. time.sleep(1)
  394. _mc=MC()
  395. _mc.loop()
  396. console = chat.Client() #port=50001)
  397. def jclient_send(data):
  398. t_start = time.time()
  399. jtxt = data
  400. jdatas = []
  401. for jdata in data:
  402. if "CMD" in jdata:
  403. try:
  404. jdatas.append(jdata)
  405. except Exception as e:
  406. cprint("jclient_send, Exception DMX ",color="red")
  407. cprint("",jdata,color="red")
  408. cprint("-----",color="red")
  409. elif "DMX" in jdata:
  410. #print(jdata)
  411. try:
  412. dmx = int(jdata["DMX"])
  413. if int(dmx) >= 1: # ignore DMX lower one
  414. if "ATTR" not in jdata:
  415. # for fx off
  416. jdatas.append(jdata)
  417. else: # with "ATTR"
  418. if "FIX" in jdata:
  419. fix = jdata["FIX"]
  420. attr = jdata["ATTR"]
  421. # find dmx-fine channel
  422. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  423. if jdata["ATTR"].startswith("_"):
  424. # ignore attr "_"
  425. # bug with "S" attr._ACTIVE breaks preset_go
  426. pass
  427. else:
  428. jdatas.append(jdata)
  429. else:
  430. cprint("jclient_send, ignore DMX ",color="red")
  431. cprint("-- ",jdata,color="red")
  432. except Exception as e:
  433. cprint("jclient_send, Exception DMX ",color="red")
  434. cprint("",jdata,color="red")
  435. cprint(e,color="red")
  436. cprint("-----",color="red")
  437. jtxt = jdatas
  438. jtxt = json.dumps(jtxt)
  439. jtxt = jtxt.encode()
  440. console.send( jtxt ) #b"\00 ")
  441. cprint("{:0.04} sec.".format(time.time()-t_start),color="yellow")
  442. cprint("{:0.04} tick".format(time.time()),color="yellow")
  443. def _highlight(fix,_attr="DIM"):
  444. " patch test button "
  445. cprint("highlight",fix,"1")
  446. if fix not in FIXTURES.fixtures:
  447. return None
  448. d = FIXTURES.fixtures[fix]
  449. #for k,v in d.items():
  450. # cprint("-",k,v)
  451. DMX = d["DMX"] + d["UNIVERS"]*512
  452. if "ATTRIBUT" in d:
  453. ATTR= d["ATTRIBUT"]
  454. data = {"VALUE":200,"DMX":1}
  455. attr = ""
  456. if _attr in ATTR:
  457. attr = _attr
  458. else:
  459. return #stop
  460. cprint(attr,ATTR[attr])
  461. old_val = ATTR[attr]["VALUE"]
  462. data["DMX"] = DMX + ATTR[attr]["NR"]-1
  463. cprint(attr,ATTR[attr])
  464. cprint(data)
  465. for i in range(3):
  466. cprint("highlight",fix,"0")
  467. data["VALUE"] = 100
  468. jclient_send([data])
  469. time.sleep(0.1)
  470. cprint("highlight",fix,"1")
  471. data["VALUE"] = 234
  472. jclient_send([data])
  473. time.sleep(0.3)
  474. cprint("highlight",fix,"0")
  475. data["VALUE"] = old_val
  476. jclient_send([data])
  477. def highlight2(fix,attr="DIM"):
  478. def x():
  479. highlight(fix,attr=attr)
  480. return x
  481. def highlight(fix):
  482. cprint("highlight",fix)
  483. thread.start_new_thread(_highlight,(fix,"DIM"))
  484. thread.start_new_thread(_highlight,(fix,"RED"))
  485. thread.start_new_thread(_highlight,(fix,"GREEN"))
  486. thread.start_new_thread(_highlight,(fix,"BLUE"))
  487. class ValueBuffer():
  488. def __init__(self,_min=0,_max=255):
  489. self._value = 2
  490. self._on = 1
  491. self._min=_min
  492. self._max=_max
  493. def check(self):
  494. if self._value < self._min:
  495. self._value = self._min
  496. elif self._value > self._max:
  497. self._value = self._max
  498. def inc(self,value=None):
  499. if value is not None:
  500. if type(value) is float:
  501. self._value += round(value,4)
  502. else:
  503. self._value += value
  504. self.check()
  505. return self._value
  506. def val(self,value=None):
  507. if value is not None:
  508. if type(value) is float:
  509. self._value = round(value,4)
  510. else:
  511. self._value = value
  512. self.check()
  513. return self._value
  514. def on(self):
  515. self._on = 1
  516. def off(self):
  517. self._on = 0
  518. def _is(self):
  519. if self._on:
  520. return 1
  521. return 0
  522. FADE = ValueBuffer() #2 #0.1 #1.13
  523. FADE.val(2.0)
  524. FADE_move = ValueBuffer() #2 #0.1 #1.13
  525. FADE_move.val(4.0)
  526. DELAY = ValueBuffer() #2 #0.1 #1.13
  527. DELAY.off()
  528. DELAY.val(0.2)
  529. 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}
  530. 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,"FX-X":1,"FX:MODE":0}
  531. fx_x_modes = ["spiral","left","right","up","down","left_right","up_down"]
  532. fx_modes = ["RED","GREEN","BLUE","MAG","YELLOW","CYAN"]
  533. fx_mo = ["fade","on","rnd","ramp","ramp2","cosinus","sinus"]
  534. class FX_handler():
  535. def __init__():
  536. pass
  537. def reshape_preset(data ,value=None,xfade=0,flash=0,ptfade=0):
  538. f=0 #fade
  539. out = []
  540. delay=0
  541. for row in data:
  542. #cprint("reshape_preset in:",row)
  543. line = {}
  544. line["DELAY"]=delay
  545. if type(value) is float:
  546. line["VALUE"] = value #round(value,3)
  547. else:
  548. line["VALUE"] = value
  549. if value is not None:
  550. line["FX"] = row["FX"].split(":",1)[-1]
  551. else:
  552. line["FX"] = row["FX"]
  553. if row["FX2"]:
  554. line["FX2"] = row["FX2"]
  555. if row["FIX"]:
  556. line["FIX"] = row["FIX"]
  557. if row["ATTR"]:
  558. line["ATTR"] = row["ATTR"]
  559. if row["VALUE"] is not None:
  560. if value is None:
  561. v=row["VALUE"]
  562. if type(v) is float:
  563. line["VALUE"] = v #round(v,3)
  564. else:
  565. line["VALUE"] = v
  566. if row["ATTR"] in ["PAN","TILT"]:
  567. f = ptfade
  568. for a in ["DIM","ZOOM","FOCUS","RED","GREEN","BLUE","WHITE","AMBER","IRIS","BLADE"]:
  569. #FADE ATTRIBUTES
  570. if a in row["ATTR"]:
  571. f = xfade
  572. break
  573. if flash:
  574. xfade = 0
  575. if type( f ) is float:
  576. line["FADE"] = round(f,4)
  577. else:
  578. line["FADE"] = f
  579. if 0:
  580. cprint("reshape_preset j",line,color="red")
  581. #cprint("reshape_preset out:",line)
  582. out.append(line)
  583. if DELAY._is():
  584. delay+=DELAY.val()/100 #0.02
  585. return out
  586. class dummy_event():
  587. def __init__(self):
  588. self.num =0
  589. self.type = 4 #press 5 release
  590. self.set_value=-1
  591. def process_wings(xfixtures):
  592. """process the wing's of selected fixtures
  593. input: [1,2,3,4,10,12,13,14]
  594. if WING = 2 return: [[1,2,3,4][14,13,12,10]]
  595. """
  596. wing_buffer = []
  597. fix_count = len(xfixtures)
  598. prm = fx_prm # ToDo: global WING for PAN/TILE !? ATTRIBUT is not availible in this moment
  599. if prm["WING"] > 1 and fix_count > 1:
  600. wing_count = fix_count // prm["WING"]
  601. number_of_fix_in_wing = fix_count // wing_count
  602. if number_of_fix_in_wing < 2:
  603. number_of_fix_in_wing = 2
  604. for i in range(number_of_fix_in_wing):
  605. j = i*wing_count
  606. wing = xfixtures[j:j+wing_count]
  607. if i%2!=0:
  608. wing = wing[::-1]
  609. cprint("wing",i,"j",j,"wing_count:",wing_count,"wing",wing)
  610. wing_buffer.append(wing)
  611. if fix_count > j+wing_count: # append Fixtures Left over
  612. wing = xfixtures[j+wing_count:]
  613. wing_buffer.append(wing)
  614. else:
  615. wing_buffer.append(xfixtures)
  616. if prm["SHUFFLE"]:
  617. _wing_buffer = []
  618. for wing in wing_buffer:
  619. wing = wing[:]
  620. random.shuffle(wing)
  621. _wing_buffer.append(wing)
  622. wing_buffer = _wing_buffer
  623. return wing_buffer
  624. def process_effect(wing_buffer,fx_name=""):
  625. jdatas = []
  626. offset = 0
  627. offset_move = 0
  628. start = fx_prm["START"]
  629. base = fx_prm["BASE"]
  630. for wing in wing_buffer:
  631. count_of_fix_in_wing = len(wing)
  632. coffset= 0 # 1024/count_of_fix_in_wing * (offset/255)
  633. coffset_move=0
  634. for fix in wing:
  635. if fix not in FIXTURES.fixtures:
  636. continue
  637. data = FIXTURES.fixtures[fix]
  638. for attr in data["ATTRIBUT"]:
  639. if attr.startswith("_"):
  640. continue
  641. jdata = {"MODE":"FX"}
  642. jdata["VALUE"] = None
  643. jdata["FIX"] = fix
  644. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  645. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  646. jdata["ATTR"] =attr
  647. if attr.endswith("-FINE"):
  648. continue
  649. if attr in ["PAN","TILT"]:
  650. csize = fx_prm_move["SIZE"]
  651. cspeed = fx_prm_move["SPEED"]
  652. cstart = fx_prm_move["START"]
  653. cbase = fx_prm_move["BASE"]
  654. width = fx_prm_move["WIDTH"]
  655. invert = fx_prm_move["INVERT"]
  656. coffset_move= round(offset_move,1)
  657. else:
  658. csize = fx_prm["SIZE"]
  659. cspeed = fx_prm["SPEED"]
  660. cstart = fx_prm["START"]
  661. cbase = fx_prm["BASE"]
  662. width = fx_prm["WIDTH"]
  663. invert = fx_prm["INVERT"]
  664. coffset= round(offset,1)
  665. fx=""
  666. if "SIN" in fx_name:
  667. fx = "sinus"
  668. elif "FD" in fx_name:
  669. fx = "fade"
  670. elif "RND" in fx_name:
  671. fx = "rnd"
  672. elif "ON" in fx_name:
  673. fx = "on"
  674. elif "RAMP2" in fx_name:
  675. fx = "bump2"
  676. fx = "ramp2"
  677. elif "RAMP" in fx_name:
  678. fx = "ramp"
  679. elif "COS" in fx_name:
  680. fx = "cosinus"
  681. if fx:
  682. if attr in ["PAN","TILT"]:
  683. cprint("SKIP FX attr:{} fix:{} " .format(attr,fix) )
  684. continue
  685. if fx:
  686. if fx_prm["SPEED"] < 0:
  687. fx = "off"
  688. else:
  689. if ":DIM" in fx_name:
  690. base=""
  691. ffxb=fx_mo[fx_prm["MO"]]
  692. #ffxb= "cosinus"
  693. if attr == "DIM":
  694. if fx_prm["SPEED"] < 0:
  695. fx = "off"
  696. else:
  697. fx = ffxb #"fade"
  698. elif ":TILT" in fx_name:
  699. base=""
  700. if attr == "PAN":
  701. fx = "off"
  702. if attr == "TILT":
  703. if fx_prm["SPEED"] < 0:
  704. fx = "off"
  705. else:
  706. fx = "sinus"
  707. elif ":PAN" in fx_name:
  708. base=""
  709. if attr == "PAN":
  710. if fx_prm_move["SPEED"] < 0:
  711. fx = "off"
  712. else:
  713. fx = "cosinus"
  714. if attr == "TILT":
  715. fx = "off"
  716. elif ":CIR" in fx_name:
  717. base=""
  718. if attr == "PAN":
  719. if fx_prm_move["SPEED"] < 0:
  720. fx = "off"
  721. else:
  722. fx = "cosinus"
  723. if attr == "TILT":
  724. if fx_prm["SPEED"] < 0:
  725. fx = "off"
  726. else:
  727. fx = "sinus"
  728. elif ":RED" in fx_name:
  729. ffxb= fx_mo[fx_prm["MO"]]
  730. ffx= "off" #fx_mo[fx_prm["MO"]]
  731. if "RED" in fx_modes[fx_prm["MODE"]]:#
  732. base="-"
  733. if attr == "RED":
  734. fx=ffx
  735. if attr == "GREEN":
  736. fx = ffxb# "off"
  737. if attr == "BLUE":
  738. fx = ffxb#"off"
  739. elif "GREEN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#in fx_name:
  740. base="-"
  741. if attr == "RED":
  742. fx = ffxb#"off"
  743. elif "GREEN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#in fx_name:
  744. if attr == "GREEN":
  745. fx = ffxb# "off"
  746. fx=ffx
  747. if attr == "BLUE":
  748. fx = ffxb#"off"
  749. elif "BLUE" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  750. base="-"
  751. if attr == "RED":
  752. fx = ffxb# "off"
  753. if attr == "GREEN":
  754. fx = ffxb# "off"
  755. if attr == "BLUE":
  756. fx = ffxb# "off"
  757. fx=ffx
  758. elif "YELLOW" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  759. base="-"
  760. if attr == "RED":
  761. fx = ffxb# "off"
  762. fx=ffx
  763. if attr == "GREEN":
  764. fx = ffxb# "off"
  765. fx=ffx
  766. if attr == "BLUE":
  767. fx = "off"
  768. elif "CYAN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  769. base="-"
  770. if attr == "RED":
  771. fx = ffxb# "off"
  772. if attr == "GREEN":
  773. fx = ffxb# "off"
  774. fx=ffx
  775. if attr == "BLUE":
  776. fx = ffxb# "off"
  777. fx=ffx
  778. elif "MAG" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  779. base="-"
  780. if attr == "RED":
  781. fx = ffxb# "off"
  782. fx=ffx
  783. if attr == "GREEN":
  784. fx = ffxb# "off"
  785. if attr == "BLUE":
  786. fx = ffxb# "off"
  787. fx=ffx
  788. else:
  789. cprint("FX: unbekant",fx_modes[fx_prm["MODE"]],color="red")
  790. fxtype = fx
  791. fxtype = fx
  792. if "FX" not in data["ATTRIBUT"][attr]:
  793. data["ATTRIBUT"][attr]["FX"] =""
  794. if "FX2" not in data["ATTRIBUT"][attr]:
  795. data["ATTRIBUT"][attr]["FX2"] ={}
  796. if data["ATTRIBUT"][attr]["ACTIVE"] and fxtype:
  797. #print("++ADD FX",fix,attr,fx)
  798. #data["ATTRIBUT"][attr]["FX"] = fx #"sinus:40:100:10"
  799. fjdata = {}
  800. if cspeed < 0.1:
  801. fjdata["TYPE"] = "off"
  802. else:
  803. fjdata["TYPE"] = fxtype
  804. fjdata["SIZE"] = round(csize,2)
  805. fjdata["SPEED"] = round(cspeed,2)
  806. fjdata["WIDTH"] = int(width)
  807. fjdata["START"] = cstart
  808. if attr in ["PAN","TILT"]:
  809. fjdata["OFFSET"]= round(coffset_move,2)
  810. else:
  811. fjdata["OFFSET"]= round(coffset,2)
  812. fjdata["INVERT"]= int(invert)
  813. fjdata["BASE"] = cbase
  814. jdata["FX2"] = fjdata
  815. data["ATTRIBUT"][attr]["FX2"] = fjdata
  816. jdatas.append(jdata)
  817. if fx_prm_move["OFFSET"] > 0.5: # and
  818. aoffset_move = (100/count_of_fix_in_wing) * (fx_prm_move["OFFSET"]/100)
  819. if fx_prm_move["DIR"] <= 0:
  820. offset_move -= aoffset_move
  821. else:
  822. offset_move += aoffset_move
  823. offset_move = round(offset_move,2)
  824. if fx_prm["OFFSET"] > 0.5: # and
  825. aoffset = (100/count_of_fix_in_wing) * (fx_prm["OFFSET"]/100)
  826. if fx_prm["DIR"] <= 0:
  827. offset -= aoffset
  828. else:
  829. offset += aoffset
  830. offset = round(offset,2)
  831. if jdatas and not modes.val("BLIND"):
  832. jclient_send(jdatas)
  833. master._refresh_fix()
  834. return jdatas
  835. def process_matrix(xfixtures):
  836. fix_count = len(xfixtures)
  837. fx_x = fx_prm["FX-X"]
  838. fx_mod = fx_x_modes[fx_prm["FX:MODE"]]
  839. cprint("----",fx_x,fx_mod)
  840. if fx_x > 1 and fix_count > fx_x:
  841. try:
  842. from lib import matrix
  843. w=fx_x
  844. h=int(fix_count/fx_x)
  845. if fx_mod == "spiral":
  846. _map = matrix.spiral(w,h)
  847. elif fx_mod == "up_down":
  848. _map = matrix.up_down(w,h)
  849. elif fx_mod == "left_right":
  850. _map = matrix.left_right(w,h)
  851. elif fx_mod == "left":
  852. _map = matrix.left(w,h)
  853. elif fx_mod == "right":
  854. _map = matrix.right(w,h)
  855. elif fx_mod == "up":
  856. _map = matrix.up(w,h)
  857. elif fx_mod == "down":
  858. _map = matrix.down(w,h)
  859. else:
  860. return xfixtures # do nothing
  861. matrix.mprint(xfixtures,w,h)
  862. out = ["0"]*(w*h)
  863. for i,f in enumerate(xfixtures):
  864. if i < w*h:
  865. j = int(_map[i])
  866. cprint([i,f,j])
  867. out[j] = f
  868. matrix.mprint(out,w,h)
  869. xfixtures = out
  870. except Exception as e:
  871. cprint("matrix exception",e)
  872. return xfixtures
  873. class Xevent_fx():
  874. """ global input event Handeler for short cut's ... etc
  875. """
  876. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  877. self.fix = fix
  878. self.data = data
  879. self.attr = attr
  880. self.elem = elem
  881. self.mode = mode
  882. def fx(self,event):
  883. cprint("Xevent.fx",self.attr,self.fix,event)
  884. fx2 = {}
  885. if event.num == 4:
  886. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  887. txt = "FX:RED"
  888. fx_prm["MODE"] += 1
  889. if fx_prm["MODE"] >= len(fx_modes):
  890. fx_prm["MODE"]=0
  891. txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
  892. master.fx.elem["FX:RED"]["text"] = txt
  893. elif event.num == 5:
  894. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  895. txt = "FX:RED"
  896. fx_prm["MODE"] -= 1
  897. if fx_prm["MODE"] < 0:
  898. fx_prm["MODE"]= len(fx_modes)-1
  899. txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
  900. master.fx.elem["FX:RED"]["text"] = txt
  901. if event.num == 4:
  902. cprint("FX-X: CHANGE",fx_prm,color="red")
  903. txt = "FX-X:"
  904. fx_prm["FX:MODE"] += 1
  905. if fx_prm["FX:MODE"] >= len(fx_x_modes):
  906. fx_prm["FX:MODE"]=0
  907. txt = "FX:MODE\n"+fx_x_modes[fx_prm["FX:MODE"]]
  908. master.fx.elem["FX:MODE"]["text"] = txt
  909. elif event.num == 5:
  910. cprint("FX-X: CHANGE",fx_prm,color="red")
  911. txt = "FX-X:"
  912. fx_prm["FX:MODE"] -= 1
  913. if fx_prm["FX:MODE"] < 0:
  914. fx_prm["FX:MODE"]= len(fx_x_modes)-1
  915. txt = "FX:MODE\n"+fx_x_modes[fx_prm["FX:MODE"]]
  916. master.fx.elem["FX:MODE"]["text"] = txt
  917. elif event.num == 1:
  918. xfixtures = []
  919. fix_active =FIXTURES.get_active()
  920. for fix in fix_active:
  921. if fix == "CFG":
  922. continue
  923. xfixtures.append(fix)
  924. if not xfixtures:
  925. cprint("470 fx() ... init no fixture selected",color="red")
  926. return 0
  927. xfixtures = process_matrix(xfixtures)
  928. wing_buffer = process_wings(xfixtures)
  929. process_effect(wing_buffer,fx_name=self.attr)
  930. def command(self,event,mode=""):
  931. cprint("fx_command",self.mode)
  932. if self.mode == "FX":
  933. prm = fx_prm
  934. ct = self.data.fx
  935. if self.mode == "FX-MOVE":
  936. prm = fx_prm_move
  937. ct = self.data.fx_moves
  938. if 1:
  939. if self.attr.startswith("SIZE:"):#SIN":
  940. #global fx_prm
  941. k = "SIZE"
  942. if event.num == 1:
  943. prm[k] =30
  944. elif event.num == 3:
  945. prm[k] =100
  946. elif event.num == 4:
  947. if prm[k] <= 0:
  948. prm[k] = 1
  949. prm[k] +=5
  950. elif event.num == 5:
  951. prm[k] -=5
  952. #prm[k] =int(prm[k])
  953. if prm[k] > 4000:
  954. prm[k] = 4000
  955. if prm[k] < 0:
  956. prm[k] =0
  957. if prm[k] == 6: #bug
  958. prm[k] =5
  959. ct.elem[self.attr]["text"] = "SIZE:\n{:0.0f}".format(prm[k])
  960. cprint(prm)
  961. elif self.attr.startswith("SPEED:"):#SIN":
  962. #global prm
  963. k = "SPEED"
  964. if event.num == 1:
  965. prm[k] = 6
  966. elif event.num == 3:
  967. prm[k] = 60
  968. elif event.num == 4:
  969. if prm[k] <= 0:
  970. prm[k] = 0.06
  971. elif prm[k] < 5:
  972. prm[k] *=1.2
  973. else:
  974. prm[k] +=5 #1.1
  975. elif event.num == 5:
  976. if prm[k] <= 5:
  977. prm[k] *=0.8
  978. else:
  979. prm[k] -= 5 #1.1
  980. #prm[k] =int(prm[k])
  981. if prm[k] > 4000:
  982. prm[k] = 4000
  983. if prm[k] < 0.05:
  984. prm[k] =0
  985. if prm[k] > 5 and prm[k] < 10: #bug
  986. prm[k] =5
  987. if prm[k] < 0:
  988. ct.elem[self.attr]["text"] = "SPEED:\noff".format(prm[k])
  989. else:
  990. ct.elem[self.attr]["text"] = "SPEED:\n{:0.02f}".format(prm[k])
  991. cprint(prm)
  992. elif self.attr.startswith("START:"):#SIN":
  993. #global prm
  994. k = "START"
  995. if event.num == 1:
  996. pass
  997. elif event.num == 2:
  998. pass
  999. elif event.num == 4:
  1000. if prm[k] <= 0:
  1001. prm[k] = 1
  1002. prm[k] += 5 #1.1
  1003. elif event.num == 5:
  1004. prm[k] -= 5 #1.1
  1005. #prm[k] =int(prm[k])
  1006. if prm[k] > 4000:
  1007. prm[k] = 4000
  1008. if prm[k] < 5:
  1009. prm[k] =0
  1010. if prm[k] == 6: #bug
  1011. prm[k] =5
  1012. ct.elem[self.attr]["text"] = "START:\n{:0.0f}".format(prm[k])
  1013. cprint(prm)
  1014. elif self.attr.startswith("WIDTH:"):#SIN":
  1015. #global prm
  1016. k = "WIDTH"
  1017. if event.num == 1:
  1018. prm[k] = 25
  1019. elif event.num == 2:
  1020. prm[k] = 50
  1021. elif event.num == 3:
  1022. prm[k] = 100
  1023. elif event.num == 4:
  1024. if prm[k] <= 0:
  1025. prm[k] = 1
  1026. elif prm[k] == 50:
  1027. prm[k] = 100
  1028. elif prm[k] == 5:
  1029. prm[k] = 25
  1030. elif prm[k] == 25:
  1031. prm[k] = 50
  1032. else:
  1033. prm[k] += 5 #*=1.1
  1034. elif event.num == 5:
  1035. if prm[k] == 10:
  1036. prm[k] = 5
  1037. elif prm[k] == 25:
  1038. prm[k] = 10
  1039. elif prm[k] == 50:
  1040. prm[k] = 25
  1041. elif prm[k] == 100:
  1042. prm[k] = 50
  1043. #else:
  1044. # prm[k] -=5 #/=1.1
  1045. #prm[k] =int(prm[k])
  1046. if prm[k] < 0:
  1047. prm[k] = 0
  1048. if prm[k] > 100:
  1049. prm[k] = 100
  1050. if prm[k] == 6: #bug
  1051. prm[k] =5
  1052. if prm[k] > 25 and prm[k] < 50: #bug
  1053. prm[k] =50
  1054. if prm[k] > 50 and prm[k] < 100: #bug
  1055. prm[k] =100
  1056. ct.elem[self.attr]["text"] = "WIDTH:\n{:0.0f}".format(prm[k])
  1057. cprint(prm)
  1058. elif self.attr.startswith("DIR:"):#SIN":
  1059. #global prm
  1060. k = "DIR"
  1061. if event.num == 1:
  1062. prm[k] = 1
  1063. elif event.num == 3:
  1064. prm[k] = -1
  1065. elif event.num == 4:
  1066. prm[k] = 1
  1067. elif event.num == 5:
  1068. prm[k] =-1
  1069. txt = prm[k]
  1070. ct.elem[self.attr]["text"] = "DIR:\n{}".format(prm[k])
  1071. cprint(prm)
  1072. elif self.attr.startswith("SHUFFLE:"):#SIN":
  1073. #global prm
  1074. k = "SHUFFLE"
  1075. if event.num == 1:
  1076. prm[k] = 0
  1077. elif event.num == 3:
  1078. prm[k] = 1
  1079. elif event.num == 4:
  1080. prm[k] = 1
  1081. elif event.num == 5:
  1082. prm[k] =0
  1083. if prm[k] == 6: #bug ?
  1084. prm[k] =5
  1085. ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
  1086. cprint(prm)
  1087. elif self.attr.startswith("INVERT:"):#SIN":
  1088. #global prm
  1089. k = "INVERT"
  1090. if event.num == 1:
  1091. prm[k] = 0
  1092. elif event.num == 3:
  1093. prm[k] = 1
  1094. elif event.num == 4:
  1095. prm[k] = 1
  1096. elif event.num == 5:
  1097. prm[k] =0
  1098. if prm[k] == 6: #bug ?
  1099. prm[k] =5
  1100. ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
  1101. cprint(prm)
  1102. elif self.attr.startswith("FX-X:"):#SIN":
  1103. #global prm
  1104. k = "FX-X"
  1105. if event.num == 1:
  1106. prm[k] = 1
  1107. elif event.num == 3:
  1108. prm[k] = 2
  1109. elif event.num == 4:
  1110. prm[k] += 1
  1111. elif event.num == 5:
  1112. prm[k] -=1
  1113. if prm[k] > 100:
  1114. prm[k] = 100
  1115. if prm[k] < 1:
  1116. prm[k] =1
  1117. txt = prm[k]
  1118. ct.elem[self.attr]["text"] = "FX-X:\n{}".format(prm[k])
  1119. cprint(prm)
  1120. elif self.attr.startswith("WING:"):#SIN":
  1121. #global prm
  1122. k = "WING"
  1123. if event.num == 1:
  1124. prm[k] = 1
  1125. elif event.num == 3:
  1126. prm[k] = 2
  1127. elif event.num == 4:
  1128. prm[k] += 1
  1129. elif event.num == 5:
  1130. prm[k] -=1
  1131. if prm[k] > 100:
  1132. prm[k] = 100
  1133. if prm[k] < 1:
  1134. prm[k] =1
  1135. txt = prm[k]
  1136. ct.elem[self.attr]["text"] = "WING:\n{}".format(prm[k])
  1137. cprint(prm)
  1138. elif self.attr.startswith("OFFSET:"):#SIN":
  1139. #global prm
  1140. k = "OFFSET"
  1141. if event.num == 1:
  1142. prm[k] = 50
  1143. elif event.num == 2:
  1144. prm[k] *= 2
  1145. elif event.num == 3:
  1146. prm[k] = 100
  1147. elif event.num == 4:
  1148. if prm[k] <= 0:
  1149. prm[k] = 1
  1150. prm[k] +=5 #*=1.1
  1151. elif event.num == 5:
  1152. prm[k] -=5 #/=1.1
  1153. #prm[k] =int(prm[k])
  1154. #if prm[k] > 512:
  1155. # prm[k] = 512
  1156. if prm[k] < 5:
  1157. prm[k] =0
  1158. if prm[k] == 6: #bug
  1159. prm[k] =5
  1160. ct.elem[self.attr]["text"] = "OFFSET:\n{:0.0f}".format(prm[k])
  1161. cprint(prm)
  1162. elif self.attr.startswith("BASE:"):
  1163. k = "BASE"
  1164. if event.num == 1:
  1165. prm[k] = "-"
  1166. elif event.num == 3:
  1167. prm[k] = "0"
  1168. elif event.num == 4:
  1169. prm[k] = "+"
  1170. elif event.num == 5:
  1171. prm[k] = "0"
  1172. ct.elem[self.attr]["text"] = "BASE:\n{}".format(prm[k])
  1173. elif self.attr.startswith("FX:"):#SIN":
  1174. self.fx(event)
  1175. elif self.attr == "FX OFF":
  1176. if event.num == 1:
  1177. FIXTURES.fx_off("all")
  1178. CONSOLE.fx_off("all")
  1179. CONSOLE.flash_off("all")
  1180. master._refresh_fix()
  1181. return 0
  1182. #if event.num == 1:
  1183. elif self.attr == "REC-FX":
  1184. cprint("ELSE",self.attr)
  1185. modes.val(self.attr,1)
  1186. return 0
  1187. def cb(self,event):
  1188. cprint("EVENT_fx cb",self.attr,self.mode,event,color='yellow')
  1189. cprint(["type",event.type,"num",event.num])
  1190. try:
  1191. change = 0
  1192. if self.mode.startswith("FX"):
  1193. self.command(event)
  1194. return 0
  1195. except Exception as e:
  1196. cprint("== cb EXCEPT",e,color="red")
  1197. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1198. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1199. return 1
  1200. window_list_buffer = {}
  1201. def save_window_position(save_as=""):
  1202. global window_list_buffer
  1203. cprint()
  1204. cprint("save_window_position",[save_as])
  1205. base = Base()
  1206. fname = HOME+"/LibreLight"
  1207. fname = base.show_path1 +base.show_name
  1208. if save_as:
  1209. fname = save_as
  1210. fname += "/gui.txt"
  1211. cprint("- fname",fname)
  1212. for k in window_list_buffer:
  1213. window_list_buffer[k][0] = 0
  1214. for k,win in window_manager.windows.items():
  1215. try:
  1216. geo = win.tk.geometry()
  1217. data = [1,k,geo]
  1218. if k not in window_list_buffer:
  1219. cprint("-- new:win:pos",k.ljust(15," "),data)
  1220. elif window_list_buffer[k][2] != geo:
  1221. cprint("-- update:win:pos",k.ljust(15," "),data)
  1222. window_list_buffer[k] = data
  1223. if k in ["PATCH","FIXTURES","DIMMER","FIXTURE-EDITOR","CONFIG"]:
  1224. window_list_buffer[k][0] = 0
  1225. except Exception as e:
  1226. cprint("-A save_window_position Exception:",k,e,color="red")
  1227. lines = ""
  1228. for k,data in window_list_buffer.items():
  1229. try:
  1230. #print("-- save:win:pos",k.ljust(15," "),data)
  1231. if not data[2]:
  1232. continue
  1233. line ="{} {} {}\n"
  1234. line = line.format(data[0],k,data[2])
  1235. lines += line
  1236. except Exception as e:
  1237. cprint("-A save_window_position Exception:",e,color="red")
  1238. try:
  1239. f = open(fname,"w")
  1240. f.write( lines )
  1241. except Exception as e:
  1242. cprint("-B save_window_position Exception:",e,color="red")
  1243. finally:
  1244. f.close() #f.flush()
  1245. def save_window_position_loop(): # like autosave
  1246. def loop():
  1247. time.sleep(20)
  1248. try:
  1249. while 1:
  1250. save_window_position()
  1251. time.sleep(60)
  1252. except Exception as e:
  1253. cprint("save_loop",e)
  1254. thread.start_new_thread(loop,())
  1255. def get_window_position(_filter="",win=None):
  1256. global window_list_buffer
  1257. cprint()
  1258. show = None
  1259. k = _filter
  1260. geo = ""
  1261. cprint("get_window_position",[_filter])
  1262. if _filter in window_list_buffer:
  1263. show,k,geo = window_list_buffer[_filter]
  1264. if win:
  1265. win.tk.geometry(geo)
  1266. return show,k,geo
  1267. def read_window_position():
  1268. try:
  1269. base = Base()
  1270. fname = HOME+"/LibreLight"
  1271. fname = base.show_path1 +base.show_name
  1272. fname += "/gui.txt"
  1273. cprint("- fname:",fname)
  1274. f = open(fname,"r")
  1275. lines = f.readlines()
  1276. f.close()
  1277. out = []
  1278. for line in lines:
  1279. line = line.strip()
  1280. #print(line)
  1281. if " " in line:
  1282. if line.count(" ") >= 2:
  1283. show,name,geo = line.split(" ",2)
  1284. elif line.count(" ") == 1:
  1285. name,geo = line.split(" ",1)
  1286. show = 1
  1287. out.append([show,name,geo])
  1288. return out
  1289. except Exception as e:
  1290. cprint("- load_window_position 345 Exception:",e,color="red")
  1291. return
  1292. return []
  1293. def split_window_show(lines,_filter=""):
  1294. try:
  1295. for show,name,geo in lines:
  1296. #print( "wwWww "*10,[show,name,geo] )
  1297. if _filter in name:
  1298. return int(show)
  1299. except Exception as e:
  1300. cprint("- split_window_show 345 Exception:",e,color="red")
  1301. def split_window_position(lines,_filter=""):
  1302. try:
  1303. for show,name,geo in lines:
  1304. #print( "wwWww "*10,[show,name,geo] )
  1305. if _filter in name:
  1306. geo = geo.replace("+"," ")
  1307. geo = geo.replace("x"," ")
  1308. geo = geo.split()
  1309. #print( "wwWww "*10,[show,name,geo] )
  1310. if len(geo) == 4:
  1311. #print( [show,name,geo] )
  1312. args = {}
  1313. args["width"] = int(geo[0])
  1314. args["height"] = int(geo[1])
  1315. args["left"] = int(geo[2])
  1316. args["top"] = int(geo[3])
  1317. return args
  1318. except Exception as e:
  1319. cprint("- split_window_position 345 Exception:",e,color="red")
  1320. def load_window_position(_filter=""):
  1321. global window_list_buffer
  1322. cprint()
  1323. cprint("load_window_position",[_filter])
  1324. try:
  1325. lines = read_window_position()
  1326. data = {}
  1327. for show,name,geo in lines:
  1328. data[name] = [show,name,geo]
  1329. window_list_buffer[name] = [show,name,geo]
  1330. for name,win in window_manager.windows.items():
  1331. if not win:
  1332. continue
  1333. if name not in data:
  1334. continue
  1335. if _filter:
  1336. if _filter != name:
  1337. continue
  1338. w = data[name][2]
  1339. cprint("- set_win_pos","filter:",[_filter],"Name: {:<20}".format(name),w,win)
  1340. try:
  1341. win.tk.geometry(w)
  1342. except Exception as e:
  1343. cprint("- load_window_position 544 Exception:",e,color="red")
  1344. except Exception as e:
  1345. cprint("- load_window_position 345 Exception:",e,color="red")
  1346. return
  1347. class BLINKI():
  1348. def __init__(self,e):
  1349. self.e = e
  1350. def blink(self):
  1351. e = self.e
  1352. e.config(bg='green')
  1353. duration = 150
  1354. for i in range(8):
  1355. d = i * duration
  1356. if i % 2 == 0:
  1357. e.after(d, lambda: e.config(bg='white')) # after 1000ms
  1358. e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
  1359. else:
  1360. e.after(d, lambda: e.config(bg='orange')) # after 1000ms
  1361. e.after(d, lambda: e.config(activebackground='orange')) # after 1000ms
  1362. i+=1
  1363. duration = 150
  1364. e.after(d, lambda: e.config(bg='white')) # after 1000ms
  1365. e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
  1366. class Xevent():
  1367. """ global input event Handeler for short cut's ... etc
  1368. """
  1369. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  1370. self.fix = fix
  1371. self.data=data
  1372. self.attr = attr
  1373. self.elem = elem
  1374. self.mode = mode
  1375. def setup(self,event):
  1376. cprint("xevent.SETUP",[self.mode,self.attr],color="red")
  1377. if self.mode == "SETUP":
  1378. if self.attr == "SAVE\nSHOW":
  1379. self.elem["bg"] = "orange"
  1380. self.elem["text"] = "SAVING..."
  1381. self.elem["bg"] = "red"
  1382. self.elem.config(activebackground="orange")
  1383. modes.val(self.attr,1)
  1384. PRESETS.backup_presets()
  1385. FIXTURES.backup_patch()
  1386. save_window_position()
  1387. #time.sleep(1)
  1388. #modes.val(self.attr,0)
  1389. self.elem["bg"] = "lightgrey"
  1390. #self.elem["fg"] = "lightgrey"
  1391. self.elem.config(activebackground="lightgrey")
  1392. b = BLINKI(self.elem)
  1393. b.blink()
  1394. self.elem["text"] = "SAVE\nSHOW"
  1395. elif self.attr == "LOAD\nSHOW":
  1396. name = "LOAD-SHOW"
  1397. base = Base()
  1398. line1 = "PATH: "+base.show_path1 +base.show_name
  1399. line2 = "DATE: "+ time.strftime("%Y-%m-%d %X", time.localtime(time.time()))
  1400. class cb():
  1401. def __init__(self,name=""):
  1402. self.name=name
  1403. cprint("cb",name)
  1404. def cb(self,event=None,**args):
  1405. cprint("cdb",self.name,event,args)
  1406. if self.name != "<exit>":
  1407. cprint("-----------------------:")
  1408. LOAD_SHOW_AND_RESTAT(self.name).cb()
  1409. #self.elem["bg"] = "lightgrey"
  1410. #self.elem.config(activebackground="lightgrey")
  1411. pw = PopupList(name,cb=cb)
  1412. frame = pw.sframe(line1=line1,line2=line2)
  1413. r = _load_show_list(frame,cb=cb)
  1414. #self.elem["bg"] = "red"# "lightgrey"
  1415. #self.elem.config(activebackground="red")
  1416. #self.elem.config(activebackground="lightgrey")
  1417. #w.tk.attributes('-topmost',False)
  1418. elif self.attr == "SAVE\nSHOW AS":
  1419. base = Base()
  1420. #def _cb(fname):
  1421. def _cb(data):
  1422. if not data:
  1423. cprint("err443",self,"_cb",data)
  1424. return None
  1425. fname = data["Value"]
  1426. cprint(self,"save_show._cb()",fname)
  1427. fpath,fname = base.build_path(fname)
  1428. cprint("SAVE AS",fpath,fname)
  1429. if base._create_path(fpath):
  1430. a=PRESETS.backup_presets(save_as=fpath)
  1431. b=FIXTURES.backup_patch(save_as=fpath)
  1432. #base._set(fname)
  1433. save_window_position(save_as=fpath)
  1434. LOAD_SHOW_AND_RESTAT(fname).cb()
  1435. dialog._cb = _cb
  1436. dialog.askstring("SAVE SHOW AS","SAVE SHOW AS:")
  1437. elif self.attr == "SAVE &\nRESTART":
  1438. self.elem["bg"] = "orange"
  1439. self.elem["text"] = "SAVING..."
  1440. self.elem["bg"] = "red"
  1441. self.elem.config(activebackground="orange")
  1442. modes.val(self.attr,1)
  1443. PRESETS.backup_presets()
  1444. FIXTURES.backup_patch()
  1445. save_window_position()
  1446. self.elem["text"] = "RESTARTING..."
  1447. #time.sleep(1)
  1448. #modes.val(self.attr,0)
  1449. self.elem["bg"] = "lightgrey"
  1450. #self.elem["fg"] = "lightgrey"
  1451. self.elem.config(activebackground="lightgrey")
  1452. LOAD_SHOW_AND_RESTAT("").cb(force=1)
  1453. elif self.attr == "DRAW\nGUI":
  1454. #self.elem["bg"] = "orange"
  1455. old_text = self.elem["text"]
  1456. #self.elem["text"] = "DRAWING..."
  1457. #self.elem["bg"] = "red"
  1458. #time.sleep(0.05)
  1459. #print("redraw",name)
  1460. #if name == "PATCH":
  1461. # gui_patch.draw()
  1462. #if name == "DIMMER":
  1463. # gui_fix.draw()
  1464. #self.elem["text"] = "PATCH..."
  1465. #self.elem["text"] = "PATCH..."
  1466. window_manager.top("PATCH")
  1467. gui_patch.draw(FIXTURES)
  1468. #self.elem["text"] = "FIX..."
  1469. gui_fix.draw(FIXTURES)
  1470. window_manager.top("FIXTURES")
  1471. master._refresh_exec()
  1472. self.elem["text"] = old_text
  1473. else:
  1474. r=tkinter.messagebox.showwarning(message="{}\nnot implemented".format(self.attr.replace("\n"," ")),parent=None)
  1475. return 1
  1476. def live(self,event):
  1477. if self.mode == "LIVE":
  1478. if "FADE" in self.attr or "DELAY" in self.attr:
  1479. if self.attr == "FADE":
  1480. ct = FADE
  1481. if self.attr == "DELAY":
  1482. ct = DELAY
  1483. if "PAN/TILT\nFADE" in self.attr:
  1484. ct = FADE_move
  1485. value = ct.val()
  1486. #print("EVENT CHANGE ",[self.attr])
  1487. cprint("EVENT CHANGE:",self.mode,value,self.attr)
  1488. if value < 0.01:
  1489. ct.val(0.01)
  1490. elif value > 100.0:
  1491. pass #value = 100
  1492. if event.num == 4:
  1493. value *= 1.1
  1494. elif event.num == 5:
  1495. value /= 1.1
  1496. elif event.num == 1:
  1497. if ct._is():
  1498. ct.off()# = 0
  1499. self.data.commands.elem[self.attr]["bg"] = "grey"
  1500. self.elem.config(activebackground="grey")
  1501. else:
  1502. ct.on()# = 1
  1503. self.data.commands.elem[self.attr]["bg"] = "green"
  1504. self.elem.config(activebackground="lightgreen")
  1505. elif event.num == 2:
  1506. if value > 1 and value < 4:
  1507. value = 4
  1508. elif value > 3 and value < 6:
  1509. value = 6
  1510. elif value > 5 and value < 7:
  1511. value = 8
  1512. elif value > 7 and value < 9:
  1513. value = 10
  1514. elif value > 9:
  1515. value = 0.01
  1516. elif value < 1:
  1517. value = 1.1
  1518. value = round(value,3)
  1519. value = ct.val(value)
  1520. if self.attr == "FADE":
  1521. self.data.commands.elem[self.attr]["text"] = "FADE:\n{:0.2f}".format(value)
  1522. if self.attr == "DELAY":
  1523. self.data.commands.elem[self.attr]["text"] = "DELAY:\n{:0.3f}".format(value)
  1524. if "PAN/TILT\nFADE" in self.attr:
  1525. self.data.commands.elem[self.attr]["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
  1526. def command(self,event):
  1527. if self.mode == "COMMAND":
  1528. if self.attr == "CLEAR":
  1529. if event.num == 1:
  1530. ok = FIXTURES.clear()
  1531. if ok:
  1532. master._refresh_fix()
  1533. modes.val(self.attr,0)
  1534. elif self.attr == "SAVE":
  1535. modes.val(self.attr,1)
  1536. PRESETS.backup_presets()
  1537. FIXTURES.backup_patch()
  1538. #time.sleep(1)
  1539. modes.val(self.attr,0)
  1540. elif self.attr == "S-KEY":
  1541. global _global_short_key
  1542. if _global_short_key:
  1543. _global_short_key = 0
  1544. master.commands.elem["S-KEY"]["bg"] = "red"
  1545. master.commands.elem["S-KEY"]["activebackground"] = "red"
  1546. else:
  1547. _global_short_key = 1
  1548. master.commands.elem["S-KEY"]["bg"] = "green"
  1549. master.commands.elem["S-KEY"]["activebackground"] = "green"
  1550. cprint("s-key",_global_short_key)
  1551. else:
  1552. if event.num == 1:
  1553. cprint("ELSE",self.attr)
  1554. modes.val(self.attr,1)
  1555. return 0
  1556. def encoder(self,event):
  1557. global _shift_key
  1558. cprint("Xevent","ENC",self.fix,self.attr,self.mode)
  1559. cprint("SHIFT_KEY",_shift_key,"??????????")
  1560. if self.mode == "ENCODER":
  1561. if self._encoder(event):
  1562. master.refresh_fix() # delayed
  1563. refresher_fix.reset() # = Refresher()
  1564. if self.mode == "ENCODER2":
  1565. if self._encoder(event):
  1566. master.refresh_fix() # delayed
  1567. refresher_fix.reset() # = Refresher()
  1568. if self.mode == "INVERT":
  1569. cprint("INVERT",event)
  1570. if self._encoder(event):
  1571. master.refresh_fix() # delayed
  1572. refresher_fix.reset() # = Refresher()
  1573. def _encoder(self,event):
  1574. global _shift_key
  1575. if 1: #self.mode == "ENCODER" or self.mode == "ENCODER2":
  1576. cprint("-- Xevent","_ENC",self.fix,self.attr,self.mode)
  1577. cprint("-- SHIFT_KEY",_shift_key,"??????????")
  1578. #cprint(self.data)
  1579. val=""
  1580. if event.num == 1:
  1581. val ="click"
  1582. elif event.num == 4:
  1583. val ="++"
  1584. if _shift_key:
  1585. val = "+"
  1586. elif event.num == 5:
  1587. val ="--"
  1588. if _shift_key:
  1589. val = "-"
  1590. #print("SHIFT",val,_shift_key)
  1591. if val:
  1592. FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
  1593. return 1
  1594. def cb(self,event):
  1595. cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
  1596. cprint(["type",event.type,"num",event.num])
  1597. global INIT_OK
  1598. INIT_OK = 1
  1599. try:
  1600. change = 0
  1601. if "keysym" in dir(event):
  1602. if "Escape" == event.keysym:
  1603. ok = FIXTURES.clear()
  1604. master._refresh_fix()
  1605. cprint()
  1606. return 0
  1607. if self.mode == "SETUP":
  1608. self.setup(event)
  1609. elif self.mode == "COMMAND":
  1610. self.command(event)
  1611. elif self.mode == "LIVE":
  1612. self.live(event)
  1613. elif self.mode == "ENCODER":
  1614. self.encoder(event)
  1615. master.refresh_fix()
  1616. elif self.mode == "ENCODER2":
  1617. self.encoder(event)
  1618. elif self.mode == "INVERT":
  1619. self.encoder(event)
  1620. elif self.mode == "FX":
  1621. cprint("Xevent CALLING FX WRONG EVENT OBJECT !!",color="red")
  1622. elif self.mode == "ROOT":
  1623. if event.keysym=="Escape":
  1624. pass
  1625. elif self.mode == "INPUT":
  1626. cprint("INP",self.data.entry.get())
  1627. if event.keycode == 36:
  1628. x=self.data.entry.get()
  1629. #client.send(x)
  1630. elif self.mode == "INPUT2":
  1631. cprint("INP2",self.data.entry2.get())
  1632. if event.keycode == 36:
  1633. x=self.data.entry2.get()
  1634. #client.send(x)
  1635. elif self.mode == "INPUT3":
  1636. cprint("INP3",self.data.entry3.get())
  1637. if event.keycode == 36:
  1638. x=self.data.entry3.get()
  1639. #client.send(x)
  1640. elif self.mode == "PRESET":
  1641. nr = self.attr #int(self.attr.split(":")[1])-1
  1642. if event.num == 3: # right click for testing
  1643. if str(event.type) == '4': #4 ButtonPress
  1644. if modes.val("CFG-BTN"):
  1645. master.btn_cfg(nr,testing=1)
  1646. if event.num == 1:
  1647. if str(event.type) == '4': #4 ButtonPress
  1648. if modes.val("REC"):
  1649. self.data.preset_rec(nr)
  1650. modes.val("REC",0)
  1651. time.sleep(0.05)
  1652. master._refresh_exec(nr=nr)
  1653. elif modes.val("DEL"):
  1654. ok=PRESETS.delete(nr)
  1655. if ok:
  1656. modes.val("DEL",0)
  1657. #master.refresh_exec()
  1658. master._refresh_exec(nr=nr)
  1659. elif modes.val("COPY"):
  1660. ok=PRESETS.copy(nr)
  1661. if ok:
  1662. modes.val("COPY",0)
  1663. master._refresh_exec(nr=nr)
  1664. elif modes.val("MOVE"):
  1665. ok,cnr,bnr=PRESETS.move(nr)
  1666. if ok:
  1667. #modes.val("MOVE",0) # keep MOVE on
  1668. master._refresh_exec(nr=nr)
  1669. master._refresh_exec(nr=bnr)
  1670. elif modes.val("CFG-BTN"):
  1671. master.btn_cfg(nr)
  1672. #master._refresh_exec(nr=nr)
  1673. elif modes.val("LABEL"):#else:
  1674. master.label(nr)
  1675. #master._refresh_exec(nr=nr)
  1676. elif modes.val("EDIT"):
  1677. FIXTURES.clear()
  1678. self.data.preset_select(nr)
  1679. self.data.preset_go(nr,xfade=0,event=event,val=255,button="go")
  1680. modes.val("EDIT", 0)
  1681. master.refresh_fix()
  1682. refresher_fix.reset() # = Refresher()
  1683. elif modes.val("SELECT"):
  1684. self.data.preset_select(nr)
  1685. else:
  1686. self.data.preset_go(nr,event=event,val=255)
  1687. else:
  1688. self.data.preset_go(nr,xfade=0,event=event,val=0)
  1689. cprint(" == "*10)
  1690. master.refresh_fix()
  1691. refresher_fix.reset() # = Refresher()
  1692. if event.num == 3:
  1693. if not modes.val("REC"):
  1694. if str(event.type) == '4': #4 ButtonPress
  1695. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=255)
  1696. else:
  1697. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=0)
  1698. cprint()
  1699. return 0
  1700. elif self.mode == "INPUT":
  1701. cprint()
  1702. return 0
  1703. except Exception as e:
  1704. cprint("== cb EXCEPT",e,color="red")
  1705. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1706. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1707. cprint()
  1708. return 1
  1709. def wheel(event,d=None):
  1710. cprint("wheel",event,d)
  1711. class Element():
  1712. def __init__(self):
  1713. self.__data = {}
  1714. def set(self,key,val):
  1715. self.__data[key] = val
  1716. class Base():
  1717. def __init__(self):
  1718. cprint("Base.init()",color="red")
  1719. self._init()
  1720. def _init(self):
  1721. show_name = "DemoShow"
  1722. self.show_path0 = HOME +"/LibreLight/"
  1723. self.show_path = self.show_path0
  1724. self.show_path1 = self.show_path0 + "show/"
  1725. try:
  1726. f = open(self.show_path+"init.txt","r")
  1727. for line in f.readlines():
  1728. #cprint(line)
  1729. if not line.startswith("#"):
  1730. show_name = line.strip()
  1731. show_name = show_name.replace(".","")
  1732. show_name = show_name.replace("\\","")
  1733. show_name = show_name.replace("/","")
  1734. self.show_name = show_name
  1735. except Exception as e:
  1736. cprint("show name exception",color="red")
  1737. msg="Error Exception:{}".format(e)
  1738. r=tkinter.messagebox.showwarning(message=msg,parent=None)
  1739. finally:
  1740. f.close()
  1741. fpath = self.show_path1 +show_name
  1742. if not os.path.isdir(fpath):
  1743. cprint(fpath)
  1744. cprint( os.path.isdir(fpath))
  1745. msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  1746. msg += "please check\n"
  1747. msg += "-{}init.txt\n".format(self.show_path0)
  1748. msg += "-{}".format(self.show_path1)
  1749. showwarning(msg=msg,title="Show Error")
  1750. exit()
  1751. self._check()
  1752. def _set(self,fname):
  1753. ok= os.path.isdir(self.show_path1+"/"+fname)
  1754. ini = self.show_path0+"init.txt"
  1755. cprint("SET SHOW NAME",fname,ok,ini)
  1756. try:
  1757. f = open( ini ,"r")
  1758. lines = f.readlines()
  1759. f.close()
  1760. if len(lines) >= 10: # cut show history
  1761. cprint("_set",ini,len(lines))
  1762. lines = lines[-10:]
  1763. f = open( ini ,"w")
  1764. f.writelines(lines)
  1765. f.close()
  1766. exit()
  1767. except:pass
  1768. if ok:
  1769. #self.show_name = fname
  1770. f = open( ini ,"a")
  1771. f.write(fname+"\n")
  1772. f.close()
  1773. return 1
  1774. def _check(self):
  1775. if not os.path.isdir(self.show_path):
  1776. os.mkdir(self.show_path)
  1777. self.show_path += "/show/"
  1778. if not os.path.isdir(self.show_path):
  1779. os.mkdir(self.show_path)
  1780. self.show_path += "/" +self.show_name +"/"
  1781. if not os.path.isdir(self.show_path):
  1782. os.mkdir(self.show_path)
  1783. pass
  1784. def _list(self):
  1785. #self._check()
  1786. show_list = list(os.listdir( self.show_path1 ))
  1787. out = []
  1788. for fname in show_list:
  1789. #print(fname)
  1790. ctime = os.path.getmtime(self.show_path1+fname)
  1791. ctime = time.strftime("%Y-%m-%d %X", time.localtime(ctime)) #1650748726.6604707))
  1792. try:
  1793. mtime = os.path.getmtime(self.show_path1+fname+"/patch.sav")
  1794. mtime = time.strftime("%Y-%m-%d %X", time.localtime(mtime)) #1650748726.6604707))
  1795. except:
  1796. mtime = 0
  1797. if mtime:
  1798. out.append([fname,mtime])#,ctime])
  1799. from operator import itemgetter
  1800. out=sorted(out, key=itemgetter(1))
  1801. out.reverse()
  1802. return out
  1803. def _load(self,filename):
  1804. xfname = self.show_path+"/"+str(filename)+".sav"
  1805. cprint("load",xfname)
  1806. try:
  1807. f = open(xfname,"r")
  1808. lines = f.readlines()
  1809. f.close()
  1810. except Exception as e:
  1811. msg = "Exception: {}".format(e)
  1812. msg += "\n\ncheck\n-init.txt"
  1813. cprint(msg,color="red")
  1814. showwarning(msg=msg,title="load Error")
  1815. data = OrderedDict()
  1816. labels = OrderedDict()
  1817. i=0
  1818. for line in lines:
  1819. if line.count("\t") < 2:
  1820. cprint("Error line.count('\\t') < 2 (is:{})".format(line.count("\t")),color="red",end=" ")
  1821. cprint("file:{}".format(xfname),color="red")
  1822. continue
  1823. key,label,rdata = line.split("\t",2)
  1824. key = int(key)
  1825. jdata = json.loads(rdata,object_pairs_hook=OrderedDict)
  1826. nrnull = 0
  1827. if "ATTRIBUT" in jdata: # translate old FIXTURES.fixtures start with 0 to 1
  1828. if nrnull:
  1829. cprint("DMX NR IS NULL",attr,"CHANGE +1")
  1830. for attr in jdata["ATTRIBUT"]:
  1831. if "NR" in jdata["ATTRIBUT"][attr]:
  1832. nr = jdata["ATTRIBUT"][attr]["NR"]
  1833. if nr >= 0:
  1834. jdata["ATTRIBUT"][attr]["NR"] +=1
  1835. data[key] = jdata
  1836. labels[key] = label
  1837. return data,labels
  1838. def _clean_path(self,fpath):
  1839. _path=[]
  1840. for i in fpath:
  1841. fpath = fpath.replace(" ","_")
  1842. if i in string.ascii_letters+string.digits+"äöüßÖÄÜ_-":
  1843. _path.append(i)
  1844. path = "".join(_path)
  1845. return path
  1846. def build_path(self,save_as):
  1847. save_as = self._clean_path(save_as)
  1848. path = self.show_path.split("/")
  1849. path = "/".join(path[:-2])
  1850. fpath = path+"/"+save_as
  1851. return fpath,save_as
  1852. def _create_path(self,fpath):
  1853. if os.path.isdir(fpath):
  1854. cprint("STOP SHOW EXIST !",color="red")
  1855. return 0
  1856. else:
  1857. cprint("CREATE DIR ",fpath,color="green")
  1858. os.mkdir(fpath)
  1859. #self._set(save_as)
  1860. return fpath
  1861. def _backup(self,filename,data,labels,save_as):
  1862. if save_as:
  1863. xfname = save_as +"/"+str(filename)+".sav"
  1864. else:
  1865. xfname = self.show_path+"/"+str(filename)+".sav"
  1866. cprint("backup",xfname)
  1867. f = open(xfname,"w")
  1868. for key in data:
  1869. line = data[key]
  1870. #print(line)
  1871. label = "label"
  1872. if key in labels:
  1873. label = labels[key]
  1874. if label == "Name-"+str(key):
  1875. label = ""
  1876. #print(xfname,"load",key,label,len(line))
  1877. f.write( "{}\t{}\t{}\n".format( key,label,json.dumps(line) ) )
  1878. f.close()
  1879. return 1
  1880. def hex_to_rgb(hex):
  1881. return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
  1882. class cb():
  1883. def __init__(self,win):
  1884. self.win = win
  1885. def _callback(self,event):
  1886. clobj=event.widget
  1887. ## undermouse=find_withtag(master.CURRENT)
  1888. undermouse=self.win.find_closest(self.win.CURRENT)
  1889. cprint( repr(undermouse))
  1890. def callback(self,event):
  1891. cprint(__file__,self,"callback",event)
  1892. cnv = self.win
  1893. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  1894. tags = cnv.gettags(item)
  1895. #cnv.itemconfigure(self.tag, text=tags[0])
  1896. cprint(tags,item)
  1897. color = cnv.itemcget(item, "fill")
  1898. cnv.itemconfig("all", width=1)#filla="green")
  1899. cnv.itemconfig(item, width=3)#filla="green")
  1900. cprint(color)
  1901. cprint( hex_to_rgb(color[1:]))
  1902. class Elem_Container():
  1903. def __init__(self):
  1904. self.commands = []
  1905. self.val = {}
  1906. self.elem = {}
  1907. class MASTER():
  1908. def __init__(self):
  1909. #super().__init__()
  1910. self.base = Base ()
  1911. self.load()
  1912. self._XX = 0
  1913. self.all_attr =["DIM","PAN","TILT"]
  1914. self.elem_attr = {}
  1915. self.setup_elem = {} # Elem_Container()
  1916. self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI"]
  1917. self.fx_moves = Elem_Container()
  1918. self.fx_moves.commands =["REC-FX","FX OFF","\n"
  1919. ,"FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  1920. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  1921. ]
  1922. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  1923. self.fx = Elem_Container()
  1924. self.fx.commands =[
  1925. "FX:DIM","FX:RED", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  1926. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","FX-X:\n-","FX:MODE"
  1927. ]
  1928. self.fx_generic = Elem_Container()
  1929. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON"]
  1930. self.commands = Elem_Container()
  1931. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  1932. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  1933. ,"BLIND","CLEAR","REC","EDIT","COPY","-","\n"
  1934. ]
  1935. self.elem_presets = {}
  1936. for i in range(8*8*8):
  1937. if i not in PRESETS.val_presets:
  1938. name = "Preset:"+str(i+1)+":\nXYZ"
  1939. #self.presets[i] = [i]
  1940. PRESETS.val_presets[i] = OrderedDict() # FIX
  1941. PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
  1942. PRESETS.label_presets[i] = "-"
  1943. modes.set_cb(self.xcb)
  1944. def button_refresh(self,name,color,color2=None,text="",fg=None):
  1945. cprint("button_refresh",name,color)
  1946. #if color == "gold":
  1947. # color2 = "yellow"
  1948. try:
  1949. if color2 is None:
  1950. color2 = color
  1951. if text:
  1952. text = "\n"+str(text)
  1953. if name in self.commands.elem:
  1954. self.commands.elem[name]["bg"] = color
  1955. self.commands.elem[name]["text"] = name+ text
  1956. self.commands.elem[name].config(activebackground=color2)
  1957. if fg:
  1958. self.commands.elem[name]["fg"] = fg
  1959. elif name in self.fx.elem:
  1960. #todo
  1961. self.fx.elem[name]["bg"] = color
  1962. self.fx.elem[name].config(activebackground=color2)
  1963. if fg:
  1964. self.fx.elem[name]["fg"] = fg
  1965. # new version
  1966. for elems in [self.fx_moves]:
  1967. if name in elems.elem:
  1968. elem = elems.elem[name]
  1969. cprint("elem",elem)
  1970. elem.config(bg = color)
  1971. elem.config(text = name+text)
  1972. elem.config(activebackground=color2)
  1973. if fg and "fg" in elem:
  1974. elem["fg"] = fg
  1975. except Exception as e:cprint("exc",self,e)
  1976. def btn_cfg(self,nr,testing=0):
  1977. cfg = PRESETS._btn_cfg(nr)
  1978. button = PRESETS.btn_cfg(nr)
  1979. label = PRESETS.label(nr)
  1980. def _cb(data):
  1981. if not data:
  1982. cprint("err443",self,"_cb",data)
  1983. return None
  1984. cprint(self,"btn_cfg._cb()",data)
  1985. if data:
  1986. if "Button" in data and type(data["Button"]) is str:
  1987. txt = data["Button"]
  1988. PRESETS.btn_cfg(nr,txt)
  1989. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1990. if "Label" in data and type(data["Label"]) is str:
  1991. txt = data["Label"]
  1992. PRESETS.label(nr,txt)
  1993. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1994. modes.val("CFG-BTN",0)
  1995. master._refresh_exec(nr=nr)
  1996. dialog._cb = _cb
  1997. if 1: # testing:
  1998. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  1999. else:
  2000. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  2001. def label(self,nr):
  2002. txt = PRESETS.label(nr)
  2003. def _cb(data):
  2004. if not data:
  2005. cprint("err443",self,"_cb",data)
  2006. return None
  2007. txt = data["Value"]
  2008. cprint(self,"label._cb()",nr,txt)
  2009. if txt:
  2010. PRESETS.label(nr,txt)
  2011. self.elem_presets[nr].configure(text = PRESETS.get_btn_txt(nr))
  2012. modes.val("LABEL", 0)
  2013. master._refresh_exec(nr=nr)
  2014. dialog._cb= _cb #_x(nr)
  2015. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  2016. def xcb(self,mode,value=None):
  2017. cprint("MODE CALLBACK",mode,value,color="green",end="")
  2018. #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
  2019. if value:
  2020. cprint("===== ON ======",color="red")
  2021. txt = ""
  2022. if mode == "REC-FX":
  2023. modes.val("REC",0)
  2024. modes.val("REC",1)
  2025. if value == 2:
  2026. if mode in ["MOVE","COPY"]:
  2027. txt="to"
  2028. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  2029. else:
  2030. if mode in ["MOVE","COPY"]:
  2031. txt="from"
  2032. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  2033. else:
  2034. cprint("===== OFF ======",color="red")
  2035. if mode == "REC-FX":
  2036. modes.val("REC",0)
  2037. self.button_refresh(mode,color="lightgrey")#,fg="black")
  2038. def load(self,fname=""):
  2039. pass
  2040. def exit(self):
  2041. cprint("__del__",self)
  2042. PRESETS.backup_presets()
  2043. #print("********************************************************")
  2044. FIXTURES.backup_patch()
  2045. #print("*********del",self,"***********************************************")
  2046. def refresh_exec(self):
  2047. refresher_exec.reset() # = Refresher()
  2048. def _refresh_exec(self,nr=-1):
  2049. s = time.time()
  2050. cprint("PRESET.refresh_exec()")
  2051. refresher_exec.reset() # = Refresher()
  2052. self._XX +=1
  2053. self._nr_ok = 0
  2054. for k in PRESETS.val_presets:
  2055. _bg = "grey"
  2056. _ba = "grey"
  2057. _fg = "lightgrey"
  2058. _text = "N/V"
  2059. if nr >= 0:
  2060. if self._nr_ok:
  2061. break
  2062. if nr != k:
  2063. continue
  2064. else:
  2065. self._nr_ok = 1
  2066. label = ""
  2067. if k not in self.elem_presets:
  2068. cprint("ERROR",k ,"not in elem_presets continue")
  2069. continue
  2070. if k in PRESETS.label_presets:
  2071. label = PRESETS.label_presets[k]
  2072. #print([label])
  2073. b = self.elem_presets[k]
  2074. ifval = 0
  2075. fx_only = 0
  2076. if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
  2077. sdata = PRESETS.val_presets[k]
  2078. #print("sdata7654",sdata)
  2079. BTN="go"
  2080. if "CFG" in sdata:#["BUTTON"] = "GO"
  2081. if "BUTTON" in sdata["CFG"]:
  2082. BTN = sdata["CFG"]["BUTTON"]
  2083. #txt=str(k+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+label
  2084. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  2085. _text = txt
  2086. if b.text != txt: # TODO
  2087. #txt+=str(self._XX)
  2088. #b.configure(text= txt)
  2089. _text = txt
  2090. _bg="yellow"
  2091. _ba="yellow"
  2092. if len(sdata) > 1:
  2093. ifval = 1
  2094. fx_color = 0
  2095. val_color = 0
  2096. for fix in sdata:
  2097. if fix == "CFG":
  2098. continue
  2099. #print( "$$$$",fix,sdata[fix])
  2100. for attr in sdata[fix]:
  2101. if "FX2" in sdata[fix][attr]:
  2102. if sdata[fix][attr]["FX2"]:
  2103. fx_color = 1
  2104. if "FX" in sdata[fix][attr]:
  2105. if sdata[fix][attr]["FX"]:
  2106. fx_color = 1
  2107. if "VALUE" in sdata[fix][attr]:
  2108. if sdata[fix][attr]["VALUE"] is not None:
  2109. val_color = 1
  2110. try:b.configure(fg= "black")
  2111. except:pass
  2112. if val_color:
  2113. _bg = "gold"
  2114. _ba = "#ffaa55"
  2115. if fx_color:
  2116. _fg = "blue"
  2117. else:
  2118. if fx_color:
  2119. fx_only = 1
  2120. else:
  2121. _bg = "grey"
  2122. _ba = "#aaa"
  2123. if "\n" in txt:
  2124. txt1 = txt.split("\n")[0]
  2125. _fg = "black"
  2126. if ifval:
  2127. if fx_only:
  2128. _bg = "cyan"
  2129. _ba = "#55d4ff"
  2130. if "SEL" in txt1:
  2131. b.configure(bg="#77f")
  2132. _bg = "#77f"
  2133. else:
  2134. _bg = "grey"
  2135. _fg = "darkgrey"
  2136. if "SEL" in txt1:
  2137. _fg = "blue"
  2138. elif "ON" in txt1:
  2139. _fg = "#040"
  2140. elif "GO" in txt1:
  2141. _fg = "#555"
  2142. if "FL" in txt1:
  2143. _fg = "#00e"
  2144. b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
  2145. time.sleep(0.01)
  2146. def refresh_fix(self):
  2147. refresher_fix.reset() # = Refresher()
  2148. def _refresh_fix(self):
  2149. cprint(self,"_refresh_fix")
  2150. s=time.time(); _XXX=0
  2151. menu_buff = {"DIM":0,"DIM-SUB":0,"FIX":0,"FIX-SUB":0}
  2152. elem_buffer = []
  2153. for fix in FIXTURES.fixtures:
  2154. sdata = FIXTURES.fixtures[fix]
  2155. elem_attr_fix = None
  2156. if fix in self.elem_attr:
  2157. elem_attr_fix = self.elem_attr[fix]
  2158. if "DIM" in sdata["ATTRIBUT"] and "_ACTIVE" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 2:
  2159. KEY = "DIM-SUB"
  2160. else:
  2161. KEY = "FIX-SUB"
  2162. FIX = 0
  2163. DIM = 0
  2164. for attr in sdata["ATTRIBUT"]:
  2165. _buff = {}
  2166. row = sdata["ATTRIBUT"][attr]
  2167. if attr.endswith("-FINE"):
  2168. continue
  2169. b_attr = attr
  2170. if b_attr == "_ACTIVE":
  2171. b_attr = "S"
  2172. elem = None
  2173. if elem_attr_fix:
  2174. if b_attr not in elem_attr_fix:
  2175. continue
  2176. elem = elem_attr_fix[b_attr]
  2177. if not elem:
  2178. continue
  2179. if "elem" not in _buff:
  2180. _buff["elem"] = elem
  2181. if not attr.startswith("_"):
  2182. v2 = row["VALUE"]
  2183. #_text = "{} {}".format(str(attr).rjust(4,"0"),str(v2).rjust(4,"0")) # ~0.2 sec
  2184. _text = "{} {}".format(attr,v2)
  2185. _buff["text"] = _text
  2186. if row["ACTIVE"]:
  2187. _buff["bg"] = "yellow"
  2188. _buff["abg"] = "yellow"
  2189. menu_buff[KEY] += 1
  2190. if b_attr == "S":
  2191. if KEY == "DIM-SUB":
  2192. DIM =1
  2193. else:
  2194. FIX =1
  2195. else:
  2196. _buff["bg"] = "grey"
  2197. _buff["abg"] = "grey"
  2198. if "FX2" not in row: # insert FX2 excetption
  2199. row["FX2"] = OrderedDict()
  2200. if row["FX"]:
  2201. _buff["fg"] = "blue"
  2202. elif row["FX2"]:
  2203. _buff["fg"] = "red"
  2204. else:
  2205. _buff["fg"] = "black"
  2206. elem_buffer.append(_buff)
  2207. menu_buff["FIX"] += FIX
  2208. menu_buff["DIM"] += DIM
  2209. cprint(" =+= "*10,"refresh_fix")
  2210. try:
  2211. for row in elem_buffer:
  2212. elem = row["elem"]
  2213. if not elem:
  2214. continue
  2215. #print("<elem>",elem)
  2216. for e in row:
  2217. if e == "elem":
  2218. continue
  2219. v = row[e]
  2220. #print("confg:",["key:",e,"val:",v])
  2221. if e == "abg":
  2222. elem.config(activebackground=v)
  2223. else:
  2224. elem[e] = v
  2225. w = window_manager.get_win("FIXTURES")
  2226. #print(dir(w))
  2227. w.update_idle_task()
  2228. #tkinter.Tk.update_idletasks(w)
  2229. except Exception as e:
  2230. cprint("exc434",e)
  2231. cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
  2232. cprint(gui_menu)
  2233. menu_buff["FIX-SUB"] -= menu_buff["FIX"]
  2234. if menu_buff["FIX-SUB"]:
  2235. gui_menu.config("FIXTURES","bg","yellow")
  2236. gui_menu.config("FIXTURES","activebackground","yellow")
  2237. elif menu_buff["FIX"]:
  2238. gui_menu.config("FIXTURES","bg","orange")
  2239. gui_menu.config("FIXTURES","activebackground","orange")
  2240. else:
  2241. gui_menu.config("FIXTURES","bg","")
  2242. gui_menu.config("FIXTURES","activebackground","")
  2243. gui_menu.update("FIXTURES","{} : {}".format(menu_buff["FIX"],menu_buff["FIX-SUB"]))
  2244. menu_buff["DIM-SUB"] -= menu_buff["DIM"]
  2245. if menu_buff["DIM-SUB"]:
  2246. gui_menu.config("DIMMER","bg","yellow")
  2247. gui_menu.config("DIMMER","activebackground","yellow")
  2248. elif menu_buff["DIM"]:
  2249. gui_menu.config("DIMMER","bg","orange")
  2250. gui_menu.config("DIMMER","activebackground","orange")
  2251. else:
  2252. gui_menu.config("DIMMER","bg","")
  2253. gui_menu.config("DIMMER","activebackground","")
  2254. gui_menu.update("DIMMER","{} : {}".format(menu_buff["DIM"],menu_buff["DIM-SUB"]))
  2255. cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
  2256. def preset_rec(self,nr):
  2257. cprint("------- STORE PRESET")
  2258. data = FIXTURES.get_active()
  2259. if modes.val("REC-FX"):
  2260. PRESETS.rec(nr,data,"REC-FX")
  2261. modes.val("REC-FX",0)
  2262. else:
  2263. PRESETS.rec(nr,data)
  2264. sdata=data
  2265. PRESETS.val_presets[nr] = sdata
  2266. master._refresh_exec()
  2267. return 1
  2268. def preset_select(self,nr):
  2269. cprint("SELECT PRESET")
  2270. sdata = PRESETS.val_presets[nr]
  2271. cmd = ""
  2272. for fix in sdata:
  2273. if fix == "CFG":
  2274. continue
  2275. for attr in sdata[fix]:
  2276. #v2 = sdata[fix][attr]["VALUE"]
  2277. #v2_fx = sdata[fix][attr]["FX"]
  2278. #print( self.data.elem_attr)
  2279. #if fix in self.elem_attr:
  2280. # if attr in self.elem_attr[fix]:
  2281. # elem = self.elem_attr[fix][attr]
  2282. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  2283. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2284. #elem["bg"] = "yellow"
  2285. def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  2286. t_start = time.time()
  2287. if xfade is None and FADE._is():
  2288. xfade = FADE.val()
  2289. if ptfade is None and FADE_move._is():
  2290. ptfade = FADE_move.val()
  2291. cprint("GO PRESET FADE",nr,val)
  2292. rdata = PRESETS.get_raw_map(nr)
  2293. if not rdata:
  2294. return 0
  2295. cprint("???????")
  2296. cfg = PRESETS.get_cfg(nr)
  2297. cprint("''''''''")
  2298. #virtcmd = FIXTURES.get_virtual(rdata)
  2299. if not cfg:
  2300. cprint("NO CFG",cfg,nr)
  2301. return 0
  2302. xFLASH = 0
  2303. value=None
  2304. cprint("preset_go",nr,cfg)
  2305. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  2306. self.preset_select(nr)
  2307. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  2308. xFLASH = 1
  2309. xfade = 0
  2310. if type(val) is not type(None) and val == 0 :
  2311. value = "off"
  2312. if event:
  2313. if str(event.type) == "ButtonRelease" or event.type == '5' :
  2314. value = "off"
  2315. cprint("preset_go() FLUSH",value,color="red")
  2316. fcmd = FIXTURES.update_raw(rdata,update=0)
  2317. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  2318. elif not val:
  2319. cprint("preset_go() STOP",value,color="red")
  2320. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  2321. fcmd = FIXTURES.update_raw(rdata)
  2322. self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  2323. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  2324. fcmd = FIXTURES.update_raw(rdata)
  2325. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  2326. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  2327. self.refresh_exec()
  2328. self.refresh_fix()
  2329. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  2330. #print(len(self.elem_presets) )
  2331. if len(self.elem_presets) > nr: # RED BUTTON IF PRESSED
  2332. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  2333. if val:# or value:
  2334. #self.elem_presets[nr].config(borderwidth=1)
  2335. self.elem_presets[nr].config(bg="red")
  2336. else:
  2337. self._refresh_exec()
  2338. cprint("preset_go",time.time()-t_start)
  2339. def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  2340. if xfade is None and FADE._is():
  2341. xfade = FADE.val()
  2342. if ptfade is None and FADE_move._is():
  2343. ptfade = FADE_move.val()
  2344. cprint("PRESETS._preset_go() len=",len(rdata),cfg)
  2345. if xfade is None:
  2346. xfade = cfg["FADE"]
  2347. if ptfade is None:
  2348. ptfade = cfg["FADE"]
  2349. #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
  2350. #cprint(rdata,color="red")
  2351. vcmd = reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
  2352. cmd = []
  2353. delay=0
  2354. for i,v in enumerate(fcmd):
  2355. #print("go",i,v)
  2356. if xFLASH:
  2357. vcmd[i]["FLASH"] = 1
  2358. DMX = fcmd[i]["DMX"]
  2359. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  2360. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  2361. if value is not None:
  2362. vcmd[i]["VALUE"] = value
  2363. if value == "off":
  2364. if "FX2" in vcmd:
  2365. vcmd[i]["FX2"]["TYPE"] = value
  2366. if "FIX" in fcmd:
  2367. vcmd[i]["FIX"] = fcmd["FIX"]
  2368. if DMX and vcmd[i]:
  2369. vcmd[i]["DMX"] = DMX
  2370. if "VIRTUAL" in fcmd[i]:
  2371. for a in fcmd[i]["VIRTUAL"]:
  2372. DMX = fcmd[i]["VIRTUAL"][a]
  2373. if DMX and vcmd[i]:
  2374. vcmd[i]["DMX"] = DMX
  2375. if type(nr) is not type(None):
  2376. vcmd[i]["EXEC"] = str(int(nr)+1)
  2377. #cprint(vcmd[i],color="red")
  2378. cmd.append(vcmd[i])
  2379. if cmd and not modes.val("BLIND"):
  2380. jclient_send(cmd)
  2381. def render(self):
  2382. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  2383. #self.draw_input()
  2384. pass
  2385. ##draw_sub_dim
  2386. class InputEventBlocker():
  2387. def __init__(self):
  2388. self.__init = 0
  2389. self.cursor = "88888"
  2390. def set(self,el,txt):
  2391. self.e = el
  2392. self.e_txt = txt
  2393. self.cursor = "88888"
  2394. def init(self):
  2395. if self.__init == 0:
  2396. try:
  2397. self.el = tk.Button()
  2398. self.e_txt = tk.StringVar()
  2399. self.__init = 1
  2400. except Exception as e:
  2401. pirnt("init() exception",e)
  2402. def _lock(self):
  2403. global _global_short_key
  2404. _global_short_key = 0
  2405. try:master.commands.elem["S-KEY"]["bg"] = "red"
  2406. except Exception as e:cprint("exc",self,e)
  2407. def _unlock(self):
  2408. global _global_short_key
  2409. _global_short_key = 1
  2410. try:master.commands.elem["S-KEY"]["bg"] = "green"
  2411. except Exception as e:cprint("exc",self,e)
  2412. def lock(self):
  2413. self._lock()
  2414. #self.e["bg"] = "red"
  2415. #self.el.config({"background": "grey"})
  2416. #self.e.focus()
  2417. def unlock(self):
  2418. self._unlock()
  2419. #self.e["bg"] = "blue"
  2420. #self.el.config({"background": "yellow"})
  2421. #self.el.focus_set()
  2422. def event(self,event,**args):
  2423. self.init()
  2424. #print()
  2425. cprint(self,event,args)
  2426. #print("###-",self.e_txt,dir(self.e_txt))
  2427. if "S-KEY" not in master.commands.elem:
  2428. return
  2429. if "num" in dir(event):
  2430. self.lock()
  2431. if "keysym" in dir(event):
  2432. t=self.e_txt.get()
  2433. if t and t[-1] == "<":
  2434. t = t[:-1]
  2435. if event.keysym == "Return" or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  2436. self.unlock()
  2437. #self.e_txt.set(t)
  2438. cprint("filter: get()",_global_short_key,t)
  2439. t2 = t
  2440. if _global_short_key == 0:
  2441. if event.keysym == "BackSpace":
  2442. if len(t) > 1:
  2443. t2 = t[:-1]
  2444. else:
  2445. t2=""
  2446. elif event.keysym == "Escape":
  2447. t2=""
  2448. elif event.keysym == "space":
  2449. t2=t+" "
  2450. elif event.char in "äöüÄÖÜ-_,.;:#'*+~":
  2451. t2=t+event.char
  2452. elif len(event.keysym) == 1:
  2453. t2=t+event.keysym
  2454. #self.e_txt.set(t2+"<")
  2455. #time.sleep(0.2)
  2456. #_global_short_key = 1
  2457. input_event_blocker = InputEventBlocker()
  2458. from tkgui.dialog import *
  2459. dialog = Dialog()
  2460. from tkgui.draw import *
  2461. from tkgui.GUI import *
  2462. class LOAD_SHOW_AND_RESTAT():
  2463. def __init__(self,fname=""):
  2464. self.fname=fname
  2465. self.base = Base()
  2466. def cb(self,event=None,force=0):
  2467. cprint("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
  2468. if not self.fname and not force:
  2469. return 0
  2470. if self.base.show_name == self.fname and not force:
  2471. cprint("filename is the same",self.fname)
  2472. return 0
  2473. if not force:
  2474. self.base._set(self.fname)
  2475. cprint("LOAD SHOW:",event,self.fname)
  2476. cprint(sys.executable, os.path.abspath(__file__), *sys.argv)
  2477. os.execl("/usr/bin/python3", "/opt/LibreLight/Xdesk/_LibreLightDesk.py", "_LibreLightDesk.py")
  2478. sys.exit()
  2479. class PopupList():
  2480. def __init__(self,name="<NAME>",master=0,width=400,height=450,exit=1,left=_POS_LEFT+400,top=_POS_TOP+100,cb=None,bg="black"):
  2481. self.name = name
  2482. self.frame = None
  2483. self.bg=bg
  2484. self.cb = cb
  2485. if cb is None:
  2486. cb = DummyCallback #("load_show_list.cb")
  2487. #w = Window(self.name,master=master,width=width,height=height,exit=exit,left=left,top=top,cb=cb)
  2488. args = {"title":self.name,"master":master,"width":width,"height":height,"exit":exit,"left":left,"top":top,"cb":cb}
  2489. w = Window(args)
  2490. self.w = w
  2491. w.show()
  2492. def sframe(self,line1="<line1>",line2="<line2>",data=[]):
  2493. xframe=self.w.tk
  2494. if self.bg:
  2495. xframe.configure(bg=self.bg)
  2496. self.w.tk.configure(bg=self.bg)
  2497. c=0
  2498. r=0
  2499. b = tk.Label(xframe,bg="grey",text=line1,anchor="w")
  2500. b.pack(side="top",expand=0,fill="x" )
  2501. b = tk.Label(xframe,bg="grey",text=line2,anchor="w")
  2502. b.pack(side="top",expand=0,fill="x" )
  2503. b = tk.Label(xframe,bg="black",fg="black",text="")
  2504. if self.bg:
  2505. b.configure(fg=self.bg)
  2506. b.configure(bg=self.bg)
  2507. b.pack(side="top")
  2508. b = tk.Entry(xframe,width=10,text="")#,anchor="w")
  2509. b.pack(side="top",expand=0,fill="x")
  2510. b.focus()
  2511. #frame = tk.Frame(xframe,heigh=2800)
  2512. #frame.pack(fill=tk.BOTH,expand=1, side=tk.TOP)
  2513. frame = ScrollFrame(xframe,width=300,height=500,bd=1,bg=self.bg)
  2514. #frame.pack(side="left") #fill=tk.BOTH,expand=1, side=tk.TOP)
  2515. #self.frame = frame
  2516. self.w.tk.state(newstate='normal')
  2517. self.w.tk.attributes('-topmost',True)
  2518. return frame
  2519. class DummyCallback():
  2520. def __init__(self,name="name"):
  2521. self.name = name
  2522. def cb(self,event=None):
  2523. cprint("DummyCallback.cb",[self.name,event])
  2524. class BaseCallback():
  2525. def __init__(self,cb=None,**args):
  2526. self._cb=cb
  2527. self.args = args
  2528. def cb(self,**args):
  2529. print("BaseCallback.cb()",self.args,self._cb)
  2530. if self._cb:
  2531. try:
  2532. self._cb(self.args)
  2533. except TypeError as e:
  2534. print(" TypeError",e)
  2535. self._cb()
  2536. def _load_show_list(frame,cb=None):
  2537. c=0
  2538. r=0
  2539. base = Base()
  2540. for i in ["name","stamp"]: #,"create"]:
  2541. b = tk.Label(frame,bg="grey",text=i)
  2542. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2543. c+=1
  2544. r+=1
  2545. blist = base._list()
  2546. for i in range(10):
  2547. blist.append(["",""])
  2548. if cb is None:
  2549. cb = DummyCallback #("load_show_list.cb")
  2550. for i in blist:
  2551. #print(i)
  2552. c=0
  2553. for j in i:
  2554. bg="lightgrey"
  2555. dbg="lightgrey"
  2556. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2557. dbg = "lightgreen"
  2558. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2559. dbg = "green"
  2560. if c > 0:
  2561. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2562. b.config(activebackground=dbg)
  2563. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2564. else:
  2565. if base.show_name == i[0]:
  2566. bg="green"
  2567. _cb = cb(j)
  2568. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2569. if base.show_name == i[0]:
  2570. b.config(activebackground=bg)
  2571. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2572. c+=1
  2573. r+=1
  2574. def _parse_fixture_name(name):
  2575. out = ["FIX","MAN","CH","PATH"]
  2576. if name.count(".") == 2:
  2577. m,n,e = name.split(".")
  2578. out = [n,m,"0",name]
  2579. elif name.count("_") == 2:
  2580. name,e = name.split(".")
  2581. m,n,c = name.split("_")
  2582. out = [n,m,c,name]
  2583. else:
  2584. out = [name]
  2585. return out
  2586. def online_help(page):
  2587. print("INIT:online_help",page)
  2588. try:
  2589. page = page.replace("&","")
  2590. page = page.replace("=","")
  2591. page = page.replace("/","")
  2592. import webbrowser
  2593. def _cb():
  2594. print("online_help",page)
  2595. webbrowser.open("http://librelight.de/wiki/doku.php?id="+page )
  2596. return _cb
  2597. except Exception as e:
  2598. print("online_help Exception",e)
  2599. raise e
  2600. def _cb():
  2601. print("error online_help",page)
  2602. return _cb
  2603. def _import_fixture_list(frame,cb=None,master=None,bg="black"):
  2604. frame.configure(bg=bg)
  2605. c=0
  2606. r=0
  2607. base = Base()
  2608. for i in ["source","name","manufacturer","channel's","file","path"]: #,"create"]:
  2609. b = tk.Label(frame,bg="grey",text=i)
  2610. b.grid(row=r, column=c, sticky=tk.W) #+tk.E)
  2611. c+=1
  2612. r+=1
  2613. blist = [] #base._list()
  2614. path = "/home/user/LibreLight/show"
  2615. for sname in os.listdir(path):
  2616. try:
  2617. fname = path+"/"+sname+"/patch.sav"
  2618. if os.path.isfile(fname):
  2619. f = open(fname)
  2620. lines = f.readlines()
  2621. f.close()
  2622. for line in lines:
  2623. line = line.split("\t")
  2624. line = json.loads(line[2])
  2625. print(line)
  2626. name = line["NAME"]
  2627. blist.append([name,fname,path])
  2628. print(":",i,name,fname)
  2629. except Exception as e:
  2630. print("exception",e)
  2631. if not blist:
  2632. #blist.append(["MAC-500","martin","Demo"])
  2633. #blist.append(["MAC-2000","martin","Demo"])
  2634. #blist.append(["MAC-VIPER","martin","Demo"])
  2635. #blist.append(["SPARX-7","JB","Demo"])
  2636. #blist.append(["SPARX-11","JB","Demo"])
  2637. #blist.append(["JB-P6","JB","Demo"])
  2638. #blist.append(["JB-P7","JB","Demo"])
  2639. #blist.append(["JB-A7","JB","Demo"])
  2640. #blist.append(["TMH-12","Eurolight","Demo"])
  2641. pass
  2642. for i in range(19):
  2643. blist.append(["IMPORT-{:02}".format(i),"Eurolight","Import"])
  2644. if len(blist) < 30:
  2645. for i in range(30-len(blist)):
  2646. blist.append(["{:0>4}".format(len(blist)+i+1),"",""])
  2647. if cb is None:
  2648. cb = DummyCallback #("load_show_list.cb")
  2649. _tmp_name = ""
  2650. _tmp_flag = 0
  2651. blist=blist[:10]
  2652. for i in blist:
  2653. #print(i)
  2654. if i[0] != _tmp_name:
  2655. _tmp_flag = "#aaf"
  2656. if i[0] == "user":
  2657. _tmp_flag = "#aaf"
  2658. if i[0] == "base":
  2659. _tmp_flag = "#0f0"
  2660. c=0
  2661. for j in i:
  2662. bg="lightgrey"
  2663. dbg="lightgrey"
  2664. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2665. dbg = "lightgreen"
  2666. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2667. dbg = "green"
  2668. if _tmp_flag:
  2669. bg = "{}".format(_tmp_flag)
  2670. if c == 1:
  2671. if base.show_name == i[0]:
  2672. bg="green"
  2673. _cb2 = BaseCallback(cb=cb,args={"file":j}).cb
  2674. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb2)
  2675. if base.show_name == i[0]:
  2676. b.config(activebackground=bg)
  2677. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2678. else:#ief c > 0:
  2679. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2680. b.config(activebackground=dbg)
  2681. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2682. c+=1
  2683. r+=1
  2684. class _LOAD_FIXTURE_LIST():
  2685. def __init__(self,mode="<name>"):
  2686. self.mode = mode
  2687. def get(self,frame,cb=None,master=None,bg="black"):
  2688. frame.configure(bg=bg)
  2689. c=0
  2690. r=0
  2691. base = Base()
  2692. for i in ["source","name","manufacturer","channel's","file","path"]: #,"create"]:
  2693. b = tk.Label(frame,bg="grey",text=i)
  2694. b.grid(row=r, column=c, sticky=tk.W) #+tk.E)
  2695. c+=1
  2696. r+=1
  2697. blist = [] #base._list()
  2698. if self.mode == "USER":
  2699. try:
  2700. p = HOME+"/LibreLight/fixtures/"
  2701. ls = os.listdir(p)
  2702. ls.sort()
  2703. for l in ls:
  2704. b = _parse_fixture_name(l)
  2705. b.append(p)
  2706. b.insert(0,"user")
  2707. blist.append(b)
  2708. except Exception as e:
  2709. cprint("Exce 877 ",e)
  2710. elif self.mode == "GLOBAL":
  2711. try:
  2712. p="/opt/LibreLight/Xdesk/fixtures/"
  2713. ls = os.listdir(p )
  2714. ls.sort()
  2715. for l in ls:
  2716. b = _parse_fixture_name(l)
  2717. b.append(p)
  2718. b.insert(0,"base")
  2719. blist.append(b)
  2720. except Exception as e:
  2721. cprint("Exce 878 ",e)
  2722. elif self.mode == "IMPORT":
  2723. path = "/home/user/LibreLight/show"
  2724. for sname in os.listdir(path):
  2725. try:
  2726. fname = path+"/"+sname+"/patch.sav"
  2727. if os.path.isfile(fname):
  2728. f = open(fname)
  2729. lines = f.readlines()
  2730. f.close()
  2731. for line in lines:
  2732. line = line.split("\t")
  2733. line = json.loads(line[2])
  2734. print(line)
  2735. name = line["NAME"]
  2736. blist.append([name,fname,path])
  2737. print(":",i,name,fname)
  2738. except Exception as e:
  2739. print("exception",e)
  2740. if cb is None:
  2741. cb = DummyCallback #("load_show_list.cb")
  2742. _tmp_name = ""
  2743. _tmp_flag = 0
  2744. blist = blist[:50]
  2745. for i in blist:
  2746. #print(i)
  2747. if i[0] != _tmp_name:
  2748. _tmp_flag = "#aaf"
  2749. if i[0] == "user":
  2750. _tmp_flag = "#aaf"
  2751. if i[0] == "base":
  2752. _tmp_flag = "#0f0"
  2753. c=0
  2754. for j in i:
  2755. bg="lightgrey"
  2756. dbg="lightgrey"
  2757. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2758. dbg = "lightgreen"
  2759. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2760. dbg = "green"
  2761. if _tmp_flag:
  2762. bg = "{}".format(_tmp_flag)
  2763. if c == 1:
  2764. if base.show_name == i[0]:
  2765. bg="green"
  2766. _cb2 = BaseCallback(cb=cb,args={"file":j}).cb
  2767. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb2)
  2768. if base.show_name == i[0]:
  2769. b.config(activebackground=bg)
  2770. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2771. else:#ief c > 0:
  2772. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2773. b.config(activebackground=dbg)
  2774. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2775. c+=1
  2776. r+=1
  2777. class Fixtures():
  2778. def __init__(self):
  2779. #super().__init__()
  2780. self.base=Base()
  2781. #self.load()
  2782. self.fixtures = OrderedDict()
  2783. self.gui = GUIHandler()
  2784. def load_patch(self):
  2785. filename="patch"
  2786. #self.base._init()
  2787. d,l = self.base._load(filename)
  2788. self.fixtures = OrderedDict()
  2789. for i in l:
  2790. sdata = d[i]
  2791. new_f = OrderedDict()
  2792. #print("++++")
  2793. for k,j in sdata.items():
  2794. overide=0 # only for repair
  2795. if overide:
  2796. if k in ["TYPE","VENDOR"]: #ignor
  2797. continue
  2798. new_f[k] = j
  2799. if k =="NAME":
  2800. #print("AAAADDDDDD")
  2801. if "TYPE" not in sdata and not overide:
  2802. if len( sdata["ATTRIBUT"]) == 1:
  2803. new_f["TYPE"] = "DIMMER"
  2804. elif "PAN" in sdata["ATTRIBUT"]:
  2805. new_f["TYPE"] = "MOVER"
  2806. elif "RED" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 3:
  2807. new_f["TYPE"] = "RGB"
  2808. elif "RED" in sdata["ATTRIBUT"]:
  2809. new_f["TYPE"] = "LED"
  2810. elif "CYAN" in sdata["ATTRIBUT"]:
  2811. new_f["TYPE"] = "COLOR"
  2812. else:
  2813. new_f["TYPE"] = ""
  2814. if "VENDOR" not in sdata and not overide:
  2815. new_f["VENDOR"] = ""
  2816. #print(k,j)#,sdata)
  2817. sdata = new_f
  2818. if "ACTIVE" not in sdata:
  2819. sdata["ACTIVE"] = 0
  2820. sdata["ATTRIBUT"]["_ACTIVE"] = OrderedDict()
  2821. sdata["ATTRIBUT"]["_ACTIVE"]["NR"] = 0
  2822. sdata["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2823. sdata["ATTRIBUT"]["_ACTIVE"]["VALUE"] = 0
  2824. for attr in sdata["ATTRIBUT"]:
  2825. sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
  2826. #print("load",filename,sdata)
  2827. #if "CFG" not in sdata:
  2828. # sdata["CFG"] = OrderedDict()
  2829. self.fixtures[str(i)] = sdata
  2830. #PRESETS.label_presets = l
  2831. self.fx_off("all")
  2832. def backup_patch(self,save_as=""):
  2833. filename = "patch"
  2834. #self.fx_off("all")
  2835. data = self.fixtures
  2836. labels = {}
  2837. for k in data:
  2838. labels[k] = k
  2839. #self.base._init()
  2840. self.base._backup(filename,data,labels,save_as)
  2841. def fx_get(self,fix=None):
  2842. out={}
  2843. if not fix or fix == "all":
  2844. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2845. for fix in self.fixtures:
  2846. data = self.fixtures[fix]
  2847. for attr in data["ATTRIBUT"]:
  2848. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX"]
  2849. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX2"]
  2850. return out
  2851. def fx_off(self,fix=None):
  2852. if not fix or fix == "all":
  2853. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2854. for fix in self.fixtures:
  2855. data = self.fixtures[fix]
  2856. for attr in data["ATTRIBUT"]:
  2857. data["ATTRIBUT"][attr]["FX"] = ""
  2858. data["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  2859. def get_attr(self,fix,attr):
  2860. if fix in self.fixtures:
  2861. data = self.fixtures[fix]
  2862. if "ATTRIBUT" in data:
  2863. if attr in data["ATTRIBUT"]:
  2864. return data["ATTRIBUT"][attr]
  2865. def get_max_dmx_nr(self,fix):
  2866. max_dmx = 0
  2867. used_dmx = 0
  2868. if fix not in self.fixtures:
  2869. return (used_dmx,max_dmx)
  2870. data = self.fixtures[fix]
  2871. used_dmx = len(data["ATTRIBUT"])
  2872. for a in data["ATTRIBUT"]:
  2873. attr = data["ATTRIBUT"][a]
  2874. if "NR" in attr:
  2875. try:
  2876. _n = int(attr["NR"])
  2877. if _n > max_dmx:
  2878. max_dmx=_n
  2879. except ValueError:pass
  2880. return (used_dmx,max_dmx)
  2881. def get_dmx(self,fix,attr):
  2882. #cprint("get_dmx",[fix,attr])
  2883. if fix in self.fixtures:
  2884. data = self.fixtures[fix]
  2885. DMX = -99
  2886. if "DMX" in data:
  2887. DMX = int(data["DMX"])
  2888. if DMX < 1: # ignore attribute with DMX lower 1
  2889. return -22
  2890. else:
  2891. return -1
  2892. if "UNIVERS" in data:
  2893. if int(data["UNIVERS"]) >= 0:
  2894. DMX += (int(data["UNIVERS"])*512)
  2895. else:
  2896. return -33
  2897. adata = self.get_attr(fix,attr)
  2898. #-hier ende 8.2.22
  2899. #cprint("adata",adata,DMX)
  2900. if adata:
  2901. if "NR" in adata:
  2902. NR = adata["NR"]
  2903. if NR >= 1:
  2904. DMX+=NR-1
  2905. else:
  2906. return -44
  2907. return DMX
  2908. return -4
  2909. return -3
  2910. def update_raw(self,rdata,update=1):
  2911. cprint("update_raw",len(rdata))
  2912. cmd = []
  2913. for i,d in enumerate(rdata):
  2914. xcmd = {"DMX":""}
  2915. #print("fix:",i,d)
  2916. fix = d["FIX"]
  2917. attr = d["ATTR"]
  2918. v2 = d["VALUE"]
  2919. v2_fx = d["FX"]
  2920. if fix not in self.fixtures:
  2921. continue
  2922. sdata = self.fixtures[fix] #shortcat
  2923. ATTR = sdata["ATTRIBUT"]
  2924. sDMX = 0
  2925. if sdata["DMX"] > 0:
  2926. #print( sdata)
  2927. sDMX = (sdata["UNIVERS"]*512)+sdata["DMX"]
  2928. #sDMX =sdata["DMX"]
  2929. #else:
  2930. # continue
  2931. if attr not in ATTR:
  2932. continue
  2933. #DMX = FIXTURES.get_dmx(fix)
  2934. if ATTR[attr]["NR"] >= 0:
  2935. DMX = sDMX+ATTR[attr]["NR"]-1
  2936. xcmd["DMX"] = str(DMX)
  2937. else:
  2938. if attr == "DIM" and ATTR[attr]["NR"] < 0:
  2939. xcmd["VIRTUAL"] = {}
  2940. for a in ATTR:
  2941. if ATTR[a]["MASTER"]:
  2942. xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
  2943. #print( "VIRTUAL",xcmd)
  2944. cmd.append(xcmd)
  2945. v=ATTR[attr]["VALUE"]
  2946. if v2 is not None and update:
  2947. ATTR[attr]["VALUE"] = v2
  2948. if d["FX2"] and update:
  2949. ATTR[attr]["FX2"] = d["FX2"]
  2950. #self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
  2951. text = str(attr)+' '+str(round(v,2))
  2952. #self.gui.update(fix,attr,args={"text":text})
  2953. #print("END 5454 _=_=_=_=_==_")
  2954. #cprint("update_raw",cmd,color="red")
  2955. return cmd
  2956. def encoder(self,fix,attr,xval="",xfade=0,xdelay=0,blind=0):
  2957. _blind = 0
  2958. if modes.val("BLIND"):
  2959. _blind = 1
  2960. if blind:
  2961. _blind = 1
  2962. if not _blind:
  2963. cprint("FIXTURES.encoder",fix,attr,xval,xfade,color="yellow")
  2964. if attr == "CLEAR":
  2965. self.clear()
  2966. return 0
  2967. if attr == "ALL":
  2968. x=self.select(fix,attr,mode="toggle")
  2969. return x
  2970. if attr == "INV-ATTR":
  2971. cprint("-x-x-x-x-x-x-x-X-")
  2972. x=self.select(fix,attr,mode="swap")
  2973. #x=self.select(fix,"ALL",mode="swap")
  2974. master.refresh_fix()
  2975. return x
  2976. if attr == "INV-FIX":
  2977. cprint("-x-x-x-x-x-x-x-x-")
  2978. x=self.select(fix,attr,mode="swap")
  2979. #x=self.select(fix,"ALL",mode="swap")
  2980. return x
  2981. out = []
  2982. if fix not in self.fixtures:
  2983. cprint(" activate Fixture in fixture list on encoder click ")
  2984. ii =0
  2985. delay=0
  2986. sstart = time.time()
  2987. cprint("-->A HIER <--")
  2988. sub_data = []
  2989. for _fix in self.fixtures:
  2990. ii+=1
  2991. data = self.fixtures[_fix]
  2992. if "-FINE" in attr.upper():
  2993. continue
  2994. elif (attr in data["ATTRIBUT"] ) and "-FINE" not in attr.upper() :
  2995. if xval == "click":
  2996. self.select(_fix,attr,mode="on")
  2997. elif data["ATTRIBUT"][attr]["ACTIVE"]:
  2998. if _fix:
  2999. sub_data.append([_fix,attr,xval,xfade,delay])
  3000. if DELAY._is():
  3001. delay += DELAY.val()/100
  3002. sub_jdata = []
  3003. for dd in sub_data:
  3004. #print("---",len(sub_data),end="")
  3005. #self.encoder(fix,attr,xval,xfade,delay)
  3006. _x123 = self.encoder(dd[0],dd[1],dd[2],dd[3],dd[4],blind=1)
  3007. sub_jdata.append(_x123)
  3008. if sub_jdata:
  3009. cprint("--- SEND MASTER ENCODER:",len(sub_data),sub_data[0],"... _blind:",_blind)#,end="")
  3010. jclient_send(sub_jdata)
  3011. jdata=[{"MODE":ii}]
  3012. cprint("-->B HIER <--")
  3013. jclient_send(jdata)
  3014. return 0
  3015. data = self.fixtures[fix]
  3016. if xval == "click":
  3017. #cprint(data)
  3018. return self.select(fix,attr,mode="toggle")
  3019. v2=data["ATTRIBUT"][attr]["VALUE"]
  3020. change=0
  3021. increment = 5 #4.11
  3022. jdata = {"MODE":"ENC"}
  3023. if xval == "++":
  3024. v2+= increment
  3025. jdata["INC"] = increment
  3026. change=1
  3027. elif xval == "--":
  3028. jdata["INC"] = increment*-1
  3029. v2-= increment
  3030. change=1
  3031. elif xval == "+":
  3032. increment = 0.25 #.5
  3033. v2+= increment
  3034. jdata["INC"] = increment
  3035. change=1
  3036. elif xval == "-":
  3037. increment = 0.25 #.5
  3038. jdata["INC"] = increment*-1
  3039. v2-= increment
  3040. change=1
  3041. elif type(xval) is int or type(xval) is float:
  3042. v2 = xval
  3043. change=1
  3044. if v2 < 0:
  3045. v2=0
  3046. elif v2 > 256:
  3047. v2=256
  3048. jdata["VALUE"] = round(v2,4)
  3049. jdata["FIX"] = fix
  3050. jdata["ATTR"] = attr
  3051. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  3052. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  3053. out = {}
  3054. if change:
  3055. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  3056. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  3057. data["ATTRIBUT"][attr]["VALUE"] = round(v2,4)
  3058. jdata["FADE"] = 0
  3059. if xfade:
  3060. jdata["FADE"] = xfade
  3061. if xdelay:
  3062. #if attr not in ["PAN","TILT"] and 1:
  3063. jdata["DELAY"] = xdelay
  3064. if not _blind:
  3065. jdata = [jdata]
  3066. #print("ENC",jdata)
  3067. jclient_send(jdata)
  3068. time.sleep(0.001)
  3069. return jdata
  3070. return v2
  3071. def get_active(self):
  3072. cprint("get_active",self)
  3073. CFG = OrderedDict()
  3074. sdata = OrderedDict()
  3075. sdata["CFG"] = CFG # OrderedDict()
  3076. sdata["CFG"]["FADE"] = FADE.val()
  3077. sdata["CFG"]["DEALY"] = 0
  3078. for fix in self.fixtures:
  3079. data = self.fixtures[fix]
  3080. for attr in data["ATTRIBUT"]:
  3081. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  3082. continue
  3083. if fix not in sdata:
  3084. sdata[fix] = {}
  3085. if attr not in sdata[fix]:
  3086. sdata[fix][attr] = OrderedDict()
  3087. if not modes.val("REC-FX"):
  3088. sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
  3089. else:
  3090. sdata[fix][attr]["VALUE"] = None
  3091. if "FX" not in data["ATTRIBUT"][attr]:
  3092. data["ATTRIBUT"][attr]["FX"] = ""
  3093. if "FX2" not in data["ATTRIBUT"][attr]:
  3094. data["ATTRIBUT"][attr]["FX2"] = {}
  3095. sdata[fix][attr]["FX"] = data["ATTRIBUT"][attr]["FX"]
  3096. sdata[fix][attr]["FX2"] = data["ATTRIBUT"][attr]["FX2"]
  3097. return sdata
  3098. def _deselect_all(self,fix=None):
  3099. cprint("FIXTURES._deselect_all()",fix,"ALL",color="yellow")
  3100. c=0
  3101. if fix in self.fixtures:
  3102. data = self.fixtures[fix]
  3103. for attr in data["ATTRIBUT"]:
  3104. #print("SELECT ALL",fix,attr)
  3105. if "-FINE" in attr.upper():
  3106. pass
  3107. else:
  3108. c+=self.select(fix,attr,mode="off",mute=1)
  3109. return c
  3110. def _select_all(self,fix=None,mode="toggle",mute=0):
  3111. if not mute:
  3112. cprint("FIXTURES._select_all()",fix,"ALL",mode,color="yellow")
  3113. c=0
  3114. if fix in self.fixtures:
  3115. data = self.fixtures[fix]
  3116. for attr in data["ATTRIBUT"]:
  3117. #print("SELECT ALL",fix,attr)
  3118. if "-FINE" in attr.upper():
  3119. continue
  3120. if mode == "toggle":
  3121. c+=self.select(fix,attr,mode="on",mute=mute)
  3122. elif mode == "swap":
  3123. if not attr.startswith("_"):
  3124. c+=self.select(fix,attr,mode="toggle",mute=mute)
  3125. if not c and mode == "toggle": # unselect all
  3126. c= self._deselect_all(fix=fix)
  3127. return c
  3128. def select(self,fix=None,attr=None,mode="on",mute=0):
  3129. if not mute:
  3130. cprint("FIXTURES.select() >>",fix,attr,mode,color="yellow")
  3131. out = 0
  3132. if fix == "SEL":
  3133. if attr.upper() == "INV-ATTR":
  3134. fixs = self.get_active()
  3135. cprint("selected:",len(fixs))
  3136. for fix in fixs:
  3137. x=self._select_all(fix=fix,mode=mode,mute=1)
  3138. return None
  3139. if fix in self.fixtures:
  3140. if attr.upper() == "ALL":
  3141. x=self._select_all(fix=fix,mode=mode)
  3142. return x
  3143. data = self.fixtures[fix]
  3144. if attr in data["ATTRIBUT"]:
  3145. if mode == "on":
  3146. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  3147. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  3148. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  3149. out = 1
  3150. elif mode == "off":
  3151. if data["ATTRIBUT"][attr]["ACTIVE"]:
  3152. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  3153. out = 1
  3154. elif mode == "toggle":
  3155. if data["ATTRIBUT"][attr]["ACTIVE"]:
  3156. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  3157. else:
  3158. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  3159. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  3160. out = 1
  3161. return out
  3162. def clear(self):
  3163. out = 0
  3164. for fix in self.fixtures:
  3165. data = self.fixtures[fix]
  3166. for attr in data["ATTRIBUT"]:
  3167. #if attr.endswith("-FINE"):
  3168. # continue
  3169. if data["ATTRIBUT"][attr]["ACTIVE"]:
  3170. out +=1
  3171. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  3172. return out
  3173. def CFG_CHECKER(sdata):
  3174. "repair CFG "
  3175. ok = 0
  3176. if "CFG" not in sdata:
  3177. sdata["CFG"] = OrderedDict()
  3178. ok += 1
  3179. if "FADE" not in sdata["CFG"]:
  3180. sdata["CFG"]["FADE"] = 4
  3181. ok += 1
  3182. if "DELAY" not in sdata["CFG"]:
  3183. sdata["CFG"]["DELAY"] = 0
  3184. ok += 1
  3185. if "BUTTON" not in sdata["CFG"]:
  3186. sdata["CFG"]["BUTTON"] = "GO"
  3187. ok += 1
  3188. if "HTP-MASTER" not in sdata["CFG"]:
  3189. sdata["CFG"]["HTP-MASTER"] = 100 #%
  3190. ok += 1
  3191. if "SIZE-MASTER" not in sdata["CFG"]:
  3192. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  3193. ok += 1
  3194. if "SPEED-MASTER" not in sdata["CFG"]:
  3195. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  3196. ok += 1
  3197. if "OFFSET-MASTER" not in sdata["CFG"]:
  3198. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  3199. ok += 1
  3200. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  3201. #except:pass
  3202. return ok
  3203. class Presets():
  3204. def __init__(self):
  3205. #super().__init__()
  3206. self.base = Base()
  3207. #self.load()
  3208. self._last_copy = None
  3209. self._last_move = None
  3210. self.fx_buffer = {}
  3211. def load_presets(self):
  3212. #self._load()
  3213. filename="presets"
  3214. #self.base._init()
  3215. d,l = self.base._load(filename)
  3216. for i in d:
  3217. sdata = d[i]
  3218. ok = CFG_CHECKER(sdata)
  3219. self.val_presets = d
  3220. self.label_presets = l
  3221. def check_cfg(self,nr=None):
  3222. cprint("PRESETS.check_cfg()",nr)#,color="red")
  3223. ok = 0
  3224. if nr is not None:
  3225. if nr in self.val_presets:
  3226. sdata = self.val_presets[nr]
  3227. ok += self._check_cfg(sdata)
  3228. else:
  3229. cprint("nr not in data ",nr,color="red")
  3230. else:
  3231. for nr in self.val_presets:
  3232. sdata = self.val_presets[nr]
  3233. ok += self._check_cfg(sdata)
  3234. return ok
  3235. def _check_cfg(self,sdata):
  3236. cprint("PRESETS._check_cfg()")#,color="red")
  3237. ok = CFG_CHECKER(sdata)
  3238. if ok:
  3239. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  3240. return ok
  3241. def backup_presets(self,save_as=""):
  3242. filename = "presets"
  3243. data = self.val_presets
  3244. labels = self.label_presets
  3245. #self.base._init()
  3246. self.base._backup(filename,data,labels,save_as)
  3247. def get_cfg(self,nr):
  3248. cprint("PRESETS.get_cfg()",nr)
  3249. self.check_cfg(nr)
  3250. if nr not in self.val_presets:
  3251. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  3252. return {}
  3253. if "CFG" in self.val_presets[nr]:
  3254. return self.val_presets[nr]["CFG"]
  3255. def clean(self,nr):
  3256. if nr not in self.val_presets:
  3257. self.val_presets[nr] = OrderedDict()
  3258. #self.val_presets[nr]["VALUE"] = 0
  3259. #self.val_presets[nr]["FX"] = ""
  3260. sdata = self.val_presets[nr]
  3261. for fix in sdata:
  3262. #print("exec.clear()",nr,fix,sdata[fix])
  3263. for attr in sdata[fix]:
  3264. row = sdata[fix][attr]
  3265. if fix == "CFG":
  3266. continue
  3267. if "VALUE" not in row:
  3268. row["VALUE"] = None
  3269. if "FX" not in row:
  3270. row["FX"] = ""
  3271. if "FX2" not in row:
  3272. row["FX2"] = OrderedDict()
  3273. elif row["FX2"]:
  3274. for k in ["SIZE","SPEED","START","OFFSET"]:
  3275. row["FX2"][k] = int( row["FX2"][k] )
  3276. row["FX"] = ""
  3277. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  3278. #"off:0:0:0:16909:-:"
  3279. x = row["FX"].split(":")
  3280. cprint("-fx",x,len(x))
  3281. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  3282. if len(x) >= 6:
  3283. row["FX2"]["TYPE"] = x[0]
  3284. row["FX2"]["SIZE"] = int(x[1])
  3285. row["FX2"]["SPEED"] = int(x[2])
  3286. row["FX2"]["START"] = int(x[3])
  3287. row["FX2"]["OFFSET"] = int(x[4])
  3288. row["FX2"]["BASE"] = x[5]
  3289. row["FXOLD"] = row["FX"]
  3290. row["FX"] = ""
  3291. #cprint("exec.clear()",nr,fix,row)
  3292. def get_raw_map(self,nr):
  3293. self.clean(nr)
  3294. cprint("get_raw_map",nr)
  3295. sdata = self.val_presets[nr]
  3296. cmd = ""
  3297. out = []
  3298. dmx=-1
  3299. for fix in sdata:
  3300. if fix == "CFG":
  3301. #print("CFG",nr,sdata[fix])
  3302. continue
  3303. for attr in sdata[fix]:
  3304. x = {}
  3305. #print("RAW",attr)
  3306. x["FIX"] = fix
  3307. x["ATTR"] = attr
  3308. x["VALUE"] = sdata[fix][attr]["VALUE"]
  3309. x["FX"] = sdata[fix][attr]["FX"]
  3310. x["FX2"] = sdata[fix][attr]["FX2"]
  3311. #x["DMX"] = sdata[fix][attr]["NR"]
  3312. out.append(x)
  3313. return out
  3314. def get_btn_txt(self,nr):
  3315. sdata=self.val_presets[nr]
  3316. BTN="go"
  3317. if "CFG" in sdata:
  3318. if "BUTTON" in sdata["CFG"]:
  3319. BTN = sdata["CFG"]["BUTTON"]
  3320. _label = self.label_presets[nr] # = label
  3321. #txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  3322. #txt=str(nr+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+_label
  3323. txt="{} {} {}\n{}".format(nr+1,BTN,len(sdata)-1,_label)
  3324. cprint("get_btn_txt",nr,[txt])
  3325. return txt
  3326. def _btn_cfg(self,nr,txt=None):
  3327. if nr not in self.val_presets:
  3328. return ""
  3329. if "CFG" not in self.val_presets[nr]:
  3330. self.val_presets[nr]["CFG"] = OrderedDict()
  3331. return self.val_presets[nr]["CFG"]
  3332. def btn_cfg(self,nr,txt=None):
  3333. if nr not in self.val_presets:
  3334. return ""
  3335. if "CFG" not in self.val_presets[nr]:
  3336. self.val_presets[nr]["CFG"] = OrderedDict()
  3337. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  3338. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3339. if type(txt) is str:
  3340. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  3341. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  3342. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3343. master._refresh_exec(nr=nr)
  3344. cprint("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  3345. return self.val_presets[nr]["CFG"]["BUTTON"]
  3346. def label(self,nr,txt=None):
  3347. if nr not in self.label_presets:
  3348. return ""
  3349. if type(txt) is str:
  3350. self.label_presets[nr] = txt
  3351. cprint("set label",nr,[txt])
  3352. cprint("??? ?? set label",nr,[txt])
  3353. return self.label_presets[nr]
  3354. def clear_move(self):
  3355. cprint("PRESETS.clear_move()",end=" ")
  3356. self.clear_copy()
  3357. def clear_copy(self):
  3358. cprint("PRESETS.clear_copy()",end=" ")
  3359. if self._last_copy is not None:
  3360. cprint("=OK=",color="red")
  3361. self._last_copy = None
  3362. else:
  3363. cprint("=NONE=",color="green")
  3364. def copy(self,nr,overwrite=1):
  3365. cprint("PRESETS._copy",nr,"last",self._last_copy)
  3366. if nr >= 0:
  3367. if self._last_copy is not None:
  3368. if modes.val("COPY"):
  3369. modes.val("COPY",3)
  3370. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  3371. return ok #ok
  3372. else:
  3373. if modes.val("COPY"):
  3374. modes.val("COPY",2)
  3375. self._last_copy = nr
  3376. cprint("PRESETS.copy START ",color="red")
  3377. return 0
  3378. return 1 # on error reset move
  3379. def _copy(self,nr_from,nr_to,overwrite=1):
  3380. cprint("PRESETS._copy",nr_from,"to",nr_to)
  3381. self.check_cfg(nr_from)
  3382. if type(self._last_copy) is None:
  3383. cprint("PRESETS._copy last nr is None",color="red")
  3384. return 0
  3385. cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
  3386. if nr_from in self.val_presets and nr_to in self.val_presets:
  3387. fdata = self.val_presets[nr_from]
  3388. tdata = self.val_presets[nr_to]
  3389. #cprint(fdata)
  3390. flabel = self.label_presets[nr_from]
  3391. tlabel = self.label_presets[nr_to]
  3392. self.val_presets[nr_to] = copy.deepcopy(fdata)
  3393. self.label_presets[nr_to] = flabel
  3394. if not overwrite: #default
  3395. cprint("overwrite",overwrite)
  3396. self.val_presets[nr_from] = copy.deepcopy(tdata)
  3397. self.label_presets[nr_from] = tlabel
  3398. #self.label_presets[nr_from] = "MOVE"
  3399. self.clear_copy()
  3400. cprint("PRESETS.copy OK",color="green")
  3401. return 1
  3402. def move(self,nr):
  3403. cprint("PRESETS.move",self._last_copy,"to",nr)
  3404. if nr >= 0:
  3405. last = self._last_copy
  3406. if modes.val("MOVE"):
  3407. modes.val("MOVE",2)
  3408. ok= self.copy(nr,overwrite=0)
  3409. if ok and last >= 0:
  3410. if modes.val("MOVE"):
  3411. modes.val("MOVE",3)
  3412. cprint("PRESETS.move OK",color="red")
  3413. #self.delete(last)
  3414. return ok,nr,last #ok
  3415. return 0,nr,last # on error reset move
  3416. def delete(self,nr):
  3417. cprint("PRESETS.delete",nr)
  3418. ok=0
  3419. if nr in self.val_presets:
  3420. self.val_presets[nr] = OrderedDict()
  3421. self.label_presets[nr] = "-"
  3422. ok = 1
  3423. self.check_cfg(nr)
  3424. return ok
  3425. def rec(self,nr,data,arg=""):
  3426. cprint("rec",self,"rec()",len(data),arg)
  3427. self.check_cfg(nr)
  3428. self._check_cfg(data) #by ref
  3429. odata=self.val_presets[nr]
  3430. #print("odata",odata)
  3431. if "CFG" in odata:
  3432. if "BUTTON" in odata["CFG"]:
  3433. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  3434. self.val_presets[nr] = data
  3435. return 1
  3436. class FixtureEditor():
  3437. def __init__(self,dmx=1):
  3438. pass
  3439. self.elem=[]
  3440. self.dmx=dmx
  3441. cprint("init FixtureEditor",dmx)
  3442. def event(self,a1="",a2=""):
  3443. cprint([self.dmx,a1,a2])
  3444. j=[]
  3445. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
  3446. j.append(jdata)
  3447. jclient_send(j)
  3448. class MasterWing():
  3449. def __init__(self,dmx=1):
  3450. pass
  3451. self.elem=[]
  3452. self.dmx=dmx
  3453. cprint("init MasterWing",dmx)
  3454. def event(self,a1="",a2=""):
  3455. cprint([self.dmx,a1,a2])
  3456. jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
  3457. j=[]
  3458. j.append(jdata)
  3459. jclient_send(j)
  3460. class BufferVar():
  3461. def __init__(self,elem):
  3462. self.elem = elem
  3463. def change_dmx(self,event=""):
  3464. nr=1
  3465. txt=""
  3466. def cb(data):
  3467. txt = data["Value"]
  3468. dialog._cb = _cb
  3469. dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
  3470. cprint("change_dmx",[event,self])
  3471. lf_nr = 0
  3472. from tkinter import PhotoImage
  3473. _shift_key = 0
  3474. class Window():
  3475. def __init__(self,args): #title="title",master=0,width=100,height=100,left=None,top=None,exit=0,cb=None,resize=1):
  3476. global lf_nr
  3477. self.args = {"title":"title","master":0,"width":100,"height":100,"left":None,"top":None,"exit":0,"cb":None,"resize":1}
  3478. self.args.update(args)
  3479. cprint("Window.init()",id(self.args),color="yellow")
  3480. cprint(" ",self.args,color="yellow")
  3481. ico_path="./icon/"
  3482. self.cb = cb
  3483. if self.args["master"]:
  3484. self.tk = tkinter.Tk()
  3485. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3486. self.tk.withdraw() # do not draw
  3487. self.tk.resizable(self.args["resize"],self.args["resize"])
  3488. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  3489. cprint(defaultFont)
  3490. defaultFont.configure(family="FreeSans",
  3491. size=10,
  3492. weight="bold")
  3493. # MAIN MENUE
  3494. try:
  3495. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"main.png"))
  3496. except Exception as e:
  3497. cprint("Exception GUIWindow.__init__",e)
  3498. else:
  3499. # addtional WINDOW
  3500. self.tk = tkinter.Toplevel()
  3501. self.tk.iconify()
  3502. #self.tk.withdraw() # do not draw
  3503. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3504. self.tk.resizable(self.args["resize"],self.args["resize"])
  3505. try:
  3506. if "COLORPICKER" in self.args["title"]:
  3507. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"picker.png"))
  3508. elif "ENCODER" in self.args["title"]:
  3509. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"enc.png"))
  3510. elif "EXEC" in self.args["title"]:
  3511. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  3512. elif "FX" in self.args["title"]:
  3513. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"fx.png"))
  3514. else:
  3515. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png"))
  3516. except Exception as e:
  3517. cprint("Exception on load window icon",self.args["title"])
  3518. cprint("Exception:",e)
  3519. #time.sleep(3)
  3520. self.tk.deiconify()
  3521. self.tk["bg"] = "black"
  3522. self.tk.bind("<Button>",self.callback)
  3523. self.tk.bind("<Key>",self.callback)
  3524. self.tk.bind("<KeyRelease>",self.callback)
  3525. self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3526. lf_nr+=1
  3527. #self.tk.geometry("270x600+0+65")
  3528. geo ="{}x{}".format(self.args["width"],self.args["height"])
  3529. if self.args["left"] is not None:
  3530. geo += "+{}".format(self.args["left"])
  3531. if self.args["top"] is not None:
  3532. geo += "+{}".format(self.args["top"])
  3533. #self._event_clear = Xevent(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
  3534. self.tk.geometry(geo)
  3535. self.show()
  3536. def update_idle_task(self):
  3537. if INIT_OK:
  3538. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3539. pass
  3540. def close_app_win(self,event=None):
  3541. cprint("close_app_win",self,event,self.args["title"],color="red")
  3542. if exit:
  3543. if self.title == "MAIN":
  3544. save_window_position()
  3545. save_window_position()
  3546. self.tk.destroy()
  3547. try:
  3548. self.cb("<exit>").cb()
  3549. except Exception as e:
  3550. cprint("EXCETPION: close_app_win",e,self,color="red")
  3551. def title(self,title=None):
  3552. if title is None:
  3553. return self.tk.title()
  3554. else:
  3555. #return self.tk.title(title)
  3556. self.args["title"] = title
  3557. return self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3558. def show(self):
  3559. self.tk.deiconify()
  3560. pass
  3561. def mainloop(self):
  3562. #save_window_position_loop() #like autosave
  3563. try:
  3564. self.tk.mainloop()
  3565. finally:
  3566. self.tk.quit()
  3567. def callback(self,event,data={}):#value=255):
  3568. global _global_short_key
  3569. sstart = time.time()
  3570. #time.sleep(0.1)
  3571. if not _global_short_key:
  3572. #cprint("<GLOBAL-GUI-EVENT-DISABLED>",event,color="red")
  3573. return 1
  3574. global _shift_key
  3575. #cprint("<GUI>",event,color="yellow")
  3576. value = 255
  3577. if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
  3578. value = 0
  3579. cprint("<GUI>",event.state,data,value,[event.type,event.keysym],color="yellow")
  3580. #print(event)
  3581. if "state" in dir(event) and "keysym" in dir(event):
  3582. #print([event.state,event.keysym,event.type])
  3583. if event.state == 4 and str(2) == str(event.type): # strg + s
  3584. if str(event.keysym) == "s":
  3585. cprint("tTtT ReW "*20)
  3586. #print("numbersign !!")
  3587. PRESETS.backup_presets()
  3588. FIXTURES.backup_patch()
  3589. save_window_position()
  3590. e = master.setup_elem["SAVE\nSHOW"]
  3591. #print(e)
  3592. b = BLINKI(e)
  3593. b.blink()
  3594. if str(event.keysym) == "c":
  3595. PRESETS.backup_presets()
  3596. FIXTURES.backup_patch()
  3597. save_window_position()
  3598. #self.elem.config(activebackground="lightgrey")
  3599. LOAD_SHOW_AND_RESTAT("").cb(force=1)
  3600. #cprint("oipo "*10,round(int(time.time()-sstart)*1000,2))
  3601. return
  3602. if "keysym" in dir(event):
  3603. if "Escape" == event.keysym:
  3604. FIXTURES.clear()
  3605. modes.val("ESC",1)
  3606. master.refresh_fix()
  3607. elif event.keysym in ["Shift_L","Shift_R"]:
  3608. #cprint(event.type)
  3609. if "KeyRelease" in str(event.type) or str(event.type) in ["3"]:
  3610. _shift_key = 0
  3611. else:
  3612. _shift_key = 1
  3613. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3614. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3615. global _ENCODER_WINDOW
  3616. try:
  3617. if _shift_key:
  3618. _ENCODER_WINDOW.title("SHIFT/FINE ")
  3619. else:
  3620. _ENCODER_WINDOW.title("ENCODER")
  3621. except Exception as e:
  3622. cprint("exc9800",e)
  3623. elif event.keysym in "ebfclrms" and value:
  3624. if "e" == event.keysym:
  3625. modes.val("EDIT",1)
  3626. elif "b" == event.keysym:
  3627. modes.val("BLIND",1)
  3628. elif "f" == event.keysym:
  3629. modes.val("FLASH",1)
  3630. elif "c" == event.keysym:
  3631. modes.val("CFG-BTN",1)
  3632. elif "l" == event.keysym:
  3633. modes.val("LABEL",1)
  3634. elif "r" == event.keysym:
  3635. modes.val("REC",1)
  3636. elif "m" == event.keysym:
  3637. x=modes.val("MOVE",1)
  3638. if not x:
  3639. PRESETS.clear_move()
  3640. elif "s" == event.keysym:
  3641. modes.val("SELECT",1)
  3642. elif event.keysym in ["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]:
  3643. nr = int( event.keysym[1:]) # F:1-12
  3644. nr = nr-1+81
  3645. cprint("F-KEY",value,nr,event.keysym)
  3646. #print(event)
  3647. master.preset_go(nr-1,xfade=None,val=value)
  3648. elif event.keysym in ["1","2","3","4","5","6","7","8","9","0"]:
  3649. nr = int( event.keysym)
  3650. if nr == 0:
  3651. nr = 10
  3652. nr = nr-1+161
  3653. cprint("NUM-KEY",value,nr)
  3654. master.preset_go(nr-1,xfade=None,val=value)
  3655. elif "numbersign" == event.keysym and value: # is char "#"
  3656. cprint("numbersign !!")
  3657. PRESETS.backup_presets()
  3658. FIXTURES.backup_patch()
  3659. save_window_position()
  3660. for e in master.setup_cmd:
  3661. cprint(e)
  3662. e = master.setup_elem["SAVE\nSHOW"]
  3663. cprint(e)
  3664. b = BLINKI(e)
  3665. b.blink()
  3666. #e = Xevent(fix=0,elem=None,attr="SAVE\nSHOW",mode="SETUP")
  3667. #e.cb(event=event)
  3668. elif "End" == event.keysym:
  3669. FIXTURES.fx_off("all")
  3670. CONSOLE.fx_off("all")
  3671. CONSOLE.flash_off("all")
  3672. elif "Delete" == event.keysym:
  3673. #PRESETS.delete(nr)
  3674. if value:
  3675. modes.val("DEL",1)
  3676. cprint("oipo "*10,round(int(time.time()-sstart)*1000,2))
  3677. class WindowManager():
  3678. def __init__(self):
  3679. self.windows = {}
  3680. self.obj = {}
  3681. self.nr= 0
  3682. self.first=""
  3683. self.window_init_buffer = {}
  3684. def update(self,w,name="",obj=None):
  3685. name = str(name)
  3686. for k in self.windows:
  3687. if k == name:
  3688. self.windows[str(name)] = w
  3689. self.obj[str(name)] = obj
  3690. def new(self,w,name="",obj=None,wcb=None):
  3691. name = str(name)
  3692. if wcb and name:
  3693. self.window_init_buffer[name] = wcb
  3694. if not self.first:
  3695. if name:
  3696. self.first = name
  3697. else:
  3698. self.first = str(self.nr)
  3699. if w:
  3700. w.tk.state(newstate='normal')
  3701. w.tk.attributes('-topmost',True)
  3702. if name:
  3703. self.windows[str(name)] = w
  3704. self.obj[str(name)] = obj
  3705. else:
  3706. self.windows[str(self.nr)] = w
  3707. self.obj[str(self.nr)] = obj
  3708. self.nr+=1
  3709. def mainloop(self):
  3710. self.windows[self.first].mainloop()
  3711. def get_win(self,name):
  3712. cprint(self,".get_win(name) =",name)
  3713. name = str(name)
  3714. if name in self.windows:
  3715. out = self.windows[name]
  3716. cprint(out)
  3717. return out
  3718. def get(self,name):
  3719. return get_win(name)
  3720. def get_obj(self,name):
  3721. name = str(name)
  3722. if name in self.windows:
  3723. out = self.obj[name]
  3724. return out
  3725. def create(self,name):
  3726. cprint( "create Window",name)
  3727. if name in self.window_init_buffer:
  3728. c = self.window_init_buffer[name]
  3729. w,obj,cb_ok = c.create()
  3730. window_manager.update(w,name,obj)
  3731. if cb_ok:
  3732. cb_ok()
  3733. resize = 1
  3734. if "resize" in c.args:
  3735. if not c.args["resize"]:
  3736. resize = 0
  3737. #if resize:
  3738. get_window_position(_filter=name,win=w)
  3739. if name in ["ENCODER"]:
  3740. global _ENCODER_WINDOW
  3741. _ENCODER_WINDOW = w
  3742. if name in ["DIMMER","FIXTURES"]:
  3743. refresher_fix.reset() # = Refresher()
  3744. def _check(self,name):
  3745. try:
  3746. self.windows[name].tk.state(newstate='normal')
  3747. return 1
  3748. except Exception as e:
  3749. cprint("exception",e,color="red")
  3750. cprint("info",name,self.windows[name],color="red")
  3751. def top(self,name):
  3752. name = str(name)
  3753. if name not in self.windows:
  3754. cprint(name,"not in self.windows",self.windows.keys())
  3755. return
  3756. if not self._check(name):
  3757. self.create(name)
  3758. self.windows[name].tk.attributes('-topmost',True)
  3759. self.windows[name].tk.attributes('-topmost',False)
  3760. self.windows[name].tk.update_idletasks()
  3761. class Console():
  3762. def __init__(self):
  3763. pass
  3764. def flash_off(self,fix):
  3765. pass#client.send("df0:alloff:::,")
  3766. def fx_off(self,fix):
  3767. cprint("Console.fx_off()",fix)
  3768. if not fix or fix == "all":
  3769. #client.send("fx0:alloff:,fxf:alloff:,")
  3770. #client.send("df0:alloff:::,")
  3771. j = []
  3772. if 0:
  3773. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  3774. j.append(jdata)
  3775. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  3776. j.append(jdata)
  3777. else:
  3778. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  3779. j.append(jdata)
  3780. jclient_send(j)
  3781. return 0
  3782. def test_1():
  3783. #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
  3784. pass
  3785. window_manager = WindowManager()
  3786. CONSOLE = Console()
  3787. PRESETS = Presets()
  3788. FIXTURES = Fixtures()
  3789. def LOAD_SHOW():
  3790. PRESETS.load_presets()
  3791. FIXTURES.load_patch()
  3792. #master._refresh_fix()
  3793. #master._refresh_exec()
  3794. LOAD_SHOW()
  3795. master = MASTER()
  3796. class Refresher():
  3797. def __init__(self):
  3798. self.time = time.time()
  3799. self.time_max = time.time()
  3800. self.time_delta = 15
  3801. self.update = 1
  3802. self.name = "name" # exec
  3803. self.cb = None #self.dummy_cb
  3804. def dummy_cb(self):
  3805. cprint(self,"dummy_cd()",time.time()-self.time)
  3806. def reset(self):
  3807. self.time = time.time()
  3808. self.update = 1
  3809. def refresh(self):
  3810. if self.update:
  3811. if self.time+self.time_delta < time.time():
  3812. self._refresh()
  3813. else:
  3814. self.time = time.time()
  3815. def _refresh(self):
  3816. cprint("_refresh()",self.name,self)
  3817. if not INIT_OK:
  3818. return
  3819. self.time_max = time.time()
  3820. self.time = time.time()
  3821. self.update = 0
  3822. try:
  3823. if self.cb:
  3824. self.cb()
  3825. else:
  3826. self.dummy_cb()
  3827. except Exception as e:
  3828. cprint("_refresh except:",e,"cb:",self.cb)
  3829. traceback.print_exc()
  3830. cprint()
  3831. cprint("t=",self.time_max- time.time())
  3832. def loop(self,args={}):
  3833. while 1:
  3834. try:
  3835. if INIT_OK:
  3836. self.refresh()
  3837. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3838. except Exception as e:
  3839. cprint("loop exc",e)
  3840. traceback.print_exc()
  3841. cprint("== cb EXCEPT",e,color="red")
  3842. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  3843. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  3844. time.sleep(0.2)
  3845. print("main",__name__)
  3846. __run_main = 0
  3847. if __name__ == "__main__":
  3848. __run_main = 1
  3849. else:
  3850. import __main__
  3851. if "unittest" not in dir(__main__):
  3852. __run_main = 1
  3853. refresher_fix = Refresher()
  3854. refresher_fix.time_delta = 0.50
  3855. refresher_fix.name = "fix"
  3856. refresher_fix.reset()
  3857. refresher_fix.cb = master._refresh_fix
  3858. refresher_exec = Refresher()
  3859. refresher_exec.time_delta = 10 #0
  3860. refresher_exec.name = "exec"
  3861. refresher_exec.reset()
  3862. refresher_exec.cb = master._refresh_exec
  3863. def loops(**args):
  3864. time.sleep(5) # wait until draw all window's
  3865. cprint("-> run loops")
  3866. thread.start_new_thread(refresher_fix.loop,())
  3867. thread.start_new_thread(refresher_exec.loop,())
  3868. class window_create_buffer():
  3869. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  3870. self.args = args.copy()
  3871. self.cls = cls
  3872. self.cb_ok = cb_ok
  3873. self.data = data
  3874. self.scroll = scroll
  3875. self.gui = gui
  3876. def create(self,hidde=0):
  3877. cprint()
  3878. cprint()
  3879. cprint("window_create_buffer.create()",id(self),self.args["title"],color="green")
  3880. obj = None
  3881. w = Window(self.args)
  3882. out = []
  3883. f = None
  3884. h = None
  3885. if self.scroll:
  3886. head = None
  3887. foot = None
  3888. if "head" in self.args:
  3889. head = self.args["head"]
  3890. if "foot" in self.args:
  3891. foot = self.args["foot"]
  3892. w1 = ScrollFrame(w.tk,width=self.args["width"],height=self.args["height"],foot=foot,head=head)
  3893. if type(w1) is list:
  3894. try:
  3895. h = w1[0]
  3896. f = w1[2]
  3897. except:pass
  3898. w1 = w1[1]
  3899. else:
  3900. w1 = tk.Frame(w.tk,width=self.args["width"],height=self.args["height"])
  3901. w1.pack()
  3902. try:
  3903. obj=self.cls(self.gui,w1,self.data,foot=f,head=h)
  3904. except:
  3905. obj=self.cls(self.gui,w1,self.data)
  3906. return w,obj,self.cb_ok
  3907. if __run_main:
  3908. cprint("main")
  3909. #thread.start_new_thread(refresher_fix.loop,())
  3910. #thread.start_new_thread(refresher_exec.loop,())
  3911. TOP = _POS_TOP + 15
  3912. L0 = _POS_LEFT
  3913. L1 = _POS_LEFT + 95
  3914. L2 = _POS_LEFT + 920
  3915. W1 = 810
  3916. H1 = 550
  3917. HTB = 23 # hight of the titlebar from window manager
  3918. pos_list = read_window_position()
  3919. data = []
  3920. #data.append({"text":"COMMAND"})
  3921. #data.append({"text":"CONFIG"})
  3922. data.append({"text":"PATCH"})
  3923. data.append({"text":"DIMMER"})
  3924. data.append({"text":"FIXTURES"})
  3925. data.append({"text":"EXEC","name":"EXEC-BTN"})
  3926. data.append({"text":"EXEC-WING"})
  3927. data.append({"text":"---"})
  3928. data.append({"text":"SETUP"})
  3929. data.append({"text":"COMMAND"})
  3930. data.append({"text":"LIVE"})
  3931. data.append({"text":"FX"})
  3932. data.append({"text":"ENCODER"})
  3933. data.append({"text":"COLORPICKER","name":"COLOR"})
  3934. data.append({"text":"---"})
  3935. data.append({"text":"FIXTURE-EDITOR","name":"FIX-EDIT"})
  3936. data.append({"text":"CONFIG"})
  3937. data.append({"text":"CLOCK"})
  3938. data.append({"text":"---"})
  3939. name="MAIN"
  3940. args = {"title":"MAIN","master":1,"width":80,"height":H1,"left":L0,"top":TOP,"resize":1}
  3941. geo = split_window_position(pos_list,name)
  3942. if geo:
  3943. args.update(geo)
  3944. cls = GUI_menu
  3945. cb_ok = None
  3946. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3947. window_manager.new(None,name,wcb=c)
  3948. window_manager.top(name)
  3949. gui_menu_gui = window_manager.get_win(name)
  3950. gui_menu = window_manager.get_obj(name)
  3951. master._refresh_fix()
  3952. # --------------------------------
  3953. name="EXEC"
  3954. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3955. geo = split_window_position(pos_list,name)
  3956. if geo:
  3957. args.update(geo)
  3958. data = PRESETS
  3959. cls = draw_exec #GUI_ExecWingLayout
  3960. cb_ok = None #set_exec_fader_all
  3961. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3962. window_manager.new(None,name,wcb=c)
  3963. if split_window_show(pos_list,_filter=name):
  3964. window_manager.top(name)
  3965. name="CONFIG"
  3966. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3967. geo = split_window_position(pos_list,name)
  3968. if geo:
  3969. args.update(geo)
  3970. data = []
  3971. cls = GUI_CONF
  3972. cb_ok = None
  3973. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3974. window_manager.new(None,name,wcb=c)
  3975. if split_window_show(pos_list,_filter=name):
  3976. window_manager.top(name)
  3977. name="DIMMER"
  3978. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3979. geo = split_window_position(pos_list,name)
  3980. if geo:
  3981. args.update(geo)
  3982. cls = GUI_DIM
  3983. data = FIXTURES
  3984. ok_cb=None
  3985. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3986. window_manager.new(None,name,wcb=c)
  3987. if split_window_show(pos_list,_filter=name):
  3988. window_manager.top(name)
  3989. name="FIXTURES"
  3990. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3991. geo = split_window_position(pos_list,name)
  3992. if geo:
  3993. args.update(geo)
  3994. cls = GUI_FIX
  3995. ok_cb=None
  3996. data = FIXTURES
  3997. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3998. window_manager.new(None,name,wcb=c)
  3999. if split_window_show(pos_list,_filter=name):
  4000. window_manager.top(name)
  4001. # -------------------------------
  4002. name="FIXTURE-EDITOR"
  4003. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  4004. geo = split_window_position(pos_list,name)
  4005. if geo:
  4006. args.update(geo)
  4007. data=[]
  4008. for i in range(12*6):
  4009. data.append({"text"+str(i):"test"})
  4010. cls = GUI_FixtureEditor
  4011. #cls = GUI_FaderLayout
  4012. cb_ok = None
  4013. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4014. window_manager.new(None,name,wcb=c)
  4015. #window_manager.top(name)
  4016. # -------------------------------
  4017. name="MASTER-WING"
  4018. args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220,"resize":0}
  4019. geo = split_window_position(pos_list,name)
  4020. if geo:
  4021. args.update(geo)
  4022. data=[]
  4023. for i in range(2):
  4024. data.append({"MASTER"+str(i):"MASTER"})
  4025. cls = GUI_MasterWingLayout #(w1,data)
  4026. cb_ok = None
  4027. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4028. window_manager.new(None,name,wcb=c)
  4029. if split_window_show(pos_list,_filter=name):
  4030. window_manager.top(name)
  4031. # -------------------------------
  4032. name="EXEC-WING"
  4033. args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
  4034. geo = split_window_position(pos_list,name)
  4035. if geo:
  4036. args.update(geo)
  4037. data=[]
  4038. for i in range(10*3):
  4039. data.append({"EXEC"+str(i):"EXEC"})
  4040. cls = GUI_ExecWingLayout
  4041. cb_ok = set_exec_fader_all
  4042. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  4043. window_manager.new(None,name,wcb=c)
  4044. if split_window_show(pos_list,_filter=name):
  4045. window_manager.top(name)
  4046. name="ENCODER"
  4047. args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
  4048. geo = split_window_position(pos_list,name)
  4049. if geo:
  4050. args.update(geo)
  4051. cls = draw_enc #(master,w.tk)#Xroot)
  4052. cb_ok = None
  4053. data = FIXTURES #master
  4054. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4055. window_manager.new(None,name,wcb=c)
  4056. if split_window_show(pos_list,_filter=name):
  4057. window_manager.top(name)
  4058. name = "SETUP"
  4059. args = {"title":name +" SHOW:"+master.base.show_name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP,"resize":0}
  4060. args["title"] = "SETUP SHOW:"+master.base.show_name
  4061. cls = draw_setup #(master,w.tk)
  4062. data = []
  4063. cb_ok = None
  4064. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4065. window_manager.new(None,name,wcb=c)
  4066. if split_window_show(pos_list,_filter=name):
  4067. window_manager.top(name)
  4068. name = "COMMAND"
  4069. args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":0}
  4070. cls = draw_command #(master,w.tk)
  4071. data = []
  4072. cb_ok = None
  4073. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4074. window_manager.new(None,name,wcb=c)
  4075. if split_window_show(pos_list,_filter=name):
  4076. window_manager.top(name)
  4077. name = "LIVE"
  4078. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":0}
  4079. cls = draw_live #(master,w.tk)
  4080. data = []
  4081. cb_ok = None
  4082. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4083. window_manager.new(None,name,wcb=c)
  4084. if split_window_show(pos_list,_filter=name):
  4085. window_manager.top(name)
  4086. name = "CLOCK"
  4087. args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
  4088. cclock = X_CLOCK()
  4089. cls = cclock.draw_clock
  4090. data = []
  4091. cb_ok = None
  4092. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4093. window_manager.new(None,name,wcb=c)
  4094. if split_window_show(pos_list,_filter=name):
  4095. window_manager.top(name)
  4096. name="FX"
  4097. args = {"title":name,"master":0,"width":415,"height":297,"left":L1+10+W1,"top":TOP+302,"resize":0}
  4098. geo = split_window_position(pos_list,name)
  4099. if geo:
  4100. args.update(geo)
  4101. cls = draw_fx #(master,w.tk)
  4102. data = []
  4103. cb_ok = None
  4104. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4105. window_manager.new(None,name,wcb=c)
  4106. if split_window_show(pos_list,_filter=name):
  4107. window_manager.top(name)
  4108. name="PATCH"
  4109. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP,"foot":1,"head":1}
  4110. geo = split_window_position(pos_list,name)
  4111. if geo:
  4112. args.update(geo)
  4113. cls = GUI_PATCH
  4114. data = FIXTURES
  4115. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  4116. window_manager.new(None,name,wcb=c) #,obj)
  4117. if split_window_show(pos_list,_filter=name):
  4118. window_manager.top(name)
  4119. name="COLORPICKER"
  4120. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  4121. geo = split_window_position(pos_list,name)
  4122. if geo:
  4123. args.update(geo)
  4124. #w = Window(args)
  4125. #draw_colorpicker(master,w.tk,FIXTURES,master)
  4126. cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
  4127. data = [FIXTURES,master]
  4128. cb_ok = None #FIXTURES
  4129. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4130. window_manager.new(None,name,wcb=c)
  4131. if split_window_show(pos_list,_filter=name):
  4132. window_manager.top(name)
  4133. name="TableA"
  4134. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  4135. #space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
  4136. #x=TableFrame(root=w.tk)#,left=80,top=620)
  4137. #w.show()
  4138. #data =[]
  4139. #for a in range(40):
  4140. # data.append(["E","E{}".format(a+1)])
  4141. #x.draw(data=data,head=["E","C"],config=[12,5,5])
  4142. #w=x.bframe
  4143. #window_manager.new(w,name)
  4144. master.render()
  4145. window_manager.top("Table")
  4146. #w = frame_fix #Window("OLD",master=0,width=W1,height=500,left=130,top=TOP)
  4147. #window_manager.new(w,name)
  4148. load_window_position()
  4149. thread.start_new_thread(loops,())
  4150. try:
  4151. window_manager.mainloop()
  4152. finally:
  4153. master.exit()