_LibreLightDesk.py 139 KB

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