_LibreLightDesk.py 168 KB

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