_LibreLightDesk.py 161 KB

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