_LibreLightDesk.py 186 KB

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