_LibreLightDesk.py 186 KB

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