_LibreLightDesk.py 171 KB

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