_LibreLightDesk.py 163 KB

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