_LibreLightDesk.py 161 KB

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