_LibreLightDesk.py 138 KB

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