_LibreLightDesk.py 167 KB

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