_LibreLightDesk.py 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662
  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 KEY == "DIM-SUB":
  2152. DIM =1
  2153. else:
  2154. FIX =1
  2155. else:
  2156. _buff["bg"] = "grey"
  2157. _buff["abg"] = "grey"
  2158. if "FX2" not in row: # insert FX2 excetption
  2159. row["FX2"] = OrderedDict()
  2160. if row["FX"]:
  2161. _buff["fg"] = "blue"
  2162. elif row["FX2"]:
  2163. _buff["fg"] = "red"
  2164. else:
  2165. _buff["fg"] = "black"
  2166. elem_buffer.append(_buff)
  2167. menu_buff["FIX"] += FIX
  2168. menu_buff["DIM"] += DIM
  2169. print(" =+= "*10,"refresh_fix")
  2170. try:
  2171. for row in elem_buffer:
  2172. elem = row["elem"]
  2173. if not elem:
  2174. continue
  2175. #print("<elem>",elem)
  2176. for e in row:
  2177. if e == "elem":
  2178. continue
  2179. v = row[e]
  2180. #print("confg:",["key:",e,"val:",v])
  2181. if e == "abg":
  2182. elem.config(activebackground=v)
  2183. else:
  2184. elem[e] = v
  2185. except Exception as e:
  2186. print("exc434",e)
  2187. cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
  2188. print(gui_menu)
  2189. menu_buff["FIX-SUB"] -= menu_buff["FIX"]
  2190. if menu_buff["FIX-SUB"]:
  2191. gui_menu.config("FIXTURES","bg","yellow")
  2192. gui_menu.config("FIXTURES","activebackground","yellow")
  2193. elif menu_buff["FIX"]:
  2194. gui_menu.config("FIXTURES","bg","orange")
  2195. gui_menu.config("FIXTURES","activebackground","orange")
  2196. else:
  2197. gui_menu.config("FIXTURES","bg","")
  2198. gui_menu.config("FIXTURES","activebackground","")
  2199. gui_menu.update("FIXTURES","{} : {}".format(menu_buff["FIX"],menu_buff["FIX-SUB"]))
  2200. menu_buff["DIM-SUB"] -= menu_buff["DIM"]
  2201. if menu_buff["DIM-SUB"]:
  2202. gui_menu.config("DIMMER","bg","yellow")
  2203. gui_menu.config("DIMMER","activebackground","yellow")
  2204. elif menu_buff["DIM"]:
  2205. gui_menu.config("DIMMER","bg","orange")
  2206. gui_menu.config("DIMMER","activebackground","orange")
  2207. else:
  2208. gui_menu.config("DIMMER","bg","")
  2209. gui_menu.config("DIMMER","activebackground","")
  2210. gui_menu.update("DIMMER","{} : {}".format(menu_buff["DIM"],menu_buff["DIM-SUB"]))
  2211. cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
  2212. def preset_rec(self,nr):
  2213. print("------- STORE PRESET")
  2214. data = FIXTURES.get_active()
  2215. if modes.val("REC-FX"):
  2216. PRESETS.rec(nr,data,"REC-FX")
  2217. modes.val("REC-FX",0)
  2218. else:
  2219. PRESETS.rec(nr,data)
  2220. sdata=data
  2221. PRESETS.val_presets[nr] = sdata
  2222. master._refresh_exec()
  2223. return 1
  2224. def preset_select(self,nr):
  2225. print("SELECT PRESET")
  2226. sdata = PRESETS.val_presets[nr]
  2227. cmd = ""
  2228. for fix in sdata:
  2229. if fix == "CFG":
  2230. continue
  2231. for attr in sdata[fix]:
  2232. #v2 = sdata[fix][attr]["VALUE"]
  2233. #v2_fx = sdata[fix][attr]["FX"]
  2234. #print( self.data.elem_attr)
  2235. #if fix in self.elem_attr:
  2236. # if attr in self.elem_attr[fix]:
  2237. # elem = self.elem_attr[fix][attr]
  2238. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  2239. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2240. #elem["bg"] = "yellow"
  2241. def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  2242. t_start = time.time()
  2243. if xfade is None and FADE._is():
  2244. xfade = FADE.val()
  2245. if ptfade is None and FADE_move._is():
  2246. ptfade = FADE_move.val()
  2247. print("GO PRESET FADE",nr,val)
  2248. rdata = PRESETS.get_raw_map(nr)
  2249. if not rdata:
  2250. return 0
  2251. print("???????")
  2252. cfg = PRESETS.get_cfg(nr)
  2253. print("''''''''")
  2254. #virtcmd = FIXTURES.get_virtual(rdata)
  2255. if not cfg:
  2256. cprint("NO CFG",cfg,nr)
  2257. return 0
  2258. xFLASH = 0
  2259. value=None
  2260. cprint("preset_go",nr,cfg)
  2261. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  2262. self.preset_select(nr)
  2263. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  2264. xFLASH = 1
  2265. xfade = 0
  2266. if type(val) is not type(None) and val == 0 :
  2267. value = "off"
  2268. if event:
  2269. if str(event.type) == "ButtonRelease" or event.type == '5' :
  2270. value = "off"
  2271. cprint("preset_go() FLUSH",value,color="red")
  2272. fcmd = FIXTURES.update_raw(rdata,update=0)
  2273. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  2274. elif not val:
  2275. cprint("preset_go() STOP",value,color="red")
  2276. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  2277. fcmd = FIXTURES.update_raw(rdata)
  2278. self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  2279. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  2280. fcmd = FIXTURES.update_raw(rdata)
  2281. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  2282. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  2283. self.refresh_exec()
  2284. self.refresh_fix()
  2285. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  2286. #print(len(self.elem_presets) )
  2287. if len(self.elem_presets) > nr: # RED BUTTON IF PRESSED
  2288. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  2289. if val:# or value:
  2290. #self.elem_presets[nr].config(borderwidth=1)
  2291. self.elem_presets[nr].config(bg="red")
  2292. else:
  2293. self._refresh_exec()
  2294. cprint("preset_go",time.time()-t_start)
  2295. def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  2296. if xfade is None and FADE._is():
  2297. xfade = FADE.val()
  2298. if ptfade is None and FADE_move._is():
  2299. ptfade = FADE_move.val()
  2300. cprint("PRESETS._preset_go() len=",len(rdata),cfg)
  2301. if xfade is None:
  2302. xfade = cfg["FADE"]
  2303. if ptfade is None:
  2304. ptfade = cfg["FADE"]
  2305. #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
  2306. #cprint(rdata,color="red")
  2307. vcmd = reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
  2308. cmd = []
  2309. delay=0
  2310. for i,v in enumerate(fcmd):
  2311. #print("go",i,v)
  2312. if xFLASH:
  2313. vcmd[i]["FLASH"] = 1
  2314. DMX = fcmd[i]["DMX"]
  2315. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  2316. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  2317. if value is not None:
  2318. vcmd[i]["VALUE"] = value
  2319. if value == "off":
  2320. if "FX2" in vcmd:
  2321. vcmd[i]["FX2"]["TYPE"] = value
  2322. if "FIX" in fcmd:
  2323. vcmd[i]["FIX"] = fcmd["FIX"]
  2324. if DMX and vcmd[i]:
  2325. vcmd[i]["DMX"] = DMX
  2326. if "VIRTUAL" in fcmd[i]:
  2327. for a in fcmd[i]["VIRTUAL"]:
  2328. DMX = fcmd[i]["VIRTUAL"][a]
  2329. if DMX and vcmd[i]:
  2330. vcmd[i]["DMX"] = DMX
  2331. if type(nr) is not type(None):
  2332. vcmd[i]["EXEC"] = str(int(nr)+1)
  2333. #cprint(vcmd[i],color="red")
  2334. cmd.append(vcmd[i])
  2335. if cmd and not modes.val("BLIND"):
  2336. jclient_send(cmd)
  2337. def render(self):
  2338. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  2339. #self.draw_input()
  2340. pass
  2341. ##draw_sub_dim
  2342. class InputEventBlocker():
  2343. def __init__(self):
  2344. self.__init = 0
  2345. self.cursor = "88888"
  2346. def set(self,el,txt):
  2347. self.e = el
  2348. self.e_txt = txt
  2349. self.cursor = "88888"
  2350. def init(self):
  2351. if self.__init == 0:
  2352. try:
  2353. self.el = tk.Button()
  2354. self.e_txt = tk.StringVar()
  2355. self.__init = 1
  2356. except Exception as e:
  2357. pirnt("init() exception",e)
  2358. def _lock(self):
  2359. global _global_short_key
  2360. _global_short_key = 0
  2361. try:master.commands.elem["S-KEY"]["bg"] = "red"
  2362. except Exception as e:cprint("exc",self,e)
  2363. def _unlock(self):
  2364. global _global_short_key
  2365. _global_short_key = 1
  2366. try:master.commands.elem["S-KEY"]["bg"] = "green"
  2367. except Exception as e:cprint("exc",self,e)
  2368. def lock(self):
  2369. self._lock()
  2370. #self.e["bg"] = "red"
  2371. #self.el.config({"background": "grey"})
  2372. #self.e.focus()
  2373. def unlock(self):
  2374. self._unlock()
  2375. #self.e["bg"] = "blue"
  2376. #self.el.config({"background": "yellow"})
  2377. #self.el.focus_set()
  2378. def event(self,event,**args):
  2379. self.init()
  2380. #print()
  2381. print(self,event,args)
  2382. #print("###-",self.e_txt,dir(self.e_txt))
  2383. if "S-KEY" not in master.commands.elem:
  2384. return
  2385. if "num" in dir(event):
  2386. self.lock()
  2387. if "keysym" in dir(event):
  2388. t=self.e_txt.get()
  2389. if t and t[-1] == "<":
  2390. t = t[:-1]
  2391. if event.keysym == "Return" or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  2392. self.unlock()
  2393. #self.e_txt.set(t)
  2394. print("filter: get()",_global_short_key,t)
  2395. t2 = t
  2396. if _global_short_key == 0:
  2397. if event.keysym == "BackSpace":
  2398. if len(t) > 1:
  2399. t2 = t[:-1]
  2400. else:
  2401. t2=""
  2402. elif event.keysym == "Escape":
  2403. t2=""
  2404. elif event.keysym == "space":
  2405. t2=t+" "
  2406. elif event.char in "äöüÄÖÜ-_,.;:#'*+~":
  2407. t2=t+event.char
  2408. elif len(event.keysym) == 1:
  2409. t2=t+event.keysym
  2410. #self.e_txt.set(t2+"<")
  2411. #time.sleep(0.2)
  2412. #_global_short_key = 1
  2413. input_event_blocker = InputEventBlocker()
  2414. from tkgui.dialog import *
  2415. dialog = Dialog()
  2416. from tkgui.draw import *
  2417. from tkgui.GUI import *
  2418. class LOAD_SHOW_AND_RESTAT():
  2419. def __init__(self,fname=""):
  2420. self.fname=fname
  2421. self.base = Base()
  2422. def cb(self,event=None,force=0):
  2423. print("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
  2424. if not self.fname and not force:
  2425. return 0
  2426. if self.base.show_name == self.fname and not force:
  2427. cprint("filename is the same",self.fname)
  2428. return 0
  2429. if not force:
  2430. self.base._set(self.fname)
  2431. print("LOAD SHOW:",event,self.fname)
  2432. print(sys.executable, os.path.abspath(__file__), *sys.argv)
  2433. os.execl("/usr/bin/python3", "/opt/LibreLight/Xdesk/_LibreLightDesk.py", "_LibreLightDesk.py")
  2434. sys.exit()
  2435. class PopupList():
  2436. 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"):
  2437. self.name = name
  2438. self.frame = None
  2439. self.bg=bg
  2440. self.cb = cb
  2441. if cb is None:
  2442. cb = DummyCallback #("load_show_list.cb")
  2443. #w = Window(self.name,master=master,width=width,height=height,exit=exit,left=left,top=top,cb=cb)
  2444. args = {"title":self.name,"master":master,"width":width,"height":height,"exit":exit,"left":left,"top":top,"cb":cb}
  2445. w = Window(args)
  2446. self.w = w
  2447. w.show()
  2448. def sframe(self,line1="<line1>",line2="<line2>",data=[]):
  2449. xframe=self.w.tk
  2450. if self.bg:
  2451. xframe.configure(bg=self.bg)
  2452. self.w.tk.configure(bg=self.bg)
  2453. c=0
  2454. r=0
  2455. b = tk.Label(xframe,bg="grey",text=line1,anchor="w")
  2456. b.pack(side="top",expand=0,fill="x" )
  2457. b = tk.Label(xframe,bg="grey",text=line2,anchor="w")
  2458. b.pack(side="top",expand=0,fill="x" )
  2459. b = tk.Label(xframe,bg="black",fg="black",text="")
  2460. if self.bg:
  2461. b.configure(fg=self.bg)
  2462. b.configure(bg=self.bg)
  2463. b.pack(side="top")
  2464. b = tk.Entry(xframe,width=10,text="")#,anchor="w")
  2465. b.pack(side="top",expand=0,fill="x")
  2466. b.focus()
  2467. #frame = tk.Frame(xframe,heigh=2800)
  2468. #frame.pack(fill=tk.BOTH,expand=1, side=tk.TOP)
  2469. frame = ScrollFrame(xframe,width=300,height=500,bd=1,bg=self.bg)
  2470. #frame.pack(side="left") #fill=tk.BOTH,expand=1, side=tk.TOP)
  2471. #self.frame = frame
  2472. self.w.tk.state(newstate='normal')
  2473. self.w.tk.attributes('-topmost',True)
  2474. return frame
  2475. class DummyCallback():
  2476. def __init__(self,name="name"):
  2477. self.name = name
  2478. def cb(self,event=None):
  2479. print("DummyCallback.cb",[self.name,event])
  2480. def _load_show_list(frame,cb=None):
  2481. c=0
  2482. r=0
  2483. base = Base()
  2484. for i in ["name","stamp"]: #,"create"]:
  2485. b = tk.Label(frame,bg="grey",text=i)
  2486. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2487. c+=1
  2488. r+=1
  2489. blist = base._list()
  2490. for i in range(10):
  2491. blist.append(["",""])
  2492. if cb is None:
  2493. cb = DummyCallback #("load_show_list.cb")
  2494. for i in blist:
  2495. #print(i)
  2496. c=0
  2497. for j in i:
  2498. bg="lightgrey"
  2499. dbg="lightgrey"
  2500. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2501. dbg = "lightgreen"
  2502. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2503. dbg = "green"
  2504. if c > 0:
  2505. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2506. b.config(activebackground=dbg)
  2507. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2508. else:
  2509. if base.show_name == i[0]:
  2510. bg="green"
  2511. _cb = cb(j)
  2512. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2513. if base.show_name == i[0]:
  2514. b.config(activebackground=bg)
  2515. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2516. c+=1
  2517. r+=1
  2518. def _parse_fixture_name(name):
  2519. out = ["FIX","MAN","CH","PATH"]
  2520. if name.count(".") == 2:
  2521. m,n,e = name.split(".")
  2522. out = [n,m,"0",name]
  2523. elif name.count("_") == 2:
  2524. name,e = name.split(".")
  2525. m,n,c = name.split("_")
  2526. out = [n,m,c,name]
  2527. else:
  2528. out = [name]
  2529. return out
  2530. def _load_fixture_list(frame,cb=None,master=None,bg="black"):
  2531. frame.configure(bg=bg)
  2532. c=0
  2533. r=0
  2534. base = Base()
  2535. for i in ["source","name","manufacturer","channel's","file","path"]: #,"create"]:
  2536. b = tk.Label(frame,bg="grey",text=i)
  2537. b.grid(row=r, column=c, sticky=tk.W) #+tk.E)
  2538. c+=1
  2539. r+=1
  2540. blist = [] #base._list()
  2541. try:
  2542. p = HOME+"/LibreLight/fixtures/"
  2543. ls = os.listdir(p)
  2544. ls.sort()
  2545. for l in ls:
  2546. b = _parse_fixture_name(l)
  2547. b.append(p)
  2548. b.insert(0,"user")
  2549. blist.append(b)
  2550. except Exception as e:
  2551. print("Exce 877 ",e)
  2552. try:
  2553. p="/opt/LibreLight/Xdesk/fixtures/"
  2554. ls = os.listdir(p )
  2555. ls.sort()
  2556. for l in ls:
  2557. b = _parse_fixture_name(l)
  2558. b.append(p)
  2559. b.insert(0,"base")
  2560. blist.append(b)
  2561. except Exception as e:
  2562. print("Exce 878 ",e)
  2563. if not blist:
  2564. blist.append(["MAC-500","martin","Demo"])
  2565. blist.append(["MAC-2000","martin","Demo"])
  2566. blist.append(["MAC-VIPER","martin","Demo"])
  2567. blist.append(["SPARX-7","JB","Demo"])
  2568. blist.append(["SPARX-11","JB","Demo"])
  2569. blist.append(["JB-P6","JB","Demo"])
  2570. blist.append(["JB-P7","JB","Demo"])
  2571. blist.append(["JB-A7","JB","Demo"])
  2572. blist.append(["TMH-12","Eurolight","Demo"])
  2573. if len(blist) < 30:
  2574. for i in range(30-len(blist)):
  2575. blist.append(["{:0>4}".format(len(blist)+i+1),"",""])
  2576. if cb is None:
  2577. cb = DummyCallback #("load_show_list.cb")
  2578. _tmp_name = ""
  2579. _tmp_flag = 0
  2580. for i in blist:
  2581. #print(i)
  2582. if i[0] != _tmp_name:
  2583. _tmp_flag = "#aaf"
  2584. if i[0] == "user":
  2585. _tmp_flag = "#aaf"
  2586. if i[0] == "base":
  2587. _tmp_flag = "#0f0"
  2588. c=0
  2589. for j in i:
  2590. bg="lightgrey"
  2591. dbg="lightgrey"
  2592. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2593. dbg = "lightgreen"
  2594. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2595. dbg = "green"
  2596. if _tmp_flag:
  2597. bg = "{}".format(_tmp_flag)
  2598. if c == 1:
  2599. if base.show_name == i[0]:
  2600. bg="green"
  2601. _cb=cb(j)
  2602. _cb.master=master
  2603. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2604. if base.show_name == i[0]:
  2605. b.config(activebackground=bg)
  2606. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2607. else:#ief c > 0:
  2608. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2609. b.config(activebackground=dbg)
  2610. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2611. c+=1
  2612. r+=1
  2613. class Fixtures():
  2614. def __init__(self):
  2615. #super().__init__()
  2616. self.base=Base()
  2617. #self.load()
  2618. self.fixtures = OrderedDict()
  2619. self.gui = GUIHandler()
  2620. def load_patch(self):
  2621. filename="patch"
  2622. #self.base._init()
  2623. d,l = self.base._load(filename)
  2624. self.fixtures = OrderedDict()
  2625. for i in l:
  2626. sdata = d[i]
  2627. new_f = OrderedDict()
  2628. #print("++++")
  2629. for k,j in sdata.items():
  2630. overide=0 # only for repair
  2631. if overide:
  2632. if k in ["TYPE","VENDOR"]: #ignor
  2633. continue
  2634. new_f[k] = j
  2635. if k =="NAME":
  2636. #print("AAAADDDDDD")
  2637. if "TYPE" not in sdata and not overide:
  2638. if len( sdata["ATTRIBUT"]) == 1:
  2639. new_f["TYPE"] = "DIMMER"
  2640. elif "PAN" in sdata["ATTRIBUT"]:
  2641. new_f["TYPE"] = "MOVER"
  2642. elif "RED" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 3:
  2643. new_f["TYPE"] = "RGB"
  2644. elif "RED" in sdata["ATTRIBUT"]:
  2645. new_f["TYPE"] = "LED"
  2646. elif "CYAN" in sdata["ATTRIBUT"]:
  2647. new_f["TYPE"] = "COLOR"
  2648. else:
  2649. new_f["TYPE"] = ""
  2650. if "VENDOR" not in sdata and not overide:
  2651. new_f["VENDOR"] = ""
  2652. #print(k,j)#,sdata)
  2653. sdata = new_f
  2654. if "ACTIVE" not in sdata:
  2655. sdata["ACTIVE"] = 0
  2656. sdata["ATTRIBUT"]["_ACTIVE"] = OrderedDict()
  2657. sdata["ATTRIBUT"]["_ACTIVE"]["NR"] = 0
  2658. sdata["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2659. sdata["ATTRIBUT"]["_ACTIVE"]["VALUE"] = 0
  2660. for attr in sdata["ATTRIBUT"]:
  2661. sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
  2662. #print("load",filename,sdata)
  2663. #if "CFG" not in sdata:
  2664. # sdata["CFG"] = OrderedDict()
  2665. self.fixtures[str(i)] = sdata
  2666. #PRESETS.label_presets = l
  2667. self.fx_off("all")
  2668. def backup_patch(self,save_as=""):
  2669. filename = "patch"
  2670. #self.fx_off("all")
  2671. data = self.fixtures
  2672. labels = {}
  2673. for k in data:
  2674. labels[k] = k
  2675. #self.base._init()
  2676. self.base._backup(filename,data,labels,save_as)
  2677. def fx_get(self,fix=None):
  2678. out={}
  2679. if not fix or fix == "all":
  2680. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2681. for fix in self.fixtures:
  2682. data = self.fixtures[fix]
  2683. for attr in data["ATTRIBUT"]:
  2684. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX"]
  2685. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX2"]
  2686. return out
  2687. def fx_off(self,fix=None):
  2688. if not fix or fix == "all":
  2689. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2690. for fix in self.fixtures:
  2691. data = self.fixtures[fix]
  2692. for attr in data["ATTRIBUT"]:
  2693. data["ATTRIBUT"][attr]["FX"] = ""
  2694. data["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  2695. def get_attr(self,fix,attr):
  2696. if fix in self.fixtures:
  2697. data = self.fixtures[fix]
  2698. if "ATTRIBUT" in data:
  2699. if attr in data["ATTRIBUT"]:
  2700. return data["ATTRIBUT"][attr]
  2701. def get_max_dmx_nr(self,fix):
  2702. max_dmx = 0
  2703. used_dmx = 0
  2704. if fix not in self.fixtures:
  2705. return (used_dmx,max_dmx)
  2706. data = self.fixtures[fix]
  2707. used_dmx = len(data["ATTRIBUT"])
  2708. for a in data["ATTRIBUT"]:
  2709. attr = data["ATTRIBUT"][a]
  2710. if "NR" in attr:
  2711. try:
  2712. _n = int(attr["NR"])
  2713. if _n > max_dmx:
  2714. max_dmx=_n
  2715. except ValueError:pass
  2716. return (used_dmx,max_dmx)
  2717. def get_dmx(self,fix,attr):
  2718. #cprint("get_dmx",[fix,attr])
  2719. if fix in self.fixtures:
  2720. data = self.fixtures[fix]
  2721. DMX = -99
  2722. if "DMX" in data:
  2723. DMX = int(data["DMX"])
  2724. if DMX < 1: # ignore attribute with DMX lower 1
  2725. return -22
  2726. else:
  2727. return -1
  2728. if "UNIVERS" in data:
  2729. if int(data["UNIVERS"]) >= 0:
  2730. DMX += (int(data["UNIVERS"])*512)
  2731. else:
  2732. return -33
  2733. adata = self.get_attr(fix,attr)
  2734. #-hier ende 8.2.22
  2735. #cprint("adata",adata,DMX)
  2736. if adata:
  2737. if "NR" in adata:
  2738. NR = adata["NR"]
  2739. if NR >= 1:
  2740. DMX+=NR-1
  2741. else:
  2742. return -44
  2743. return DMX
  2744. return -4
  2745. return -3
  2746. def update_raw(self,rdata,update=1):
  2747. cprint("update_raw",len(rdata))
  2748. cmd = []
  2749. for i,d in enumerate(rdata):
  2750. xcmd = {"DMX":""}
  2751. #print("fix:",i,d)
  2752. fix = d["FIX"]
  2753. attr = d["ATTR"]
  2754. v2 = d["VALUE"]
  2755. v2_fx = d["FX"]
  2756. if fix not in self.fixtures:
  2757. continue
  2758. sdata = self.fixtures[fix] #shortcat
  2759. ATTR = sdata["ATTRIBUT"]
  2760. sDMX = 0
  2761. if sdata["DMX"] > 0:
  2762. #print( sdata)
  2763. sDMX = (sdata["UNIVERS"]*512)+sdata["DMX"]
  2764. #sDMX =sdata["DMX"]
  2765. #else:
  2766. # continue
  2767. if attr not in ATTR:
  2768. continue
  2769. #DMX = FIXTURES.get_dmx(fix)
  2770. if ATTR[attr]["NR"] >= 0:
  2771. DMX = sDMX+ATTR[attr]["NR"]-1
  2772. xcmd["DMX"] = str(DMX)
  2773. else:
  2774. if attr == "DIM" and ATTR[attr]["NR"] < 0:
  2775. xcmd["VIRTUAL"] = {}
  2776. for a in ATTR:
  2777. if ATTR[a]["MASTER"]:
  2778. xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
  2779. #print( "VIRTUAL",xcmd)
  2780. cmd.append(xcmd)
  2781. v=ATTR[attr]["VALUE"]
  2782. if v2 is not None and update:
  2783. ATTR[attr]["VALUE"] = v2
  2784. if d["FX2"] and update:
  2785. ATTR[attr]["FX2"] = d["FX2"]
  2786. #self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
  2787. text = str(attr)+' '+str(round(v,2))
  2788. #self.gui.update(fix,attr,args={"text":text})
  2789. #print("END 5454 _=_=_=_=_==_")
  2790. #cprint("update_raw",cmd,color="red")
  2791. return cmd
  2792. def encoder(self,fix,attr,xval="",xfade=0,xdelay=0,blind=0):
  2793. _blind = 0
  2794. if modes.val("BLIND"):
  2795. _blind = 1
  2796. if blind:
  2797. _blind = 1
  2798. if not _blind:
  2799. cprint("FIXTURES.encoder",fix,attr,xval,xfade,color="yellow")
  2800. if attr == "CLEAR":
  2801. self.clear()
  2802. return 0
  2803. if attr == "ALL":
  2804. x=self.select(fix,attr,mode="toggle")
  2805. return x
  2806. if attr == "INV-ATTR":
  2807. print("-x-x-x-x-x-x-x-X-")
  2808. x=self.select(fix,attr,mode="swap")
  2809. #x=self.select(fix,"ALL",mode="swap")
  2810. master.refresh_fix()
  2811. return x
  2812. if attr == "INV-FIX":
  2813. print("-x-x-x-x-x-x-x-x-")
  2814. x=self.select(fix,attr,mode="swap")
  2815. #x=self.select(fix,"ALL",mode="swap")
  2816. return x
  2817. out = []
  2818. if fix not in self.fixtures:
  2819. print(" activate Fixture in fixture list on encoder click ")
  2820. #jdata=[{"MODE":"---"}]
  2821. ii =0
  2822. #jclient_send(jdata)
  2823. delay=0
  2824. print("-->A HIER <--")
  2825. sub_data = []
  2826. for fix in self.fixtures:
  2827. ii+=1
  2828. #cprint(fix,attr,xval)
  2829. data = self.fixtures[fix]
  2830. if "-FINE" in attr.upper():
  2831. continue
  2832. elif (attr in data["ATTRIBUT"] ) and "-FINE" not in attr.upper() :
  2833. if xval == "click":
  2834. self.select(fix,attr,mode="on")
  2835. elif data["ATTRIBUT"][attr]["ACTIVE"]:
  2836. if fix: # prevent endless recursion
  2837. #print("------",end="")
  2838. #self.encoder(fix,attr,xval,xfade,delay)
  2839. sub_data.append([fix,attr,xval,xfade,delay])
  2840. if DELAY._is():
  2841. delay += DELAY.val()/100
  2842. sub_jdata = []
  2843. for dd in sub_data:
  2844. #print("---",len(sub_data),end="")
  2845. #self.encoder(fix,attr,xval,xfade,delay)
  2846. _x123 = self.encoder(dd[0],dd[1],dd[2],dd[3],dd[4],blind=1)
  2847. sub_jdata.append(_x123)
  2848. if sub_jdata:
  2849. print("--- SEND MASTER ENCODER:",len(sub_data),sub_data[0],"... _blind:",_blind)#,end="")
  2850. jclient_send(sub_jdata)
  2851. jdata=[{"MODE":ii}]
  2852. print("-->B HIER <--")
  2853. jclient_send(jdata)
  2854. return 0
  2855. data = self.fixtures[fix]
  2856. if xval == "click":
  2857. #cprint(data)
  2858. return self.select(fix,attr,mode="toggle")
  2859. v2=data["ATTRIBUT"][attr]["VALUE"]
  2860. change=0
  2861. increment = 4.11
  2862. jdata = {"MODE":"ENC"}
  2863. if xval == "++":
  2864. v2+= increment
  2865. jdata["INC"] = increment
  2866. change=1
  2867. elif xval == "--":
  2868. jdata["INC"] = increment*-1
  2869. v2-= increment
  2870. change=1
  2871. elif xval == "+":
  2872. increment = 0.5
  2873. v2+= increment
  2874. jdata["INC"] = increment
  2875. change=1
  2876. elif xval == "-":
  2877. increment = 0.5
  2878. jdata["INC"] = increment*-1
  2879. v2-= increment
  2880. change=1
  2881. elif type(xval) is int or type(xval) is float:
  2882. v2 = xval
  2883. change=1
  2884. if v2 < 0:
  2885. v2=0
  2886. elif v2 > 256:
  2887. v2=256
  2888. jdata["VALUE"] = round(v2,4)
  2889. jdata["FIX"] = fix
  2890. jdata["ATTR"] = attr
  2891. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  2892. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  2893. out = {}
  2894. if change:
  2895. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2896. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2897. data["ATTRIBUT"][attr]["VALUE"] = round(v2,4)
  2898. jdata["FADE"] = 0
  2899. if xfade:
  2900. jdata["FADE"] = xfade
  2901. if xdelay:
  2902. #if attr not in ["PAN","TILT"] and 1:
  2903. jdata["DELAY"] = xdelay
  2904. if not _blind:
  2905. jdata = [jdata]
  2906. #print("ENC",jdata)
  2907. jclient_send(jdata)
  2908. time.sleep(0.001)
  2909. return jdata
  2910. return v2
  2911. def get_active(self):
  2912. cprint("get_active",self)
  2913. CFG = OrderedDict()
  2914. sdata = OrderedDict()
  2915. sdata["CFG"] = CFG # OrderedDict()
  2916. sdata["CFG"]["FADE"] = FADE.val()
  2917. sdata["CFG"]["DEALY"] = 0
  2918. #sdata["CFG"]["BUTTON"] = "GO"
  2919. for fix in self.fixtures:
  2920. data = self.fixtures[fix]
  2921. for attr in data["ATTRIBUT"]:
  2922. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2923. if fix not in sdata:
  2924. sdata[fix] = {}
  2925. if attr not in sdata[fix]:
  2926. sdata[fix][attr] = OrderedDict()
  2927. if not modes.val("REC-FX"):
  2928. sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
  2929. #sdata[fix][attr]["FADE"] = FADE.val() #fade
  2930. else:
  2931. sdata[fix][attr]["VALUE"] = None #data["ATTRIBUT"][attr]["VALUE"]
  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 get_active2(self):
  2940. pass
  2941. def _deselect_all(self,fix=None):
  2942. cprint("FIXTURES._deselect_all()",fix,"ALL",color="yellow")
  2943. c=0
  2944. if fix in self.fixtures:
  2945. data = self.fixtures[fix]
  2946. for attr in data["ATTRIBUT"]:
  2947. #print("SELECT ALL",fix,attr)
  2948. if "-FINE" in attr.upper():
  2949. pass
  2950. else:
  2951. c+=self.select(fix,attr,mode="off",mute=1)
  2952. return c
  2953. def _select_all(self,fix=None,mode="toggle",mute=0):
  2954. if not mute:
  2955. cprint("FIXTURES._select_all()",fix,"ALL",mode,color="yellow")
  2956. c=0
  2957. if fix in self.fixtures:
  2958. data = self.fixtures[fix]
  2959. for attr in data["ATTRIBUT"]:
  2960. #print("SELECT ALL",fix,attr)
  2961. if "-FINE" in attr.upper():
  2962. continue
  2963. if mode == "toggle":
  2964. c+=self.select(fix,attr,mode="on",mute=mute)
  2965. elif mode == "swap":
  2966. if not attr.startswith("_"):
  2967. c+=self.select(fix,attr,mode="toggle",mute=mute)
  2968. if not c and mode == "toggle": # unselect all
  2969. c= self._deselect_all(fix=fix)
  2970. return c
  2971. def select(self,fix=None,attr=None,mode="on",mute=0):
  2972. if not mute:
  2973. cprint("FIXTURES.select() >>",fix,attr,mode,color="yellow")
  2974. out = 0
  2975. if fix == "SEL":
  2976. if attr.upper() == "INV-ATTR":
  2977. fixs = self.get_active()
  2978. print("selected:",len(fixs))
  2979. for fix in fixs:
  2980. x=self._select_all(fix=fix,mode=mode,mute=1)
  2981. return None
  2982. if fix in self.fixtures:
  2983. if attr.upper() == "ALL":
  2984. x=self._select_all(fix=fix,mode=mode)
  2985. return x
  2986. data = self.fixtures[fix]
  2987. if attr in data["ATTRIBUT"]:
  2988. if mode == "on":
  2989. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  2990. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2991. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2992. out = 1
  2993. elif mode == "off":
  2994. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2995. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2996. out = 1
  2997. elif mode == "toggle":
  2998. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2999. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  3000. else:
  3001. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  3002. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  3003. out = 1
  3004. return out
  3005. def clear(self):
  3006. out = 0
  3007. for fix in self.fixtures:
  3008. data = self.fixtures[fix]
  3009. for attr in data["ATTRIBUT"]:
  3010. #if attr.endswith("-FINE"):
  3011. # continue
  3012. if data["ATTRIBUT"][attr]["ACTIVE"]:
  3013. out +=1
  3014. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  3015. return out
  3016. def CFG_CHECKER(sdata):
  3017. "repair CFG "
  3018. ok = 0
  3019. if "CFG" not in sdata:
  3020. sdata["CFG"] = OrderedDict()
  3021. ok += 1
  3022. if "FADE" not in sdata["CFG"]:
  3023. sdata["CFG"]["FADE"] = 4
  3024. ok += 1
  3025. if "DELAY" not in sdata["CFG"]:
  3026. sdata["CFG"]["DELAY"] = 0
  3027. ok += 1
  3028. if "BUTTON" not in sdata["CFG"]:
  3029. sdata["CFG"]["BUTTON"] = "GO"
  3030. ok += 1
  3031. if "HTP-MASTER" not in sdata["CFG"]:
  3032. sdata["CFG"]["HTP-MASTER"] = 100 #%
  3033. ok += 1
  3034. if "SIZE-MASTER" not in sdata["CFG"]:
  3035. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  3036. ok += 1
  3037. if "SPEED-MASTER" not in sdata["CFG"]:
  3038. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  3039. ok += 1
  3040. if "OFFSET-MASTER" not in sdata["CFG"]:
  3041. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  3042. ok += 1
  3043. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  3044. #except:pass
  3045. return ok
  3046. class Presets():
  3047. def __init__(self):
  3048. #super().__init__()
  3049. self.base = Base()
  3050. #self.load()
  3051. self._last_copy = None
  3052. self._last_move = None
  3053. self.fx_buffer = {}
  3054. def load_presets(self):
  3055. #self._load()
  3056. filename="presets"
  3057. #self.base._init()
  3058. d,l = self.base._load(filename)
  3059. for i in d:
  3060. sdata = d[i]
  3061. ok = CFG_CHECKER(sdata)
  3062. self.val_presets = d
  3063. self.label_presets = l
  3064. def check_cfg(self,nr=None):
  3065. cprint("PRESETS.check_cfg()",nr)#,color="red")
  3066. ok = 0
  3067. if nr is not None:
  3068. if nr in self.val_presets:
  3069. sdata = self.val_presets[nr]
  3070. ok += self._check_cfg(sdata)
  3071. else:
  3072. cprint("nr not in data ",nr,color="red")
  3073. else:
  3074. for nr in self.val_presets:
  3075. sdata = self.val_presets[nr]
  3076. ok += self._check_cfg(sdata)
  3077. return ok
  3078. def _check_cfg(self,sdata):
  3079. cprint("PRESETS._check_cfg()")#,color="red")
  3080. ok = CFG_CHECKER(sdata)
  3081. if ok:
  3082. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  3083. return ok
  3084. def backup_presets(self,save_as=""):
  3085. filename = "presets"
  3086. data = self.val_presets
  3087. labels = self.label_presets
  3088. #self.base._init()
  3089. self.base._backup(filename,data,labels,save_as)
  3090. def get_cfg(self,nr):
  3091. cprint("PRESETS.get_cfg()",nr)
  3092. self.check_cfg(nr)
  3093. if nr not in self.val_presets:
  3094. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  3095. return {}
  3096. if "CFG" in self.val_presets[nr]:
  3097. return self.val_presets[nr]["CFG"]
  3098. def clean(self,nr):
  3099. if nr not in self.val_presets:
  3100. self.val_presets[nr] = OrderedDict()
  3101. #self.val_presets[nr]["VALUE"] = 0
  3102. #self.val_presets[nr]["FX"] = ""
  3103. sdata = self.val_presets[nr]
  3104. for fix in sdata:
  3105. #print("exec.clear()",nr,fix,sdata[fix])
  3106. for attr in sdata[fix]:
  3107. row = sdata[fix][attr]
  3108. if fix == "CFG":
  3109. continue
  3110. if "VALUE" not in row:
  3111. row["VALUE"] = None
  3112. if "FX" not in row:
  3113. row["FX"] = ""
  3114. if "FX2" not in row:
  3115. row["FX2"] = OrderedDict()
  3116. elif row["FX2"]:
  3117. for k in ["SIZE","SPEED","START","OFFSET"]:
  3118. row["FX2"][k] = int( row["FX2"][k] )
  3119. row["FX"] = ""
  3120. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  3121. #"off:0:0:0:16909:-:"
  3122. x = row["FX"].split(":")
  3123. print("-fx",x,len(x))
  3124. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  3125. if len(x) >= 6:
  3126. row["FX2"]["TYPE"] = x[0]
  3127. row["FX2"]["SIZE"] = int(x[1])
  3128. row["FX2"]["SPEED"] = int(x[2])
  3129. row["FX2"]["START"] = int(x[3])
  3130. row["FX2"]["OFFSET"] = int(x[4])
  3131. row["FX2"]["BASE"] = x[5]
  3132. row["FXOLD"] = row["FX"]
  3133. row["FX"] = ""
  3134. #cprint("exec.clear()",nr,fix,row)
  3135. def get_raw_map(self,nr):
  3136. self.clean(nr)
  3137. print("get_raw_map",nr)
  3138. sdata = self.val_presets[nr]
  3139. cmd = ""
  3140. out = []
  3141. dmx=-1
  3142. for fix in sdata:
  3143. if fix == "CFG":
  3144. #print("CFG",nr,sdata[fix])
  3145. continue
  3146. for attr in sdata[fix]:
  3147. x = {}
  3148. #print("RAW",attr)
  3149. x["FIX"] = fix
  3150. x["ATTR"] = attr
  3151. x["VALUE"] = sdata[fix][attr]["VALUE"]
  3152. x["FX"] = sdata[fix][attr]["FX"]
  3153. x["FX2"] = sdata[fix][attr]["FX2"]
  3154. #x["DMX"] = sdata[fix][attr]["NR"]
  3155. out.append(x)
  3156. return out
  3157. def get_btn_txt(self,nr):
  3158. sdata=self.val_presets[nr]
  3159. BTN="go"
  3160. if "CFG" in sdata:
  3161. if "BUTTON" in sdata["CFG"]:
  3162. BTN = sdata["CFG"]["BUTTON"]
  3163. _label = self.label_presets[nr] # = label
  3164. #txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  3165. #txt=str(nr+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+_label
  3166. txt="{} {} {}\n{}".format(nr+1,BTN,len(sdata)-1,_label)
  3167. print("get_btn_txt",nr,[txt])
  3168. return txt
  3169. def _btn_cfg(self,nr,txt=None):
  3170. if nr not in self.val_presets:
  3171. return ""
  3172. if "CFG" not in self.val_presets[nr]:
  3173. self.val_presets[nr]["CFG"] = OrderedDict()
  3174. return self.val_presets[nr]["CFG"]
  3175. def btn_cfg(self,nr,txt=None):
  3176. if nr not in self.val_presets:
  3177. return ""
  3178. if "CFG" not in self.val_presets[nr]:
  3179. self.val_presets[nr]["CFG"] = OrderedDict()
  3180. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  3181. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3182. if type(txt) is str:
  3183. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  3184. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  3185. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3186. master._refresh_exec(nr=nr)
  3187. print("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  3188. return self.val_presets[nr]["CFG"]["BUTTON"]
  3189. def label(self,nr,txt=None):
  3190. if nr not in self.label_presets:
  3191. return ""
  3192. if type(txt) is str:
  3193. self.label_presets[nr] = txt
  3194. print("set label",nr,[txt])
  3195. print("??? ?? set label",nr,[txt])
  3196. return self.label_presets[nr]
  3197. def clear_move(self):
  3198. cprint("PRESETS.clear_move()",end=" ")
  3199. self.clear_copy()
  3200. def clear_copy(self):
  3201. cprint("PRESETS.clear_copy()",end=" ")
  3202. if self._last_copy is not None:
  3203. cprint("=OK=",color="red")
  3204. self._last_copy = None
  3205. else:
  3206. cprint("=NONE=",color="green")
  3207. def copy(self,nr,overwrite=1):
  3208. cprint("PRESETS._copy",nr,"last",self._last_copy)
  3209. if nr >= 0:
  3210. if self._last_copy is not None:
  3211. if modes.val("COPY"):
  3212. modes.val("COPY",3)
  3213. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  3214. return ok #ok
  3215. else:
  3216. if modes.val("COPY"):
  3217. modes.val("COPY",2)
  3218. self._last_copy = nr
  3219. cprint("PRESETS.copy START ",color="red")
  3220. return 0
  3221. return 1 # on error reset move
  3222. def _copy(self,nr_from,nr_to,overwrite=1):
  3223. cprint("PRESETS._copy",nr_from,"to",nr_to)
  3224. self.check_cfg(nr_from)
  3225. if type(self._last_copy) is None:
  3226. cprint("PRESETS._copy last nr is None",color="red")
  3227. return 0
  3228. cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
  3229. if nr_from in self.val_presets and nr_to in self.val_presets:
  3230. fdata = self.val_presets[nr_from]
  3231. tdata = self.val_presets[nr_to]
  3232. #cprint(fdata)
  3233. flabel = self.label_presets[nr_from]
  3234. tlabel = self.label_presets[nr_to]
  3235. self.val_presets[nr_to] = copy.deepcopy(fdata)
  3236. self.label_presets[nr_to] = flabel
  3237. if not overwrite: #default
  3238. cprint("overwrite",overwrite)
  3239. self.val_presets[nr_from] = copy.deepcopy(tdata)
  3240. self.label_presets[nr_from] = tlabel
  3241. #self.label_presets[nr_from] = "MOVE"
  3242. self.clear_copy()
  3243. cprint("PRESETS.copy OK",color="green")
  3244. return 1
  3245. def move(self,nr):
  3246. cprint("PRESETS.move",self._last_copy,"to",nr)
  3247. if nr >= 0:
  3248. last = self._last_copy
  3249. if modes.val("MOVE"):
  3250. modes.val("MOVE",2)
  3251. ok= self.copy(nr,overwrite=0)
  3252. if ok and last >= 0:
  3253. if modes.val("MOVE"):
  3254. modes.val("MOVE",3)
  3255. cprint("PRESETS.move OK",color="red")
  3256. #self.delete(last)
  3257. return ok,nr,last #ok
  3258. return 0,nr,last # on error reset move
  3259. def delete(self,nr):
  3260. cprint("PRESETS.delete",nr)
  3261. ok=0
  3262. if nr in self.val_presets:
  3263. self.val_presets[nr] = OrderedDict()
  3264. self.label_presets[nr] = "-"
  3265. ok = 1
  3266. self.check_cfg(nr)
  3267. return ok
  3268. def rec(self,nr,data,arg=""):
  3269. cprint("rec",self,"rec()",len(data),arg)
  3270. self.check_cfg(nr)
  3271. self._check_cfg(data) #by ref
  3272. odata=self.val_presets[nr]
  3273. #print("odata",odata)
  3274. if "CFG" in odata:
  3275. if "BUTTON" in odata["CFG"]:
  3276. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  3277. self.val_presets[nr] = data
  3278. return 1
  3279. class FixtureEditor():
  3280. def __init__(self,dmx=1):
  3281. pass
  3282. self.elem=[]
  3283. self.dmx=dmx
  3284. print("init FixtureEditor",dmx)
  3285. def event(self,a1="",a2=""):
  3286. print([self.dmx,a1,a2])
  3287. j=[]
  3288. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
  3289. j.append(jdata)
  3290. jclient_send(j)
  3291. class MasterWing():
  3292. def __init__(self,dmx=1):
  3293. pass
  3294. self.elem=[]
  3295. self.dmx=dmx
  3296. print("init MasterWing",dmx)
  3297. def event(self,a1="",a2=""):
  3298. print([self.dmx,a1,a2])
  3299. jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
  3300. j=[]
  3301. j.append(jdata)
  3302. jclient_send(j)
  3303. class BufferVar():
  3304. def __init__(self,elem):
  3305. self.elem = elem
  3306. def change_dmx(self,event=""):
  3307. nr=1
  3308. txt=""
  3309. def cb(data):
  3310. txt = data["Value"]
  3311. dialog._cb = _cb
  3312. dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
  3313. print("change_dmx",[event,self])
  3314. lf_nr = 0
  3315. from tkinter import PhotoImage
  3316. _shift_key = 0
  3317. class Window():
  3318. def __init__(self,args): #title="title",master=0,width=100,height=100,left=None,top=None,exit=0,cb=None,resize=1):
  3319. global lf_nr
  3320. self.args = {"title":"title","master":0,"width":100,"height":100,"left":None,"top":None,"exit":0,"cb":None,"resize":1}
  3321. self.args.update(args)
  3322. cprint("Window.init()",id(self.args),color="yellow")
  3323. cprint(" ",self.args,color="yellow")
  3324. ico_path="./icon/"
  3325. self.cb = cb
  3326. if self.args["master"]:
  3327. self.tk = tkinter.Tk()
  3328. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3329. self.tk.withdraw() # do not draw
  3330. self.tk.resizable(self.args["resize"],self.args["resize"])
  3331. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  3332. print(defaultFont)
  3333. defaultFont.configure(family="FreeSans",
  3334. size=10,
  3335. weight="bold")
  3336. # MAIN MENUE
  3337. try:
  3338. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"main.png"))
  3339. except Exception as e:
  3340. print("Exception GUIWindow.__init__",e)
  3341. else:
  3342. # addtional WINDOW
  3343. self.tk = tkinter.Toplevel()
  3344. self.tk.iconify()
  3345. #self.tk.withdraw() # do not draw
  3346. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3347. self.tk.resizable(self.args["resize"],self.args["resize"])
  3348. try:
  3349. if "COLORPICKER" in self.args["title"]:
  3350. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"picker.png"))
  3351. elif "ENCODER" in self.args["title"]:
  3352. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"enc.png"))
  3353. elif "EXEC" in self.args["title"]:
  3354. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  3355. elif "FX" in self.args["title"]:
  3356. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"fx.png"))
  3357. else:
  3358. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png"))
  3359. except Exception as e:
  3360. print("Exception on load window icon",self.args["title"])
  3361. print("Exception:",e)
  3362. #time.sleep(3)
  3363. self.tk.deiconify()
  3364. self.tk["bg"] = "black"
  3365. self.tk.bind("<Button>",self.callback)
  3366. self.tk.bind("<Key>",self.callback)
  3367. self.tk.bind("<KeyRelease>",self.callback)
  3368. self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3369. lf_nr+=1
  3370. #self.tk.geometry("270x600+0+65")
  3371. geo ="{}x{}".format(self.args["width"],self.args["height"])
  3372. if self.args["left"] is not None:
  3373. geo += "+{}".format(self.args["left"])
  3374. if self.args["top"] is not None:
  3375. geo += "+{}".format(self.args["top"])
  3376. #self._event_clear = Xevent(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
  3377. self.tk.geometry(geo)
  3378. self.show()
  3379. def update_idle_task(self):
  3380. if INIT_OK:
  3381. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3382. pass
  3383. def close_app_win(self,event=None):
  3384. cprint("close_app_win",self,event,self.args["title"],color="red")
  3385. if exit:
  3386. if self.title == "MAIN":
  3387. save_window_position()
  3388. save_window_position()
  3389. self.tk.destroy()
  3390. try:
  3391. self.cb("<exit>").cb()
  3392. except Exception as e:
  3393. cprint("EXCETPION: close_app_win",e,self,color="red")
  3394. def title(self,title=None):
  3395. if title is None:
  3396. return self.tk.title()
  3397. else:
  3398. #return self.tk.title(title)
  3399. self.args["title"] = title
  3400. return self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3401. def show(self):
  3402. self.tk.deiconify()
  3403. pass
  3404. def mainloop(self):
  3405. #save_window_position_loop() #like autosave
  3406. try:
  3407. self.tk.mainloop()
  3408. finally:
  3409. self.tk.quit()
  3410. def callback(self,event,data={}):#value=255):
  3411. global _global_short_key
  3412. #time.sleep(0.1)
  3413. if not _global_short_key:
  3414. #cprint("<GLOBAL-GUI-EVENT-DISABLED>",event,color="red")
  3415. return 1
  3416. global _shift_key
  3417. #cprint("<GUI>",event,color="yellow")
  3418. value = 255
  3419. if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
  3420. value = 0
  3421. cprint("<GUI>",event.state,data,value,[event.type,event.keysym],color="yellow")
  3422. #print(event)
  3423. if "state" in dir(event) and "keysym" in dir(event):
  3424. #print([event.state,event.keysym,event.type])
  3425. if event.state == 4 and str(2) == str(event.type): # strg + s
  3426. if str(event.keysym) == "s":
  3427. print("tTtT ReW "*20)
  3428. #print("numbersign !!")
  3429. PRESETS.backup_presets()
  3430. FIXTURES.backup_patch()
  3431. save_window_position()
  3432. e = master.setup_elem["SAVE\nSHOW"]
  3433. #print(e)
  3434. b = BLINKI(e)
  3435. b.blink()
  3436. if str(event.keysym) == "c":
  3437. PRESETS.backup_presets()
  3438. FIXTURES.backup_patch()
  3439. save_window_position()
  3440. #self.elem.config(activebackground="lightgrey")
  3441. LOAD_SHOW_AND_RESTAT("").cb(force=1)
  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. print("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. class WindowManager():
  3518. def __init__(self):
  3519. self.windows = {}
  3520. self.obj = {}
  3521. self.nr= 0
  3522. self.first=""
  3523. self.window_init_buffer = {}
  3524. def update(self,w,name="",obj=None):
  3525. name = str(name)
  3526. for k in self.windows:
  3527. if k == name:
  3528. self.windows[str(name)] = w
  3529. self.obj[str(name)] = obj
  3530. def new(self,w,name="",obj=None,wcb=None):
  3531. name = str(name)
  3532. if wcb and name:
  3533. self.window_init_buffer[name] = wcb
  3534. if not self.first:
  3535. if name:
  3536. self.first = name
  3537. else:
  3538. self.first = str(self.nr)
  3539. if w:
  3540. w.tk.state(newstate='normal')
  3541. w.tk.attributes('-topmost',True)
  3542. if name:
  3543. self.windows[str(name)] = w
  3544. self.obj[str(name)] = obj
  3545. else:
  3546. self.windows[str(self.nr)] = w
  3547. self.obj[str(self.nr)] = obj
  3548. self.nr+=1
  3549. def mainloop(self):
  3550. self.windows[self.first].mainloop()
  3551. def get_win(self,name):
  3552. print(self,".get_win(name) =",name)
  3553. name = str(name)
  3554. if name in self.windows:
  3555. out = self.windows[name]
  3556. print(out)
  3557. return out
  3558. def get(self,name):
  3559. return get_win(name)
  3560. def get_obj(self,name):
  3561. name = str(name)
  3562. if name in self.windows:
  3563. out = self.obj[name]
  3564. return out
  3565. def create(self,name):
  3566. cprint( "create Window",name)
  3567. if name in self.window_init_buffer:
  3568. c = self.window_init_buffer[name]
  3569. w,obj,cb_ok = c.create()
  3570. window_manager.update(w,name,obj)
  3571. if cb_ok:
  3572. cb_ok()
  3573. resize = 1
  3574. if "resize" in c.args:
  3575. if not c.args["resize"]:
  3576. resize = 0
  3577. #if resize:
  3578. get_window_position(_filter=name,win=w)
  3579. if name in ["ENCODER"]:
  3580. global _ENCODER_WINDOW
  3581. _ENCODER_WINDOW = w
  3582. if name in ["DIMMER","FIXTURES"]:
  3583. refresher_fix.reset() # = Refresher()
  3584. def _check(self,name):
  3585. try:
  3586. self.windows[name].tk.state(newstate='normal')
  3587. return 1
  3588. except Exception as e:
  3589. cprint("exception",e,color="red")
  3590. cprint("info",name,self.windows[name],color="red")
  3591. def top(self,name):
  3592. name = str(name)
  3593. if name not in self.windows:
  3594. print(name,"not in self.windows",self.windows.keys())
  3595. return
  3596. if not self._check(name):
  3597. self.create(name)
  3598. self.windows[name].tk.attributes('-topmost',True)
  3599. self.windows[name].tk.attributes('-topmost',False)
  3600. self.windows[name].tk.update_idletasks()
  3601. class Console():
  3602. def __init__(self):
  3603. pass
  3604. def flash_off(self,fix):
  3605. pass#client.send("df0:alloff:::,")
  3606. def fx_off(self,fix):
  3607. cprint("Console.fx_off()",fix)
  3608. if not fix or fix == "all":
  3609. #client.send("fx0:alloff:,fxf:alloff:,")
  3610. #client.send("df0:alloff:::,")
  3611. j = []
  3612. if 0:
  3613. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  3614. j.append(jdata)
  3615. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  3616. j.append(jdata)
  3617. else:
  3618. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  3619. j.append(jdata)
  3620. jclient_send(j)
  3621. return 0
  3622. def test_1():
  3623. #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
  3624. pass
  3625. window_manager = WindowManager()
  3626. CONSOLE = Console()
  3627. PRESETS = Presets()
  3628. FIXTURES = Fixtures()
  3629. def LOAD_SHOW():
  3630. PRESETS.load_presets()
  3631. FIXTURES.load_patch()
  3632. #master._refresh_fix()
  3633. #master._refresh_exec()
  3634. LOAD_SHOW()
  3635. master = MASTER()
  3636. class Refresher():
  3637. def __init__(self):
  3638. self.time = time.time()
  3639. self.time_max = time.time()
  3640. self.time_delta = 15
  3641. self.update = 1
  3642. self.name = "name" # exec
  3643. self.cb = None #self.dummy_cb
  3644. def dummy_cb(self):
  3645. print(self,"dummy_cd()",time.time()-self.time)
  3646. def reset(self):
  3647. self.time = time.time()
  3648. self.update = 1
  3649. def refresh(self):
  3650. if self.update:
  3651. if self.time+self.time_delta < time.time():
  3652. self._refresh()
  3653. else:
  3654. self.time = time.time()
  3655. def _refresh(self):
  3656. print("_refresh()",self.name,self)
  3657. if not INIT_OK:
  3658. return
  3659. self.time_max = time.time()
  3660. self.time = time.time()
  3661. self.update = 0
  3662. try:
  3663. if self.cb:
  3664. self.cb()
  3665. else:
  3666. self.dummy_cb()
  3667. except Exception as e:
  3668. print("_refresh except:",e,"cb:",self.cb)
  3669. traceback.print_exc()
  3670. print()
  3671. print("t=",self.time_max- time.time())
  3672. def loop(self,args={}):
  3673. while 1:
  3674. try:
  3675. if INIT_OK:
  3676. self.refresh()
  3677. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3678. except Exception as e:
  3679. print("loop exc",e)
  3680. traceback.print_exc()
  3681. cprint("== cb EXCEPT",e,color="red")
  3682. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  3683. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  3684. time.sleep(0.2)
  3685. print("main",__name__)
  3686. __run_main = 0
  3687. if __name__ == "__main__":
  3688. __run_main = 1
  3689. else:
  3690. import __main__
  3691. if "unittest" not in dir(__main__):
  3692. __run_main = 1
  3693. refresher_fix = Refresher()
  3694. refresher_fix.time_delta = 1.0
  3695. refresher_fix.name = "fix"
  3696. refresher_fix.reset()
  3697. refresher_fix.cb = master._refresh_fix
  3698. refresher_exec = Refresher()
  3699. refresher_exec.time_delta = 10 #0
  3700. refresher_exec.name = "exec"
  3701. refresher_exec.reset()
  3702. refresher_exec.cb = master._refresh_exec
  3703. def loops(**args):
  3704. time.sleep(5) # wait until draw all window's
  3705. cprint("-> run loops")
  3706. thread.start_new_thread(refresher_fix.loop,())
  3707. thread.start_new_thread(refresher_exec.loop,())
  3708. class window_create_buffer():
  3709. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  3710. self.args = args.copy()
  3711. self.cls = cls
  3712. self.cb_ok = cb_ok
  3713. self.data = data
  3714. self.scroll = scroll
  3715. self.gui = gui
  3716. def create(self,hidde=0):
  3717. cprint()
  3718. cprint()
  3719. cprint("window_create_buffer.create()",id(self),self.args["title"],color="green")
  3720. obj = None
  3721. w = Window(self.args)
  3722. if self.scroll:
  3723. w1 = ScrollFrame(w.tk,width=self.args["width"],height=self.args["height"])
  3724. else:
  3725. w1 = tk.Frame(w.tk,width=self.args["width"],height=self.args["height"])
  3726. w1.pack()
  3727. obj=self.cls(self.gui,w1,self.data)
  3728. return w,obj,self.cb_ok
  3729. if __run_main:
  3730. print("main")
  3731. #thread.start_new_thread(refresher_fix.loop,())
  3732. #thread.start_new_thread(refresher_exec.loop,())
  3733. TOP = _POS_TOP + 15
  3734. L0 = _POS_LEFT
  3735. L1 = _POS_LEFT + 95
  3736. L2 = _POS_LEFT + 920
  3737. W1 = 810
  3738. H1 = 550
  3739. HTB = 23 # hight of the titlebar from window manager
  3740. pos_list = read_window_position()
  3741. data = []
  3742. #data.append({"text":"COMMAND"})
  3743. #data.append({"text":"CONFIG"})
  3744. data.append({"text":"PATCH"})
  3745. data.append({"text":"DIMMER"})
  3746. data.append({"text":"FIXTURES"})
  3747. data.append({"text":"EXEC","name":"EXEC-BTN"})
  3748. data.append({"text":"EXEC-WING"})
  3749. data.append({"text":"---"})
  3750. data.append({"text":"SETUP"})
  3751. data.append({"text":"COMMAND"})
  3752. data.append({"text":"LIVE"})
  3753. data.append({"text":"FX"})
  3754. data.append({"text":"ENCODER"})
  3755. data.append({"text":"COLORPICKER","name":"COLOR"})
  3756. data.append({"text":"---"})
  3757. data.append({"text":"FIXTURE-EDITOR","name":"FIX-EDIT"})
  3758. data.append({"text":"CONFIG"})
  3759. data.append({"text":"CLOCK"})
  3760. data.append({"text":"---"})
  3761. name="MAIN"
  3762. args = {"title":"MAIN","master":1,"width":80,"height":H1,"left":L0,"top":TOP,"resize":1}
  3763. geo = split_window_position(pos_list,name)
  3764. if geo:
  3765. args.update(geo)
  3766. cls = GUI_menu
  3767. cb_ok = None
  3768. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3769. window_manager.new(None,name,wcb=c)
  3770. window_manager.top(name)
  3771. gui_menu_gui = window_manager.get_win(name)
  3772. gui_menu = window_manager.get_obj(name)
  3773. master._refresh_fix()
  3774. # --------------------------------
  3775. name="EXEC"
  3776. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3777. geo = split_window_position(pos_list,name)
  3778. if geo:
  3779. args.update(geo)
  3780. data = PRESETS
  3781. cls = draw_exec #GUI_ExecWingLayout
  3782. cb_ok = None #set_exec_fader_all
  3783. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3784. window_manager.new(None,name,wcb=c)
  3785. window_manager.top(name)
  3786. name="CONFIG"
  3787. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3788. geo = split_window_position(pos_list,name)
  3789. if geo:
  3790. args.update(geo)
  3791. data = []
  3792. cls = GUI_CONF
  3793. cb_ok = None
  3794. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3795. window_manager.new(None,name,wcb=c)
  3796. #window_manager.top(name)
  3797. name="DIMMER"
  3798. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3799. geo = split_window_position(pos_list,name)
  3800. if geo:
  3801. args.update(geo)
  3802. cls = GUI_DIM
  3803. data = FIXTURES
  3804. ok_cb=None
  3805. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3806. window_manager.new(None,name,wcb=c)
  3807. #window_manager.top(name)
  3808. name="FIXTURES"
  3809. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3810. geo = split_window_position(pos_list,name)
  3811. if geo:
  3812. args.update(geo)
  3813. cls = GUI_FIX
  3814. ok_cb=None
  3815. data = FIXTURES
  3816. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3817. window_manager.new(None,name,wcb=c)
  3818. #window_manager.top(name)
  3819. # -------------------------------
  3820. name="FIXTURE-EDITOR"
  3821. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3822. geo = split_window_position(pos_list,name)
  3823. if geo:
  3824. args.update(geo)
  3825. data=[]
  3826. for i in range(12*6):
  3827. data.append({"text"+str(i):"test"})
  3828. cls = GUI_FaderLayout
  3829. cb_ok = None
  3830. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3831. window_manager.new(None,name,wcb=c)
  3832. #window_manager.top(name)
  3833. # -------------------------------
  3834. name="MASTER-WING"
  3835. args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220,"resize":0}
  3836. geo = split_window_position(pos_list,name)
  3837. if geo:
  3838. args.update(geo)
  3839. data=[]
  3840. for i in range(2):
  3841. data.append({"MASTER"+str(i):"MASTER"})
  3842. cls = GUI_MasterWingLayout #(w1,data)
  3843. cb_ok = None
  3844. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3845. window_manager.new(None,name,wcb=c)
  3846. window_manager.top(name)
  3847. # -------------------------------
  3848. name="EXEC-WING"
  3849. args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
  3850. geo = split_window_position(pos_list,name)
  3851. if geo:
  3852. args.update(geo)
  3853. data=[]
  3854. for i in range(10*3):
  3855. data.append({"EXEC"+str(i):"EXEC"})
  3856. cls = GUI_ExecWingLayout
  3857. cb_ok = set_exec_fader_all
  3858. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3859. window_manager.new(None,name,wcb=c)
  3860. window_manager.top(name)
  3861. name="ENCODER"
  3862. args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
  3863. geo = split_window_position(pos_list,name)
  3864. if geo:
  3865. args.update(geo)
  3866. cls = draw_enc #(master,w.tk)#Xroot)
  3867. cb_ok = None
  3868. data = FIXTURES #master
  3869. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3870. window_manager.new(None,name,wcb=c)
  3871. #window_manager.top(name)
  3872. name = "SETUP"
  3873. args = {"title":name +" SHOW:"+master.base.show_name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP,"resize":0}
  3874. args["title"] = "SETUP SHOW:"+master.base.show_name
  3875. cls = draw_setup #(master,w.tk)
  3876. data = []
  3877. cb_ok = None
  3878. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3879. window_manager.new(None,name,wcb=c)
  3880. window_manager.top(name)
  3881. name = "COMMAND"
  3882. args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":0}
  3883. cls = draw_command #(master,w.tk)
  3884. data = []
  3885. cb_ok = None
  3886. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3887. window_manager.new(None,name,wcb=c)
  3888. window_manager.top(name)
  3889. name = "LIVE"
  3890. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":0}
  3891. cls = draw_live #(master,w.tk)
  3892. data = []
  3893. cb_ok = None
  3894. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3895. window_manager.new(None,name,wcb=c)
  3896. window_manager.top(name)
  3897. name = "CLOCK"
  3898. args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
  3899. cclock = X_CLOCK()
  3900. cls = cclock.draw_clock
  3901. data = []
  3902. cb_ok = None
  3903. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3904. window_manager.new(None,name,wcb=c)
  3905. window_manager.top(name)
  3906. name="FX"
  3907. args = {"title":name,"master":0,"width":415,"height":297,"left":L1+10+W1,"top":TOP+302,"resize":0}
  3908. geo = split_window_position(pos_list,name)
  3909. if geo:
  3910. args.update(geo)
  3911. cls = draw_fx #(master,w.tk)
  3912. data = []
  3913. cb_ok = None
  3914. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3915. window_manager.new(None,name,wcb=c)
  3916. window_manager.top(name)
  3917. name="PATCH"
  3918. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3919. geo = split_window_position(pos_list,name)
  3920. if geo:
  3921. args.update(geo)
  3922. cls = GUI_PATCH
  3923. data = FIXTURES
  3924. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3925. window_manager.new(None,name,wcb=c) #,obj)
  3926. #window_manager.top(name)
  3927. name="COLORPICKER"
  3928. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  3929. geo = split_window_position(pos_list,name)
  3930. if geo:
  3931. args.update(geo)
  3932. #w = Window(args)
  3933. #draw_colorpicker(master,w.tk,FIXTURES,master)
  3934. cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
  3935. data = [FIXTURES,master]
  3936. cb_ok = None #FIXTURES
  3937. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3938. window_manager.new(None,name,wcb=c)
  3939. #window_manager.top(name)
  3940. name="TableA"
  3941. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3942. #space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
  3943. #x=TableFrame(root=w.tk)#,left=80,top=620)
  3944. #w.show()
  3945. #data =[]
  3946. #for a in range(40):
  3947. # data.append(["E","E{}".format(a+1)])
  3948. #x.draw(data=data,head=["E","C"],config=[12,5,5])
  3949. #w=x.bframe
  3950. #window_manager.new(w,name)
  3951. master.render()
  3952. window_manager.top("Table")
  3953. #w = frame_fix #Window("OLD",master=0,width=W1,height=500,left=130,top=TOP)
  3954. #window_manager.new(w,name)
  3955. load_window_position()
  3956. thread.start_new_thread(loops,())
  3957. try:
  3958. window_manager.mainloop()
  3959. finally:
  3960. master.exit()