_LibreLightDesk.py 140 KB

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