_LibreLightDesk.py 190 KB

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