_LibreLightDesk.py 149 KB

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